• Resolved Warren

    (@rabbitwordpress)


    Hi there,

    Is it possible to have a minimum order restriction that is bypassed when using a PW WooCommerce Gift Cards code or a standard WC coupon code?

    Example; if the minimum order amount is £25 a user cannot checkout with anything less than this unless they are using a gift code or coupon.

    Many thanks
    Warren

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author pimwick

    (@pimwick)

    WooCommerce itself doesn’t have the ability to require a minimum order amount. Can you let me know which plugin that you are using to require a minimum order amount? We can see if there is something that can be done from within the gift card plugin to get this working as you expect.

    Thread Starter Warren

    (@rabbitwordpress)

    Hi @pimwick thanks for getting back to me.

    At the moment we’re using this filter:

    // Minimum Spend £24 for Nick
    
    add_action( 'woocommerce_check_cart_items', 'required_min_cart_subtotal_amount' );
    function required_min_cart_subtotal_amount() {
        // Only run in the Cart or Checkout pages
       if( is_cart() || is_checkout() ) {
    
            // HERE Set minimum cart total amount
           $min_total = 24;
    
            // Total (before taxes and shipping charges)
           $total = WC()->cart->subtotal;
    
            // Add an error notice is cart total is less than the minimum required
           if( $total <= $min_total  ) {
                // Display an error message
               wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($min_total) ) . '<strong>', 'error' );
           }
       }
    }
    /**
     * Set a minimum order amount for checkout
     */
    add_action( 'woocommerce_before_checkout_form', 'wc_minimum_order_amount' );
    add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
    add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
    
    function wc_minimum_order_amount() {
        // Set this variable to specify a minimum order value
        $minimum = 24;
    
        if ( WC()->cart->total < $minimum ) {
    
    		add_filter( 'wt_show_paypal_express_button_in_cart_page', 'wt_show_paypal_express_button_in_cart_page', 99 );
    		add_filter( 'wt_show_paypal_express_button_in_checkout_page', 'wt_show_paypal_express_button_in_checkout_page', 99 );
            if( is_cart() ) {
    
                wc_print_notice(
                    sprintf( 'Your current order total is only %s.' ,
                        wc_price( WC()->cart->total ),
                        wc_price( $minimum )
                    ), 'error'
                );
    
            } else {
    
                wc_add_notice(
                    sprintf( 'Your current order total is only %s.' ,
                        wc_price( WC()->cart->total ),
                        wc_price( $minimum )
                    ), 'error'
                );
    
            }
        }
    }
    
    function wt_show_paypal_express_button_in_cart_page($show){
    	$show = false;
    	return $show;
    
    }
    function wt_show_paypal_express_button_in_checkout_page($show){
    	$show = false;
    	return $show;
    
    }
    
    // END Minimum Spend £24 for Nick

    However I’ve been looking at alternative solutions since an issue where a user was unable to checkout with a PW gift card code that produced £0.00 total.

    Here are two we looked at today:

    https://wordpress.org/plugins/order-minimum-amount-for-woocommerce/

    https://woostify.com/woocommerce-minimum-order/

    We are completely open to suggestions though if you can recommend a better solution!

    Many thanks
    Warren

    • This reply was modified 1 year, 8 months ago by Warren.
    Plugin Author pimwick

    (@pimwick)

    Try adding this code in required_min_cart_subtotal_amount():

    // Add an error notice is cart total is less than the minimum required
           if( $total <= $min_total  ) {
    
                if ( defined( 'PWGC_SESSION_KEY' ) ) {
                    $session_data = (array) WC()->session->get( PWGC_SESSION_KEY );
                    if ( isset( $session_data['gift_cards'] ) && count( $session_data['gift_cards'] ) > 0 ) {
                        // Gift cards are in use on this order, bypass the minimum order requirement.
                        return;
                    }
                }
    Thread Starter Warren

    (@rabbitwordpress)

    Hi @pimwick

    Thanks for the code above!

    I tried it but sadly it caused an error.

    Many thanks
    Warren

    Plugin Author pimwick

    (@pimwick)

    Can you provide the error message? The code above is just a snippet of what should be inserted into your existing code (I left a few lines of your code so you can see where to put the new code).

    Thread Starter Warren

    (@rabbitwordpress)

    Hi @pimwick

    Aaah yes that works perfectly, thanks so much! I actually put it in two places to hide all the notices.

    Here’s the complete code for anyone who might be looking for the same solution:

    // Minimum Spend £24 Except when using Gift Card
    
    add_action( 'woocommerce_check_cart_items', 'required_min_cart_subtotal_amount' );
    function required_min_cart_subtotal_amount() {
        // Only run in the Cart or Checkout pages
       if( is_cart() || is_checkout() ) {
    
            // HERE Set minimum cart total amount
           $min_total = 24;
    
            // Total (before taxes and shipping charges)
           $total = WC()->cart->subtotal;
    
            // Add an error notice is cart total is less than the minimum required
           if( $total <= $min_total  ) {
             if ( defined( 'PWGC_SESSION_KEY' ) ) {
                 $session_data = (array) WC()->session->get( PWGC_SESSION_KEY );
                 if ( isset( $session_data['gift_cards'] ) && count( $session_data['gift_cards'] ) > 0 ) {
                     // Gift cards are in use on this order, bypass the minimum order requirement.
                     return;
                 }
             }
                // Display an error message
               wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($min_total) ) . '<strong>', 'error' );
           }
       }
    }
    /**
     * Set a minimum order amount for checkout
     */
    add_action( 'woocommerce_before_checkout_form', 'wc_minimum_order_amount' );
    add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
    add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
    
    function wc_minimum_order_amount() {
        // Set this variable to specify a minimum order value
        $minimum = 24;
    
        if ( WC()->cart->total < $minimum ) {
    
          if ( defined( 'PWGC_SESSION_KEY' ) ) {
              $session_data = (array) WC()->session->get( PWGC_SESSION_KEY );
              if ( isset( $session_data['gift_cards'] ) && count( $session_data['gift_cards'] ) > 0 ) {
                  // Gift cards are in use on this order, bypass the minimum order requirement.
                  return;
              }
          }
    
    		add_filter( 'wt_show_paypal_express_button_in_cart_page', 'wt_show_paypal_express_button_in_cart_page', 99 );
    		add_filter( 'wt_show_paypal_express_button_in_checkout_page', 'wt_show_paypal_express_button_in_checkout_page', 99 );
            if( is_cart() ) {
    
                wc_print_notice(
                    sprintf( 'Your current order total is only %s.' ,
                        wc_price( WC()->cart->total ),
                        wc_price( $minimum )
                    ), 'error'
                );
    
            } else {
    
                wc_add_notice(
                    sprintf( 'Your current order total is only %s.' ,
                        wc_price( WC()->cart->total ),
                        wc_price( $minimum )
                    ), 'error'
                );
            }
        }
    }
    
    function wt_show_paypal_express_button_in_cart_page($show){
    	$show = false;
    	return $show;
    
    }
    function wt_show_paypal_express_button_in_checkout_page($show){
    	$show = false;
    	return $show;
    
    }
    
    // END Minimum Spend £24 Except when using Gift Card

    Many thanks
    Warren

    • This reply was modified 1 year, 8 months ago by Warren. Reason: Changed the comment to be more descriptive

    Hey,

    I’m facing the same issue except I’m using standard WooCommerce -> Marketing -> Coupons section to create coupons.

    Would it be possible to adapt this code for my use case as well?

    I’m using basic code to require minimum order amount:

    Thank you for your time

    /**
     * Set a minimum order amount for checkout
     */
    add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
    add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
     
    function wc_minimum_order_amount() {
        // Set this variable to specify a minimum order value
        $minimum = 13.13;
    
        if ( WC()->cart->total < $minimum ) {
    
            if( is_cart() ) {
    
                wc_print_notice( 
                    sprintf( 'Minimali užsakymo suma yra 13.13€' , 
                        wc_price( WC()->cart->total ), 
                        wc_price( $minimum )
                    ), 'error' 
                );
    
            } else {
    
                wc_add_notice( 
                    sprintf( 'Minimali užsakymo suma yra 13.13€' , 
                        wc_price( WC()->cart->total ), 
                        wc_price( $minimum )
                    ), 'error' 
                );
    
            }
        }
    }
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Bypass minimum order amount when using gift card’ is closed to new replies.