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
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.
Go to: WooCommerce > Settings > Shipping > Shipping Zones. Hover over the Shipping Zone you wish to change, and select Edit.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With