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);
-
This reply was modified 2 years, 5 months ago by
rafaelrafael.
Zee
(@doublezed2)
Hello rafaelrafael
We are glad to know that you were able to find a solution to set specific countries via php.
Appreciate you for sharing your solution here with other fellow users.
It is because of people like you that the WordPress community is thriving 🙂
Thank you and have a great day!
Thank YOU, without your help I would dig forever 🙂 Thanks, have a gread day 🙂
Hey @rafaelrafael,
We’re happy to help!
Since this has been marked as resolved, feel free to create a new topic if you need any further help. 🙂
Also, if you have a minute, we’d love it if you could leave us a review:
https://ww.wp.xz.cn/support/plugin/woocommerce/reviews/
Cheers!