php购物车删除某个商品,php – 删除Woocommerce中针对特定产品类别的添加购物车按钮...

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:30   2629   0

我有一个问题如何从类别产品中删除购物车.如果我将它应用于特定的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');

}

解决方法:

要使其适用于产品类别,您可以使用WordPress条件函数has_term():

//function for deleting ....

function remove_product_description_add_cart_button(){

global $product;

// Set HERE your category ID, slug or name (or an array)

$category = 'categoryslug';

//Remove Add to Cart button from product description of product with id 1234

if ( has_term( $category, 'product_cat', $product->id ) )

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

}

add_action('wp','remove_product_description_add_cart_button');

代码位于活动子主题(或主题)的function.php文件中.或者也可以在任何插件php文件中.

标签:categories,php,wordpress,woocommerce,product

来源: https://codeday.me/bug/20190823/1701718.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP