WooCommerce set a min order price for a single country
Question
I’m trying through this code to set a minimum price for orders:
// Set a minimum dollar amount per order
add_action( 'woocommerce_check_cart_items', __NAMESPACE__ . 'spyr_set_min_total' );
function spyr_set_min_total() {
// Only run in the Cart or Checkout pages
if ( is_cart() || is_checkout() ) {
global $woocommerce;
// Set minimum cart total
$minimum_cart_total = 10;
// Total we are going to be using for the Math
// This is before taxes and shipping charges
$total = WC()->cart->subtotal;
// Compare values and add an error is Cart's total
// happens to be less than the minimum required before checking out.
// Will display a message along the lines of
// A Minimum of 10 USD is required before checking out. (Cont. below)
// Current cart total: 6 USD
if ( $total <= $minimum_cart_total ) {
// Display our error message
wc_add_notice(
sprintf(
'You have not yet reached the minimum order of € 10,00.' .
'Your order is: %s %s',
$total,
get_option( 'woocommerce_currency' )
),
'error'
);
}
}
}
So everything works, but I need to enable it only for orders placed in UK.
I thought that the solution could be adding these variables:
$states = array( 'UK' );
$shippingaddr = WC()->customer->shipping_state;
if ( is_cart() || is_checkout() || $shippingaddr = $states ) {
but it’s not working. Any suggestions?
EDIT.
CORRECT CODE
// Only run in the Cart or Checkout pages
global $woocommerce;
if( ( is_cart() || is_checkout()) && "UK" == WC()->customer->shipping_country )
// Set minimum cart total
$minimum_cart_total = 10;
0
4 months
0 Answers
13 views
0
Leave an answer
You must login or register to add a new answer .