ResolvedMinimum order quantity for delivery

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26477
    juliansantanilla
    Participant

    Hi, how´s it going…
    How can we set up a Minimum order quantity for delivery?
    For example, If a Customer order only 1 Buerger for 5 USD, the online store can´t sell that product.
    If the Minimum order quantity for delivery is 20 USD, the Onnline Store can sell that product.

    How can I set up that feature?

    #26500
    Althemist
    Keymaster

    Hi juliansantanilla,

    I am afraid this is not theme related. Also, there is no such feature in WooCommerce by default. You’d need to use a plugin for minimum quantity. There are many plugins like this, both free and premium. Something like this one:

    Product Quantity, Minimum Maximum quantity & Minimum Order quantity WooCommerce

    Hope this helps.

    Regards,
    Dimitar

    #27045
    polspede
    Participant

    Hi!
    I made such mod myself. All you need is to modify functions.php of your child theme. Add this at the end of file (don’t forget to make backup!):

    function getMinimumCartNoticeErrorText() {
    	$str = 'The delivery requires you to have an order with a value of at least %s in your cart.';
    	return $str;
    }
    function checkIfMinimumCartOrderIsMet() {
    	$woo_min_cart_order = 50; // amount
    	$woo_include_shipping = false;
    	$woo_min_cart_end_value = $woo_include_shipping ? WC()->cart->total : WC()->cart->subtotal;
    	$woo_min_cart_shipping = WC()->cart->get_shipping_total();
    	
    	return ($woo_min_cart_end_value < $woo_min_cart_order && $woo_min_cart_shipping > 0) ? array('cart_min_order' => $woo_min_cart_order, 'cart_total' => $woo_min_cart_end_value, 'cart_shipping' => $woo_min_cart_shipping) : null;
    }
    function checkMinimumCartOrder() {
    	$noMinOrder = checkIfMinimumCartOrderIsMet();
    	if ($noMinOrder) {
    		if (is_cart() || is_checkout()) {
    			wc_print_notice( sprintf( esc_html__(getMinimumCartNoticeErrorText(), 'lafka'), wc_price($noMinOrder['cart_min_order']) ), 'error' );
    		}
    	}
    }
    // cart view
    add_action('woocommerce_before_cart', 's77_woocommerce_before_cart_min_order');
    function s77_woocommerce_before_cart_min_order() {
    	checkMinimumCartOrder();
    }
    // checkout view
    add_action('woocommerce_before_checkout_form', 's77_woocommerce_before_checkout_form_min_order');
    function s77_woocommerce_before_checkout_form_min_order() {
    	checkMinimumCartOrder();
    }
    // when 'place order' button at checkout is pressed
    add_action('woocommerce_checkout_process', 's77_woocommerce_checkout_process_min_order');
    function s77_woocommerce_checkout_process_min_order() {
    	$noMinOrder = checkIfMinimumCartOrderIsMet();
    	if ($noMinOrder) {
    		throw new Exception(sprintf( esc_html__(getMinimumCartNoticeErrorText(), 'lafka'), wc_price($noMinOrder['cart_min_order']) ));
    	}
    }
    
    #27056
    Althemist
    Keymaster

    Hello polspede,

    Thanks for sharing with other users, so they can benefit from your experience.

    Regards,
    Dimitar

    #37791
    unifiquedesigns
    Participant

    Hi @polspede,

    Thanks for your response, should I just paste this codes in the funtion.php file?
    And it will work?

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in and have valid license to reply to this topic.

License required for the following item
Login and Registration Log in · Register