【问题标题】:Woocommerce - single product - show different content for different productsWoocommerce - 单品 - 为不同的产品展示不同的内容
【发布时间】:2013-10-25 10:42:35
【问题描述】:

我想在不同类别的单个产品页面上显示不同的内容。

示例代码

<?php if(in_category('62')){ ?>Text for category 62<?php }?>
<?php if(in_category('21')){ ?>Text for category 21<?php }?>

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    制作新模板并将其命名为:taxonomy-product_cat-Your_category_product_slug.php

    路径:/wp-content/your-theme/woocommerce/taxonomy-product_cat-Your_category_product_slug.php

    另一种方法:

    $cat1 = 62;
    $cat2 = 21;
    
    $terms = wp_get_post_terms($post->ID, 'product_cat');
    if (!empty($terms)) {
        foreach ($terms as $t) {
            if ($t->term_id == $cat1) {
                woocommerce_get_template_part('single-product-product1');
            } else if ($t->term_id == $cat2) {
                woocommerce_get_template_part('single-product-product2');
            }
        }
    }
    

    【讨论】:

    • 单个产品页面的工作解决方案是:ID, 'product_cat' ); foreach ( $terms as $term ) $categories[] = $term->slug; if ( has_term( 'In audio', 'product_cat' ) ) { ?> echo 'In audio'; } elseif ( has_term( 'elektro', 'product_cat' ) ) { echo '在 elektro'; } 其他 { 回声 '一些 blabla'; }?>
    猜你喜欢
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    • 2023-01-18
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    相关资源
    最近更新 更多