Php 自定义单个产品页不工作

Php 自定义单个产品页不工作,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,在使用woocommerce时,我更改了single-product.php,并在循环中放置了一个“if”语句,以加载特定产品的自定义页面 <?php while ( have_posts() ) : the_post(); if (is_product_category( 'Benefit')) { woocommerce_get_template_part( 'content', 'single-product-benefit' ); }else{ w

在使用woocommerce时,我更改了single-product.php,并在循环中放置了一个“if”语句,以加载特定产品的自定义页面

        <?php while ( have_posts() ) : the_post();

if (is_product_category( 'Benefit')) {
    woocommerce_get_template_part( 'content', 'single-product-benefit' );
}else{
    woocommerce_get_template_part( 'content', 'single-product' );
}
        endwhile; // end of the loop. ?>

我的问题是“if”的第一部分调用的content-single-product-benefit.php总是被加载(对于所有产品)。 我怀疑这是一个非常愚蠢的php语法错误,但我花了一个小时在上面,却看不到它。这两个php页面都称自己可以正常工作。不知怎的,我不能把“如果”说对。我做错了什么?? Thx for your help ^ ^

功能仅在显示存档页面时有效,与Wordpress功能相同。由于您在
single product.php
文件中使用此函数,并且这是单个页面的模板,因此上述函数将无法工作。尝试:

has_term( 'Benefit', 'product_cat', $post );

您能否在
while()
循环中使用此代码来输出产品所属的类别?然后试穿一种非效益产品,让我们知道产品的产量
$terms=get_the_terms($post->ID,'product_cat');var_dump(条款)谢谢你的回答。代码输出
array(1){[6]=>object(stdClass){102(11){[“term_id”]=>int(6)[“name”]=>string(8)“benefit”[“slug”]=>string(8)“benefit”[“term_group”]=>int(0)[“term_分类法”]=>int(6)[“taxonomology”=>string(11)“product_cat”[“description”]=>string(0)”[“parent”]=>int(0)[“parent”]=>int(0)[“count”[“count”=>int(int)”过滤对象”[]=>string(3)“raw”}
在福利产品页面上……和
array(1){[7]=>object(stdClass){102(11){[“term\u id”]=>int(7)[“name”=>string(9)“books”[“slug”]=>string(9)“books”[“term\u-group”]=>int(0)[“term\u-taxonomology\u-id”=>int(7)[“taxonomology”=>string(11)”产品分类”[“description”]=>string(11)”说明”=>string(0)[>]=>int(1)[“object_id”]=>int(8)[“filter”]=>string(3)“raw”}}
在我尝试的另一个页面上。谢谢Danijel!!我忽略了这一点。”has_term()'工作正常。