0

1 つの商品ページにさまざまなカテゴリのさまざまなコンテンツを表示したいと考えています。

サンプルコード

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

1 に答える 1

0

新しいテンプレートを作成して名前を付けます: 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');
        }
    }
}
于 2013-10-25T11:27:07.777 に答える