How to set specific countries via php

[ad_1]

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 site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer