Sha*_*ary 4 php wordpress product cart woocommerce
我正在为我的网站使用 woocommerce,我想隐藏一个特定项目的“删除此项目/产品”,你能告诉我我该怎么做。
我将不胜感激对此的任何帮助。
更新(对于数组中的多个产品 ID)
这是禁用/删除“删除此项目”按钮的正确方法,适用于以下代码中的特定产品 ID(您应该定义):
add_filter('woocommerce_cart_item_remove_link', 'customized_cart_item_remove_link', 20, 2 );
function customized_cart_item_remove_link( $button_link, $cart_item_key ){
//SET HERE your specific products IDs
$targeted_products_ids = array( 25, 22 );
// Get the current cart item
$cart_item = WC()->cart->get_cart()[$cart_item_key];
// If the targeted product is in cart we remove the button link
if( in_array($cart_item['data']->get_id(), $targeted_products_ids) )
$button_link = '';
return $button_link;
}
Run Code Online (Sandbox Code Playgroud)
代码位于活动子主题(或活动主题)的 function.php 文件中。
测试和工作。
| 归档时间: |
|
| 查看次数: |
2027 次 |
| 最近记录: |