Get shipping country during cart view - WooCommerce

Cedric De Clercq picture Cedric De Clercq · Jun 15, 2016 · Viewed 8.7k times · Source

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

Answer

YajiV picture YajiV · Jun 16, 2016

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.