0

I am developing a Woocommerce shop. I have minimum order amount for ordering for specific postcodes. How to display error message when the user fills checkout form, particularly the post code field, when he typed postcode then show him a error message that the minimum order amount is not reached for his postcode. Currently, I am having this messages to throw when the user click place order button at last.

Based on Set a minimum order amount in WooCommerce answer, that is my code:

add_action( 'woocommerce_checkout_process' , 'required_min_cart_subtotal_amount');

// Only run in the Cart or Checkout pages
function required_min_cart_subtotal_amount() {
    
    if( is_checkout()) {
        global $woocommerce;

        // Set the minimum order amount and shipping zone before checking out
        $county1    = array(69214);
                
        // Defining var total amount      
        $cart_tot_order = WC()->cart->total;
        
        if( $cart_tot_order < 8 && in_array( WC()->customer->get_shipping_postcode(), $county1 )  ) {
            // Display error message
             wc_add_notice( sprintf( '<strong>Eine Mindestbestellmenge von $% s ist erforderlich, um an Ihre Adresse zu liefern.</strong>' 
                . '<br />Aktueller Auftrag: $%s.',
                8,
                $cart_tot_order ),
            'error' );
            
        }}
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Tom
  • 87
  • 1
  • 9
  • 1
    Sorry but "I want to" is not a question – RiggsFolly Sep 10 '20 at 11:12
  • Yeah @LoicTheAztec, but i am skipping the cart page, and how can i implement that when user types post code in checkout page, it involves with order total and postcode... – Tom Sep 10 '20 at 11:43
  • I don't know has you get a problem with [Paypal Express checkout that is hiding custom error message](https://stackoverflow.com/questions/63815069/paypal-express-checkout-is-hiding-custom-error-message) – LoicTheAztec Sep 10 '20 at 12:41
  • Yeah, that's why I am thinking to implement the error messages in this way..... – Tom Sep 10 '20 at 12:50

0 Answers0