1 回答

TA貢獻2051條經驗 獲得超10個贊
您通過在每一行上使用相同的命名約定來覆蓋您的變量。所以如果你想將它應用于多個 ID,你必須將它們放在一個數組中。
function min_cart_amount() {
## ----- EXCLUDES A PRODUCT FROM MINIMUM ORDER DOLLAR VALUE Your Settings below ----- ##
$min_cart_amount = 130; // Minimum cart amount
$except_product_id = array ( 2649, 2659, 1747 ); // Except for this product ID
// Loop though cart items searching for the defined product
foreach( WC()->cart->get_cart() as $cart_item ) {
// Product id
$product_id = $cart_item['product_id'];
// Exit if the defined product is in cart
if ( in_array( $product_id, $except_product_id) ) {
return;
}
}
if( WC()->cart->subtotal < $min_cart_amount ) {
wc_add_notice( sprintf(
__( "<strong>A Minimum of %s is required before checking out.</strong><br>The current cart's total is %s" ),
wc_price( $min_cart_amount ),
wc_price( WC()->cart->subtotal )
), 'error' );
}
}
add_action( 'woocommerce_check_cart_items', 'min_cart_amount', 10, 0 );
- 1 回答
- 0 關注
- 127 瀏覽
添加回答
舉報