I have tried to do it using a filter hook called "woocommerce_countries". I tried getting the cart total in this hook but it's not working. Is anyone have any idea on this OR suggest any hook?
Asked
Active
Viewed 140 times
1 Answers
0
Please try with this code. WooCommerce 3.6.2
, they have removed the ability to check the cart data. But cart session is accessible right now so we use this function WC()->session->cart
add_filter( 'woocommerce_countries', 'products_disable_country', 10, 1 );
function products_disable_country( $countries ) {
$cartdata = WC()->session->cart;
if (is_array($cartdata) && !empty($cartdata)) {
foreach ($cartdata as $itemdata) {
$sum += $itemdata['line_total'];
}
if ($sum >= 100) {
unset($countries["CA"]);
}
}
return $countries;
}

Team Dolphin
- 173
- 7
-
Thank @Team Dolphins, I made minor changes and it almost works. Only facing issue when updating cart quantity. Like, it's only reflected when the page refresh. – Rahul Gandhrokiya Apr 06 '21 at 11:41
-
on the cart page change Change address? I will check my local demo with storefront theme it's work on update cart – Team Dolphin Apr 06 '21 at 11:45
-
While changing the quantity on the cart page. – Rahul Gandhrokiya Apr 06 '21 at 11:49
-
on cart page It's Work with storefront theme so may be it's conflict with your theme – Team Dolphin Apr 06 '21 at 12:08