Get shipping country during cart view - WooCommerce
12,210
If I am not wrong, you are looking for the code to get shipping country set on WooCommerce cart / checkout page. Below code is tested till WooCommerce 2.4.
Method #1:
global $woocommerce;
$woocommerce->customer->get_shipping_country()
Method #2
WC()->customer->get_shipping_country()
Note that there are major changes on shipping side from WooCommerce 2.6. But from the GitHub reference, it should work.
Author by
Cedric De Clercq
Updated on June 24, 2022Comments
-
Cedric De Clercq over 1 year
I want to get the chosen shipping country when on the cart / checkout (so before the order is placed). This is to determine if an extra fee (above the normal shipping costs) must be added.
How can i get the chosen country for this function? I use it in an if-function (in this example for the country 'Belgium'):
` elseif ($total >= $min_order and $chosen_shippingcountry = 'BE') {$fees = 10;}`
Can anyone help?
Thanks!
Regards, Cedric
-
anhduc.bkhn over 4 yearscomfirm both of method it is still working on Woocommerce Version 3.4.5