WooCommerce Minimum Order – Exception on user account

I am building a wholesale ecom site for a client. They require a minimum order of $300 in order for the sale to go through. Clients must be logged in, in order to access the site and place orders.

There is one client that needs the minimum order to be removed. So he/she can place orders under $300 successfully.

Read More

Here is the current code I am using to generate the minimum order:

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 = 354.93;

        if ( WC()->cart->total < $minimum ) {

            if( is_cart() ) {

                wc_print_notice( 
                    sprintf( 'Votre commande doit être au minimum de 300$ afin de se qualifier pour les prix de distributeur et pour compléter votre commande.' , 
                        woocommerce_price( $minimum ), 
                        woocommerce_price( WC()->cart->total )
                    ), 'error' 
                );

            } else {

                wc_add_notice( 
                    sprintf( 'Votre commande doit être au minimum de 300$ afin de se qualifier pour les prix de distributeur et pour compléter votre commande.' , 
                        woocommerce_price( $minimum ), 
                        woocommerce_price( WC()->cart->total )
                    ), 'error' 
                );

            }
        }

    }

I can not figure out how to adjust the clients account so that the above code is discarded when they are browsing the site.

Any help would be greatly appreciated.

Related posts

Leave a Reply

1 comment

  1. At the easiest, but least extensible to other future clients:

    if ( WC()->cart->total < $minimum && get_current_user_id() != 999 )
    

    where 999 is the user ID of the client for whom you wish to forgo the $300 minimum.

    You could create a custom capability and using a roles manager type of plugin assign a special role to all customers for whom the minimum does not apply:

    if ( WC()->cart->total < $minimum && ! current_user_can('ignore_cart_minimum' ) )
    

    EDIT

    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 = 354.93;
    
            if ( WC()->cart->total < $minimum && get_current_user_id() != 999 ) {
    
                if( is_cart() ) {
    
                    wc_print_notice( 
                        sprintf( 'Votre commande doit être au minimum de 300$ afin de se qualifier pour les prix de distributeur et pour compléter votre commande.' , 
                            woocommerce_price( $minimum ), 
                            woocommerce_price( WC()->cart->total )
                        ), 'error' 
                    );
    
                } else {
    
                    wc_add_notice( 
                        sprintf( 'Votre commande doit être au minimum de 300$ afin de se qualifier pour les prix de distributeur et pour compléter votre commande.' , 
                            woocommerce_price( $minimum ), 
                            woocommerce_price( WC()->cart->total )
                        ), 'error' 
                    );
    
                }
            }
    
        }