Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get shipping country during cart view - WooCommerce

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

like image 374
Cedric De Clercq Avatar asked Jun 15 '16 19:06

Cedric De Clercq


People also ask

How do I show shipping address in WooCommerce?

Click on the Shipping tab and then scroll down to the Shipping Options section. Here, you will see an option to display the shipping address on the checkout page. Simply check the box next to this option and save your changes. Another way to show a shipping address in WooCommerce is to use a plugin.

How do I change the shipping country in WooCommerce?

Go to: WooCommerce > Settings > Shipping > Shipping Zones. Hover over the Shipping Zone you wish to change, and select Edit.

How do I restrict shipping location in WooCommerce?

Shipping DestinationsNavigate to WooCommerce > Settings > Restrictions. Navigate to the Payment Gateways, Shipping Methods, or Shipping Destinations section, depending on the type of restriction you want to create. Click the Add Restriction button.


1 Answers

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.

like image 110
YajiV Avatar answered Sep 28 '22 09:09

YajiV