【发布时间】:2021-10-31 02:45:39
【问题描述】:
我对此有点卡住..每当用户添加特定产品时,我都会尝试删除条件,在这种情况下是一盒葡萄酒
所以当我添加一瓶酒时,有一个最低量条件,所以你必须添加 3,但是当你添加一个盒子时,必须删除条件
add_action('woocommerce_after_cart_contents', 'box_special_function', 1, 1);
function box_special_function()
{
// getting cart items
$cart = WC()->cart->get_cart();
$terms = [];
// Getting categories of products in the cart
foreach ($cart as $cart_item_key => $cart_item) {
$product = $cart_item['data'];
$terms[] = get_the_terms( $product->get_id(), 'product_cat' );
}
// Cycling categories to find if there is a box inside of the cart
foreach($terms as $term => $item){
foreach($item as $key){
if($key->name == "BOX"){
// The only thing i did is to remove notices (which doesn't even work .-.)
$notices = WC()->session->get('wc_notices', array());
foreach($notices['error']){
wc_clear_notices();
}
}
}
}
}
我什至不能强制结帐,所以我被这个卡住了..有人可以清除我的想法吗?
【问题讨论】:
标签: php wordpress woocommerce shopping-cart woocommerce-theming