Setting minimum amount to certain category
-
Hi, i try to add in my fuction.php this custom code. I would you like to setting minimum amount 50€ only for purchase category “PRODUCTS” but do not works
add_action( ‘woocommerce_check_cart_items’, ‘check_cart_outlet_items’ ); function check_cart_outlet_items() { $categories = array(‘PRODOTTI’); // Defined targeted product categories $threshold = 50; // Defined threshold amount $cart = WC()->cart; $cart_items = $cart->get_cart(); $subtotal = $cart->subtotal; $subtotal -= $cart->get_cart_discount_total() + $cart->get_cart_discount_tax_total(); $found = false; foreach( $cart_items as $cart_item_key => $cart_item ) { // Check for specific product categories if ( has_term( $categories, ‘product_cat’, $cart_item[‘product_id’] ) ) { $found = true; // A category is found break; // Stop the loop } } if ( $found && $subtotal < $threshold ) { // Display an error notice (and avoid checkout) wc_add_notice( sprintf( __( “You must order at least %s” ), wc_price($threshold) ), ‘error’ ); } }
The topic ‘Setting minimum amount to certain category’ is closed to new replies.