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?
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.
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.
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.
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.
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 );
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