minimum order value for certain product category
-
Hello,
i have use the following php snippet for my online shop
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' ); add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); add_action( 'woocommerce_before_checkout' , 'wc_minimum_order_amount' ); function wc_minimum_order_amount() { // Set this variable to specify a minimum order value $minimum = 99; // set array with cat IDs $category_ids = array('Gratis'); // set bool that checks is minimum amount has been reached $needs_minimum_amount = false; // Initializing $subTotal_amount = WC()->cart->subtotal; // Items subtotal including taxes $total_amount = WC()->cart->total; // Items subtotal excluding taxes if ( $total_amount < $minimum ) { // Loop through cart items foreach ( WC()->cart->get_cart() as $cart_item ) { $product_id = $cart_item['product_id']; $variation_id = $cart_item['variation_id']; // Check for matching product categories if( sizeof($category_ids) > 0 ) { $taxonomy = 'product_cat'; if ( has_term( $category_ids, $taxonomy, $product_id ) ) { $needs_minimum_amount = true; break; // Stop the loop } } } if( $needs_minimum_amount ) { if( is_cart()) { wc_print_notice( sprintf( 'Die Gratisartikel sind 1 Stück pro Bestellung limitiert. Aktueller Bestellwert %s — Bitte erreichen Sie den Mindestbestellwert von %s', wc_price( WC()->cart->total ), wc_price( $minimum ) ), 'error' ); } else { wc_add_notice( sprintf( 'Die Gratisartikel sind 1 Stück pro Bestellung limitiert. Aktueller Bestellwert %s — Bitte erreichen Sie den Mindestbestellwert von %s' , wc_price( WC()->cart->total ), wc_price( $minimum ) ), 'error' ); } } } }My Question: how can i adjust the code as long as the minimum order is not reached, no redirect to checkout page.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘minimum order value for certain product category’ is closed to new replies.