WordPress.org

Support

Support » Plugins and Hacks » 2.1.3 Minimum Order Required

2.1.3 Minimum Order Required

  • WordPress 3.8.1 with WooCommerce 2.1.3 on Media Temple gs…

    Does anyone know of a tested method to require a minimum order amount for 2.1.3? I am currently using the code snippet below. It does prevent you from accessing the checkout page if your order does not meet the minimum, however, if you do meet the minimum and successfully checkout, you are still redirected back to the cart, which is now empty because the order went through. Before the redirect back to the cart, the site does attempt to load the order-recieved page (endpoint), but the redirect happens before the page loads that has the order confirmation, making the purchaser think their order did not go through when it did.

    add_action('the_post','minimum_order_func',10);
    function minimum_order_func(){
    global $woocommerce;
    if ( is_checkout() ) {
    	$minorder = 150;
    	if( $woocommerce->cart->subtotal < $minorder){
    		 $woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. Once you do meet this minimum, you can proceed with the checkout. <a href="%s/store">Continue Shopping &rarr;</a>', 'woocommerce'), home_url()) );
    		    wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );
    		   			exit;
    		}
    	}
    }

    https://wordpress.org/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Okay I tried this (hacky) work-around which does prevent the redirect after successful checkout, but, the error message still shows on the order-received page.

    add_action('the_post','minimum_order_func',10);
    function minimum_order_func(){
    global $woocommerce;
    if ( is_checkout() ) {
    
    	$minorder = 150;
    
    	$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    
    	if( $woocommerce->cart->subtotal < $minorder ){
    
    		 $woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. Once you do meet this minimum, you can proceed with the checkout. <a href="%s/store">Continue Shopping &rarr;</a>', 'woocommerce'), home_url()) );
    
    		 	if (false !== strpos($url,'order-received')) { //order recieved enpoint exists
    			    //do nothing
    			} else {
    		    wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );
    		   			exit;
    		   	}
    
    		}
    	}
    }
    Roy Ho
    Member

    @splashingpixelscom

    Thanks Roy. The snippet provided at http://docs.woothemes.com/document/minimum-order-amount/ doesn’t seem to do anything at all.

    Okay I have accomplished what I want, but I still feel it’s ‘hacky.’ Below is my code. I moved the output of the error into the else block:

    add_action('the_post','minimum_order_func',10);
    function minimum_order_func(){
    	global $woocommerce;
    
    	if ( is_checkout() ) {
    
    		$minorder = 150;
    
    		$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    
    		if( $woocommerce->cart->subtotal < $minorder ){
    
    		 	if (false !== strpos($url,'order-received')) { //order recieved enpoint exists
    			    //do nothing
    			} else {
    
    			 $woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. Once you do meet this minimum, you can proceed with the checkout. <a href="%s/store">Continue Shopping →</a>', 'woocommerce'), home_url()) );
    
    		     wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );
    
    		   	 exit;
    		   	}
    
    		}
    	}
    }

    vark
    Participant

    @vark

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘2.1.3 Minimum Order Required’ is closed to new replies.