WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. mike73
    Member
    Posted 12 months ago #

    Hi Terry,

    ... yes I've the latest version wooCommerce.
    WooCommerce Version: 2.0.13
    WooCommerce Datenbank-Version: 2.0.13

    Do you mean, the bugfix ist not in the latest version (2.0.13)?
    And I must take the bugfix from/in the 3 files?

    But in the latest version (2.0.13) is the code completely different,
    than the core files by this (this is wooCommerceVersion 2.0.0!):
    https://github.com/woothemes/woocommerce/commit/2db3d24a8297c2b25b13fd700fc5a903d6763a40

    For example in the version (2.0.13):

    public function __unset( $property ) {
        	if ( isset( $this->_data[ $property ] ) ) {
           		unset( $this->_data[ $property ] );
           		$this->_dirty = true;
            }
        }

    ... instead in the version (2.0.0) by the updated core file:

    public function __unset( $key ) {
         if ( isset( $this->_data[ $key ] ) ) {
                unset( $this->_data[ $key ] );
            $this->_dirty = true;
            }
        }

    the version (2.0.13) use "$property" instead "$key"!

    What should I do?

    g, mike

  2. petriknz
    Member
    Posted 11 months ago #

    Mike73 did you ever get an answer to your question?

    There's several different version of the code here in this posting and all seem radically different from the official documentation here http://docs.woothemes.com/document/minimum-order-amount/

    So before I break everything I'd like to clarify which is correct.

    I have WP 3.6 and WC 2.0.13

  3. vark
    Member
    Posted 11 months ago #

    Hi,
    The Minimum Purchase for WooCommerce plugin in wordpress.org will do that job for you: http://wordpress.org/plugins/minimum-purchase-for-woocommerce/

  4. petriknz
    Member
    Posted 11 months ago #

    Thanks Vark, but I need to get this done with the code. I told my boss I could get this working for him with just the addition of some code and not having to pay for yet another plugin. (At that stage only having seen the "official" documentation).

    We need a blanket minimum amount in the cart which this code covers.

    From what I can tell, only your paid version of the plugin covers that and that has not been budgeted for.

  5. vark
    Member
    Posted 11 months ago #

    Hi @petriknz,
    If I understood correctly that you want a whole-store minimum purchase amount, the wordpress.org (free) version will give you what you need. As the doc says, just set up a rule for the role 'not logged in' or 'just visiting' and/or whatever other roles you'd like it to apply to. That will give you full store coverage for that rule. And Bob's your uncle.

  6. petriknz
    Member
    Posted 11 months ago #

    I'll have another look at it but when I installed it yesterday the option to have the rules effect the total cart was greyed out if I recall correctly, unless I missed some setting.

    I'm trying to locate your email address on your website to email you regarding another, unrelated, issue I could use assistance with.

  7. vark
    Member
    Posted 11 months ago #

    The plugin will work out of the box, no setting changes are needed. Just create a new rule, and it will automatically display the 'use selection groups' option. Below, you'll see a box labeled 'Membership list by Role'. Just tick the roles you need, in order for the whole store to be covered by the rule.

    My email is: vark [at] varktech.com ..

  8. rsharrer
    Member
    Posted 11 months ago #

    Hi All, looks like we have a pretty smart group here, I am having a similar issues, I want to add a small order fee for order less than $50.00. I am halfway there I am currently using

    /* add custom price for small order fee */
    add_action( 'woocommerce_cart_totals_before_shipping', 'cp_check_total' ); 
    
    function cp_check_total() {
    global $woocommerce;
    $minorder = 50.00;
    $excost = 4.95;
    if($woocommerce->cart->get_cart()->cart_contents_total>$minorder) {
        end();
    
     }elseif($woocommerce->cart->get_cart()->cart_contents_total<$minorder) {
    	  $woocommerce->cart->add_fee( 'Small Order Fee', $excost, $taxable = false,'');
    	 }
    
     }

    it is adding the small order fee just fine, but is will add it to all orders regardless of the order total, so even if it is above $50.00 the fee is still added. Any Ideas? Thanks in advance.

  9. vark
    Member
    Posted 11 months ago #

    This may fix the problem (Untested, ymmv):

    /* add custom price for small order fee */
    add_action( 'woocommerce_cart_totals_before_shipping', 'cp_check_total' ); 
    
    function cp_check_total() {
      global $woocommerce;
      $minorder = 50.00;
    
      if($woocommerce->cart->get_cart()->cart_contents_total>$minorder) {
          return;
      }
      $excost = 4.95;
      if($woocommerce->cart->get_cart()->cart_contents_total<$minorder) {
      	  $woocommerce->cart->add_fee( 'Small Order Fee', $excost, $taxable = false,'');
      }
    
    }
  10. vark
    Member
    Posted 11 months ago #

    hmmmm missed the >= , should be:

    /* add custom price for small order fee */
    add_action( 'woocommerce_cart_totals_before_shipping', 'cp_check_total' ); 
    
    function cp_check_total() {
      global $woocommerce;
      $minorder = 50.00;
    
      if($woocommerce->cart->get_cart()->cart_contents_total>=$minorder) {
          return;
      }
      $excost = 4.95;
      if($woocommerce->cart->get_cart()->cart_contents_total<$minorder) {
      	  $woocommerce->cart->add_fee( 'Small Order Fee', $excost, $taxable = false,'');
      }
    
    }
  11. rsharrer
    Member
    Posted 11 months ago #

    Nope still stays for the above $50.00 orders too, maybe I am not using the right hook?

  12. terrytsang
    Member
    Posted 11 months ago #

    Hi rsharrer, i have tried to come out something and tested that, it worked for latest version 2.0.13, maybe you can give it a try.

    function woo_add_extra_fee() {
    	global $woocommerce;
    
    	//4 parameters that you can change based on your requirement
    	$extra_fee_label = "Extra Fee";
    	$extra_fee_cost = 5;
    	$extra_fee_taxable = false;
    	$min_order = 50.00;
    
    	//get cart total from session
    	$session_cart = $woocommerce->session->cart;
    	if(count($session_cart) > 0) {
    		$total = 0;
    		foreach($session_cart as $cart_product)
    			$total = $total + $cart_product['line_subtotal'];
    	}
    
    	//if cart total less or equal than $min_order, add extra fee
    	if($total <= $min_order) {
    		$woocommerce->cart->add_fee( __($extra_fee_label, 'woocommerce'), $extra_fee_cost, $extra_fee_taxable );
    	}
    }
    add_action( 'woocommerce_before_calculate_totals', 'woo_add_extra_fee' );
  13. rsharrer
    Member
    Posted 11 months ago #

    Terry, it works perfectly. Thank you very much!!

  14. terrytsang
    Member
    Posted 11 months ago #

    Ryan, it's my pleasure and glad to know it worked for you.

  15. webswift
    Member
    Posted 9 months ago #

    Hi terrytsang, your code looks very good and is almost exactly what I need. How could it be enhanced to also offer a different extra fee and minimum order for BOTH regular and international customers? (i.e. how can you tell if the order is local or international?)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic