WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Set a minimum order for cart total? (45 posts)

  1. Greg
    Member
    Posted 1 year ago #

    I'm using woocommerce for a wholesale site and need to be able to set a minimum order value. Does anyone know if this is possible?

    I noticed that the free shipping option has a minimum order value but it's not quite what I need.

    http://wordpress.org/extend/plugins/woocommerce/

  2. andrianiannalisa
    Member
    Posted 1 year ago #

    So do I.
    I'm looking for a very simple add-on for woocommerce in WordPress to allow me to set a minimum order value. If the order total is below the set value the user is told the value is too low and directed to add more to their card.

    Does anyone know if this is possible?

  3. bheadrick
    Member
    Posted 1 year ago #

    there's a redirect in place that if someone tries to access the checkout and there's no items in the cart, it redirects them back to cart. the action that's called just before it is woocommerce_before_checkout_process

    so,

    add_action('woocommerce_before_checkout_process','minimum_order_func');
    
    function minimum_order_func(){
    global $woocommerce;
    $minorder = 20;
    if( $woocommerce->cart->get_cart()->cart_contents_total<$minorder){
    $woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. <a href="%s">Return to homepage &rarr;</a>', 'woocommerce'), home_url()) );
    }
    }
  4. andrianiannalisa
    Member
    Posted 1 year ago #

    Where do I add this code?

    I'm not an expert in PHP :-(

    Thank's very much!!

  5. andrianiannalisa
    Member
    Posted 1 year ago #

    Do I insert it before of "woocommerce_before_checkout_process" (with parameters I want the minimum order) in the class-wc-checkout.php?

  6. andrianiannalisa
    Member
    Posted 1 year ago #

    ok it works fine!!

    you are great!
    Another question ... if I would like to redirect the user to another page, and not at the home, how can I do?

    Thank's!

  7. andrianiannalisa
    Member
    Posted 1 year ago #

    mmm .. I did a test with a minimum order but does not work ...
    Perhaps because the minimum amount in my cart is in € and not in dollars?

  8. bheadrick
    Member
    Posted 1 year ago #

    you could wrap it in a basic plugin, or you could copy it into your theme's functions.php

    I just tested this, and it doesn't work. Seems you need a different action hook. haven't found the right one yet.

  9. bheadrick
    Member
    Posted 1 year ago #

    definitely don't modify the woocommerce files (except for the template files copied to your theme)

  10. May Didly
    Member
    Posted 1 year ago #

    The code above didn't work for me. I played around with a bit and got it to work. I don't know php so it might not be the best way of coding it.

    add_action('woocommerce_before_checkout_process','minimum_order_func');
    
    function minimum_order_func(){
    	global $woocommerce;
    	$minorder = 50;
    
    	if( $woocommerce->cart->subtotal<$minorder ){
    		$woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. <a href="%s">Return to homepage &rarr;</a>', 	'woocommerce'), home_url()) );
    	}
    }
  11. andrianiannalisa
    Member
    Posted 1 year ago #

    I have pasted into the file class-wc-checkout.php before "woocommerce_before_checkout_process", but the warning "Sorry, you have not met the minimum order amount..." appears also if the minimum order was made.

  12. bheadrick
    Member
    Posted 1 year ago #

    OK, I got this working. apparently the *checkout_process actions actually fire after you click "place order" not when you first hit the checkout page. We need the function to fire as soon as the page loads.

    add_action('the_post','minimum_order_func',10);
    function minimum_order_func(){
    global $woocommerce;
    if (is_checkout()){
    $minorder = 50;
    if( $woocommerce->cart->subtotal < $minorder){
     $woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. <a href="%s">Return to homepage &rarr;</a>', 'woocommerce'), home_url()) );
        wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );
       			exit;
    }}}

    Don't hack up the woocommerce plugin, cos when they release an update, your changes will be gone. The point of hooks is so you can apply your mods outside of the core code.

    Most people put this kind of stuff at the bottom of their theme's functions.php, although it's sometimes a good idea to wrap it up in a separate plugin. You'll be fine to put this in your functions.php, though.

  13. andrianiannalisa
    Member
    Posted 1 year ago #

    Perfect!
    Now it seems to work fine!

    You are great!!

  14. Jeff Smith
    Member
    Posted 1 year ago #

    Thanks for this.

    How to add a check to see if the customer chose delivery before showing the message? I have a store that customers can order food for pickup or delivery. Pickup has no minimum order value, but delivery has a $15 minimum.

  15. miketopher
    Member
    Posted 1 year ago #

    i had this working a few weeks back on a demo site im working on.

    getting back to working on the site, having updated wp and wc this does not seem to work any longer...

    could anyone verify this?

  16. kristicecca
    Member
    Posted 1 year ago #

    Hi guys - Thank you collective brainpower for solving this one!

    I'm trying to add this rule to my site...
    but can someone please clarify where precisely I should include this?

    on the theme's functions.php?
    on the woocommerce plugins functions.php?

    somewhere else entirely?

    and is this exactly how i should paste it in?

    add_action('the_post','minimum_order_func',10);
    function minimum_order_func(){
    global $woocommerce;
    if (is_checkout()){
    $minorder = 50;
    if( $woocommerce->cart->subtotal < $minorder){
    $woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. Return to homepage →', 'woocommerce'), home_url()) );
    wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );
    exit;
    }}}

  17. deifos
    Member
    Posted 1 year ago #

    looking to set up a minimum amount for the check out, I found this plug in -Minimum Purchase for WooCommerce- I tested it on wp 3.4.9 and it worked perfect but now on 3.5.1 I get a grey screen and does not let set up the rules need, might want to give it a try and see it works for you guys.

  18. deifos
    Member
    Posted 1 year ago #

    Kristicecca, you have to add it to your theme's function.php

    any ideas on how we can get the message to be translatable using WPML. I don't know PHP although I tried a few things but did not work.

    Any suggestions would be greatly appreciated.

  19. zaggle
    Member
    Posted 1 year ago #

    Just had to log in to say thanks for this simple piece of code... it's awesome... well done

  20. bheadrick
    Member
    Posted 1 year ago #

  21. deifos
    Member
    Posted 1 year ago #

    Thanks bheadrick, you are right that function makes it translatable as per WPML documentation, I was just not using the string translator propertly, you guys can see it in action by trying to buy from here.

    Thanks for the script it sure save me a lot of time.

  22. vark
    Member
    Posted 1 year ago #

    Deifos is right, either of these two plugins will set a minimum purchase rule:

    Minimum Purchase for WooCommerce
    Min and Max Purchase for WooCommerce

    The bug Deifos experienced was resolved with v 1.06.

  23. deifos
    Member
    Posted 1 year ago #

    However I think vark's plug in is the way to go if you don't want to mess with any code on the theme, I will be trying it on my next project so it will make easier for the client to adjust the max and min amounts from the admin panel. Thanks for your plugin vark

  24. theworld
    Member
    Posted 1 year ago #

    HELLO,

    CAN SOME ONE PLS BE MORE SPECIFIC WHERE TO PLACE THE CODE?

    THERE ARE NEWBEE'S THAT DOESN'T HAVE PHP KNOWLEDGE SO PLS, BE MORE SPECIFIC FOR EXAMPLE: SPECIFY THE ROOT PAD OF THE FILE NAME AND ON WHAT LINE THE CODE SHOULD BE ADDED.

    add_action('the_post','minimum_order_func',10);
    function minimum_order_func(){
    global $woocommerce;
    if (is_checkout()){
    $minorder = 50;
    if( $woocommerce->cart->subtotal < $minorder){
     $woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. <a href="%s">Return to homepage &rarr;</a>', 'woocommerce'), home_url()) );
        wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );
       			exit;
    }}}

    THANKS,

    THAT WILL HELP A LOT OF PEOPLE ASKING THE SAME QUESTIONS

  25. deifos
    Member
    Posted 1 year ago #

    Theworld if you are not familiar with PHP I would suggest you to use the Minimum Purchase for WooCommerce plugin it does what you want and more and very easy to use, I received a email from the developer stating that he fixed the bug with wp 3.5, so give it a try.

  26. terrytsang
    Member
    Posted 1 year ago #

    If you ever want to place hooks(add_action) and filters(add_filter), please put it at the end of your theme's functions.php

    For example:

    add_action('the_post','minimum_order_func',10);
    function minimum_order_func(){
    global $woocommerce;
    if (is_checkout()){
    $minorder = 50;
    if( $woocommerce->cart->subtotal < $minorder){
      $woocommerce->add_error( sprintf(__('Sorry, you have not met the minimum order amount of $' . $minorder . '. <a href="%s">Return to homepage →</a>', 'woocommerce'), home_url()) );
      wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );
      exit;
    }}}
  27. balas
    Member
    Posted 12 months ago #

    i got woocommerce checkout redirect if minimum order amt less than 100 working.

    Thanks for all. and this is the right place for the solution.

  28. mike73
    Member
    Posted 12 months ago #

    hi hi,

    ... Is it possible to bring this function / hook(add_action) in conjunction with the shipping method "local delivery"?

    So that it applies only to this shipping method "local delivery".

    ----------------------------------------------
    ... Ist es möglich, diese Funktion in Verbindung mit der Versandmethode "Lokale Zustellung" zu bringen?
    So das sie nur für diese Versandmethode gilt.

    Many thanks for your help!

    g, mike

  29. mike73
    Member
    Posted 12 months ago #

    ... there is a another problem ;)

    If I put it (this hook) at the end of my theme's functions.php,
    then I've following error:

    Fatal error: Cannot unset string offsets in /../../wp-content/plugins/woocommerce/classes/abstracts/abstract-wc-session.php on line 66

    Have someone any help for me?

    Thanks, mike

  30. terrytsang
    Member
    Posted 12 months ago #

    Fatal error: Cannot unset string offsets in /../../wp-content/plugins/woocommerce/classes/abstracts/abstract-wc-session.php on line 66

    Hi mike73, have you updated to latest WooCommerce version? I found a bug issue at github = https://github.com/woothemes/woocommerce/issues/3135

    and they solved that by updated the core file:
    https://github.com/woothemes/woocommerce/commit/2db3d24a8297c2b25b13fd700fc5a903d6763a40

    Hope that will help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic