2017-04-06 40 views

回答

2

該過濾器在以下位置定義。

/includes/class-wc-ajax.php 

允許在WooCommerce車只添加單個項目

add_filter('woocommerce_add_to_cart_validation', 'restrict_only_one_item_in_cart'); 

function restrict_only_one_item_in_cart($cart_item_data) { 

    global $woocommerce; 
    $item_count = $woocommerce->cart->cart_contents_count; 

    if($item_count > 0){ 
     wc_add_notice('Sorry. Only one item is allowed.If you would like to add another, please remove the item in the cart.', 'error'); 
     return false; 
    } 
    return $cart_item_data; 
} 
相關問題