• Resolved stefanig

    (@stefanig)


    Hello,
    I use a minimum order code that works well, but I want to use this code according to the states that I have on my website.
    I want state 1 to have a minimum of 30$ and state 2 to be 45$
    I’m sending you a link to my code: https://pastebin.com/tQk0FcfB
    The problem is that even if I don’t update my cart, it allows me to continue to checkout, also allows me to complete my order in checkout and I shouldn’t do it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi

    You are currently using:

    $state = array('BG-23');  
     
             $cart_total_order = WC()->cart->total;
     
    		 if( $cart_total_order < $minimum && in_array(WC()->customer->get_shipping_state(), $state )  ) {

    You’ll want to use something like this:

    $state = $woocommerce->customer->get_shipping_state();
         
            if( $cart_total_order < $minimum  && $state == 'BG-23'  ) {

    Let me know if that helps.

    Cheers!

    • This reply was modified 4 years, 3 months ago by Rynald0s.
    Thread Starter stefanig

    (@stefanig)

    Hello,
    Thank you for your replay.
    I’m sorry, but it doesn’t work, it still allows me to complete my order even if the amount is below the minimum…
    I’ve tried this function for disabling proceed to checkout button, but I have an error and I don’t know where to insert it to work well.

    function disable_checkout_button_no_shipping() {
    remove_action( ‘woocommerce_proceed_to_checkout’, ‘woocommerce_button_proceed_to_checkout’, 20 );
    echo ‘Proceed to checkout‘;}
    add_action( ‘woocommerce_proceed_to_checkout’, ‘disable_checkout_button_no_shipping’, 1 );

    Can you edit it for me and tell me where to insert it?

    Best wishes,
    Stefani

    • This reply was modified 4 years, 3 months ago by stefanig.
    • This reply was modified 4 years, 3 months ago by stefanig.
    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @stefanig!

    The following code works for me, so maybe modify this to fit your specific needs.

    In the case, I am requiring a minimum order value of $25 if the state is CA (California). It does not allow checkout. Instead, it displays an error that there is a problem in the cart, and the cart itself echoes the error message within the code:

    add_action( 'woocommerce_check_cart_items', 'wc_min_order_total' );
    
    function wc_min_order_total() {
    	
    	if( is_cart() || is_checkout() ) {
    		global $woocommerce;
    		
            $minimum = 25;
    	  	$state = array('CA');  //California
    		   
            $cart_tot_order = WC()->cart->total;
    		$state = $woocommerce->customer->get_shipping_state();
         
            if( $cart_total_order < $minimum  && $state == 'CA'  ) {
    
    	        wc_add_notice( sprintf( '<strong>A Minimum order of $%s is required before checking out.</strong>' 
    	        	. '<br />Current order: $%s.', $minimum, $cart_tot_order	), 'error' );
    		}
    	}
    }

    You can extend the array and add more states if you like.

    Cheers!

    • This reply was modified 4 years, 3 months ago by Rynald0s.
    Thread Starter stefanig

    (@stefanig)

    @rynald0s

    Тhank you so much, it works correctly! ??

    Have a nice day! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Minimum order amount’ is closed to new replies.