我遇到如何从类别产品中删除购物车的问题。如果我将它应用于特定的 ID 或一般情况下的所有 ID,它就可以正常工作,但我无法对类别执行此操作。下面是我对此所做的代码。
另外,我正在努力将相同的模式应用到相关文章部分,因此任何帮助将不胜感激。
谢谢。
//function for deleting ....
function remove_product_description_add_cart_button(){
global $product;
//Remove Add to Cart button from product description of product with id 1234
if ($product->id == 188){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
add_action('wp','remove_product_description_add_cart_button');
}
2020 年 11 月更新
要使其适用于产品类别,您可以使用 WordPress 条件函数has_term() https://codex.wordpress.org/Function_Reference/has_term这边走:
add_action('woocommerce_single_product_summary', 'remove_product_description_add_cart_button', 1 );
function remove_product_description_add_cart_button() { // function for deleting ...
// Set HERE your category ID, slug or name (or an array)
$categories = array('your-category-1');
//Remove Add to Cart button from product description of product with id 1234
if ( has_term( $categories, 'product_cat', get_the_id() ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
代码位于活动子主题(或活动主题)的 function.php 文件中。或者也可以在任何插件 php 文件中。经过测试并有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)