Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce: get and set shipping & billing address's postcode

How do I set/get the Postcode(Zip-code) in woocommerce? Is there a function for this?

ie., can I set the zip code through any function?

I would also like to know, how to populate this field with my data(say 546621) if the user is not logged in?

like image 809
Nagendra Rao Avatar asked Oct 03 '13 09:10

Nagendra Rao


People also ask

How do I set up shipping in WooCommerce?

Start by navigating to WooCommerce → Settings → Shipping in your dashboard, which contains your options for Shipping Zones. A shipping zone is a geographical area that you ship to, defined by countries, regions, states, and zip codes. Set up shipping zones to define different rates based on customers' locations.

How do I get the selected shipping method in WooCommerce?

If you want to use a shipping method other than default USPS shipping, you can add a shipping method in WooCommerce. To do so, go to WooCommerce > Settings > Shipping, and select the shipping method you want to use.

How do I set up calculated shipping in WooCommerce?

Go to WooCommerce > Settings > ACS Web Services. Check Enable ACS Automatic Shipping Calculation and press Save. On Weight you will be able to select Automatic Weight if you want to calculate the shipping fee based on order's total weight or select flat to set a fixed order weight.

How do I change the default shipping method in WooCommerce?

To do so, select and hold the three bars on the left-side of the shipping method name (local pickup, flat rate, or free shipping) and drag it up or down in the list. The default shipping method for that shipping zone will be the top, enabled method in the list.


1 Answers

You can do the following to get/set billing/shipping postcodes,

To set the values,

$customer = new WC_Customer();
$customer->set_postcode('123456');     //for setting billing postcode
$customer->set_shipping_postcode('123456');    //for setting shipping postcode

If you just want to fetch the postcodes, you can fetch it from the user meta table itself,

$shipping_postcode = get_user_meta( $current_user->ID, 'shipping_postcode', true );
$billing_postcode = get_user_meta( $current_user->ID, 'billing_postcode', true );
like image 123
Nagendra Rao Avatar answered Sep 23 '22 12:09

Nagendra Rao