I am using a custom code that shows a notification of the minimum order amount and blocks the checkout button if the amount is less.
/* Minimum Order Notification */
add_action('woocommerce_check_cart_items', 'custom_checkout_min_order_amount');
function custom_checkout_min_order_amount() {
$minimum_amount = 1000;
if (WC()->cart && WC()->cart->subtotal < $minimum_amount) {
wc_add_notice(
sprintf(
'The minimum order is %s. Your order is for %s. You need to add more %s',
wc_price($minimum_amount),
wc_price(WC()->cart->subtotal),
wc_price($minimum_amount - (WC()->cart->subtotal))
),
'error'
);
}
}
remove_action( 'woocommerce_before_cart', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_cart_totals_after_order_total', 'woocommerce_output_all_notices', 10 );
/* Blocking the checkout button */
add_action( 'woocommerce_proceed_to_checkout', 'disable_checkout_button', 1 );
function disable_checkout_button() {
$minimum_amount = 1000;
$total = WC()->cart->cart_contents_total;
if( $total < $minimum_amount ){
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
echo '<a style="pointer-events: none !important; background: #fb7df3;" href="#" class="checkout-button button alt wc-forward">Proceed to checkout</a>';
}
}
I added this notification to the "Your Order" block. There is a problem when automatically updating the quantity of products in the cart, this notification disappears.
How to make the notification not respond to the cart update or show the notification again after the update. I can't find the right code for this.
add_action('woocommerce_after_cart_item_quantity_update','disable_checkout_button');