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' );
}}