Hello @rafaelrafael,
Thank you for reaching out!
Hi! I want to set “Sell to specific countries” via php and set several countries, so that they are saved in DB and appear in that field with specific countries.
The country list is saved in a database option named (serialized) woocommerce_specific_allowed_countries.
You can update it just like any other stored wp_options. Here are some resources that might help:
Also, just a small reminder, custom requests are not something we can assist with generall per our support policy. If you need more help with this, you might want to check the #developers channel of the Woo Community Slack or hire a WooExpert.
Cheers!
Thank you very much! I’m not experienced in developing, only learning at the moment, so I’m really appreciated. Thank you)
For anyone who may need this? Here is the coding:
// Set “Selling locations” to “Sell to specific countries”
update_option(‘woocommerce_allowed_countries’, ‘specific’);
// Array with your countries (use country codes)
$countries = array(‘US’, ‘CA’, ‘GB’, ‘AU’);
// Save our options
update_option(‘woocommerce_specific_allowed_countries’, $countries);
