• Resolved arif66

    (@arif66)


    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)
  • Hi there @arif66 👋

    My Question: how can i adjust the code as long as the minimum order is not reached, no redirect to checkout page.

    Thanks for reaching out. This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    There is a way to achieve the desired functionality, without touching a line of code, by using the Order Restrictions for WooCommerce plugin, directly linked here.

    Furthermore, kindly keep in mind, we are not developers and only offer support for existing functionality.

    Please see our Support Policy: http://www.woocommerce.com/support-policy/

    For assistance with customization or development with your site, we recommend that you seek help from:

    * A local web developer
    * Codeable.io
    * WooExperts
    * Stackexchange

    If you are comfortable coding yourself and have questions, I would also recommend that you consider:

    * WooCommerce developer Portal
    * WooCommerce Slack Community
    * Advanced WooCommerce Facebook group

    I hope that helps you to figure it out.

    Feel free to get back to us if you have further questions.

Viewing 1 replies (of 1 total)

The topic ‘minimum order value for certain product category’ is closed to new replies.