Rynald0s
(@rynald0s)
Automattic Happiness Engineer
Hi
You are currently using:
$state = array('BG-23');
$cart_total_order = WC()->cart->total;
if( $cart_total_order < $minimum && in_array(WC()->customer->get_shipping_state(), $state ) ) {
You’ll want to use something like this:
$state = $woocommerce->customer->get_shipping_state();
if( $cart_total_order < $minimum && $state == 'BG-23' ) {
Let me know if that helps.
Cheers!
-
This reply was modified 5 years, 9 months ago by
Rynald0s.
Hello,
Thank you for your replay.
I’m sorry, but it doesn’t work, it still allows me to complete my order even if the amount is below the minimum…
I’ve tried this function for disabling proceed to checkout button, but I have an error and I don’t know where to insert it to work well.
function disable_checkout_button_no_shipping() {
remove_action( ‘woocommerce_proceed_to_checkout’, ‘woocommerce_button_proceed_to_checkout’, 20 );
echo ‘Proceed to checkout‘;}
add_action( ‘woocommerce_proceed_to_checkout’, ‘disable_checkout_button_no_shipping’, 1 );
Can you edit it for me and tell me where to insert it?
Best wishes,
Stefani
-
This reply was modified 5 years, 9 months ago by
stefanig.
-
This reply was modified 5 years, 9 months ago by
stefanig.
Rynald0s
(@rynald0s)
Automattic Happiness Engineer
Hi @stefanig!
The following code works for me, so maybe modify this to fit your specific needs.
In the case, I am requiring a minimum order value of $25 if the state is CA (California). It does not allow checkout. Instead, it displays an error that there is a problem in the cart, and the cart itself echoes the error message within the code:
add_action( 'woocommerce_check_cart_items', 'wc_min_order_total' );
function wc_min_order_total() {
if( is_cart() || is_checkout() ) {
global $woocommerce;
$minimum = 25;
$state = array('CA'); //California
$cart_tot_order = WC()->cart->total;
$state = $woocommerce->customer->get_shipping_state();
if( $cart_total_order < $minimum && $state == 'CA' ) {
wc_add_notice( sprintf( '<strong>A Minimum order of $%s is required before checking out.</strong>'
. '<br />Current order: $%s.', $minimum, $cart_tot_order ), 'error' );
}
}
}
You can extend the array and add more states if you like.
Cheers!
-
This reply was modified 5 years, 9 months ago by
Rynald0s.
@rynald0s
Тhank you so much, it works correctly! 🙂
Have a nice day! 🙂