admin管理员组文章数量:1323035
I'm trying to add text to the product short description by category.
So for example, for all Cake Toppers, I want to add to the bottom of the short description to show "This is a cake topper". For all products which are not cake toppers, I want to show the text "Not a cake topper".
This is the code I'm using:
add_action( 'woocommerce_single_product_summary', 'product_short_description_by_category', 20 );
function product_short_description_by_category() {
if( is_product_category('cake-toppers') ){
echo '<p>A cake topper</p>';
}else{
echo '<p>NOT CAKE TOPPER</p>';
}
}
But all products, including cake topper, show "THIS IS NOT A CAKE TOPPER".
What am I doing wrong here? "cake-toppers" is the slug for the category name.
Site at: /
Any help is greatly appreciated!
I'm trying to add text to the product short description by category.
So for example, for all Cake Toppers, I want to add to the bottom of the short description to show "This is a cake topper". For all products which are not cake toppers, I want to show the text "Not a cake topper".
This is the code I'm using:
add_action( 'woocommerce_single_product_summary', 'product_short_description_by_category', 20 );
function product_short_description_by_category() {
if( is_product_category('cake-toppers') ){
echo '<p>A cake topper</p>';
}else{
echo '<p>NOT CAKE TOPPER</p>';
}
}
But all products, including cake topper, show "THIS IS NOT A CAKE TOPPER".
What am I doing wrong here? "cake-toppers" is the slug for the category name.
Site at: http://wendyw11.sg-host/product/two-wild-cake-topper/
Any help is greatly appreciated!
Share Improve this question edited Sep 20, 2020 at 8:17 Antti Koskinen 6,0088 gold badges15 silver badges26 bronze badges asked Sep 20, 2020 at 7:26 WendyWendy 32 bronze badges 1- Related: wordpress.stackexchange/questions/333424/… – Jesse Nickles Commented Feb 2, 2023 at 8:58
1 Answer
Reset to default 0is_product_category() – Check If Current Page is a Product Category
Try this
add_action( 'woocommerce_single_product_summary', 'product_short_description_by_category', 20 );
function product_short_description_by_category() {
if( has_term( 'cake-toppers', 'product_cat' )){
echo 'A cake topper';
} else{
echo 'NOT CAKE TOPPER';
}
}
本文标签: phpWooCommerce isproductcategory() not working
版权声明:本文标题:php - WooCommerce is_product_category() not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742109206a2421167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论