John Davidson

php - Set WooCommerce user billing and shipping country programmatically

0 comments
Message:


I use WooCommerce and I build some custom functions.
The last thing what I want is set the country for billing and shipping programmatically.


I removed the input billing_country and shipping_country from the checkout page.


Is there a way to set the billing_country and shipping_country programmatically?


I tried WC()->customer->set_shipping_country('US'); this set only the country for the cart and checkout page but does not send the country by submit.



My Answer:
>customer->set_billing_country( 'US' );
WC()->customer->set_shipping_country( 'US' );

This code snippet should set the billing and shipping country to 'US' programmatically. You can replace 'US' with the desired country code. Make sure to place this code in a suitable hook or function in your theme's functions.php file or a custom plugin.

Rate this post

5 of 5 based on 6861 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us