The Prices by Country plugin stores product prices in post meta table. They can be manipulated by using the standard update_post_meta() and get_post_meta() functions. For the data to be used correctly, it's important that the country specific prices are associated to the correct region. Below you can find the instructions to determine the ID of each region, and how to assign it to prices.


1. Create the appropriate regions

Before prices can be imported, you must create one or more regions. To do so, go to WooCommerce > Prices by Country and create the regions you need.


2. Write down the ID of each region

Region IDs are alphanumeric values generated automatically and stored with the Prices by Country plugin's settings. You can fetch option IDs in two ways:


If you are running the Prices by Country plugin 1.6.17.160223 and later, you can find this information in the plugin's settings page. See screenshot, below.


If you are running an earlier version of the plugin, you can either update the plugin, or retrieve the region IDs from the options table. You can use the following query to get the plugin options:  

SELECT option_value
-- Make sure that you change the "wp_" prefix as appropriate
FROM wp_options 
WHERE option_name = 'wc_aelia_prices_by_country'

 Field option_value will contain the plugin settings, which include a section with a list of regions and their IDs.


3. Import product prices for each region

Product prices are stored in a product's meta, which can be found in the postmeta table. The data is saved as a serialised PHP array, with the meta key _prices_by_country. Here's an example of the data, unserialised:   

array
(
  // The numeric key is a region ID
  '7c337ba8befab52b27856bb048e91d8b' => array
    (
      // The entry contains one set of prices for each currency. If your shop
      // only uses one currency, you will only have one set of prices
      'CAD' => array
        (
          'sale_price' => '1.23',
          'regular_price' => '4.56',
          // The subscription_signup_fee is only applicable for subscription
          // products. If not needed, it can be omitted, or left empty (see
          // below)
          'subscription_signup_fee' => '7.89',
        ),
      // Prices for additional currencies
      'EUR' => array
        (
          'sale_price' => '2.34',
          'regular_price' => '3.45',
          // To leave a product empty, set it as an empty string. Don't set it
          // as zero, as that is a valid price and it will be used for the product
          'subscription_signup_fee' => '',
        )
    )
)

 Once serialised, the data will look be stored follows: 

a:1:{s:32:"7c337ba8befab52b27856bb048e91d8b";a:2:{s:3:"CAD";a:3:{s:10:"sale_price";s:4:"1.23";s:13:"regular_price";s:4:"4.56";s:23:"subscription_signup_fee";s:4:"7.89";}s:3:"EUR";a:3:{s:10:"sale_price";s:4:"2.34";s:13:"regular_price";s:4:"3.45";s:23:"subscription_signup_fee";s:0:"";}}}


How to serialise the data in the correct format

Depending on which tool you use to store the data, the serialisation may be automatic. This is the case with several CSV Import plugins. Such plugins can accept a JSON string in the CSV file to import, and they will transform it into the correct format automatically. Here is the above data in JSON format, ready to be imported.

{"7c337ba8befab52b27856bb048e91d8b":{"CAD":{"sale_price":"1.23","regular_price":"4.56","subscription_signup_fee":"7.89"},"EUR":{"sale_price":"2.34","regular_price":"3.45","subscription_signup_fee":""}}}

 

3.1 Importing and exporting product prices using the built-in tools offered by WooCommerce

WooCommerce includes tools to simplify the import and export operations of product data. Since version 1.10.4.200526, the Prices by Country plugin includes native support for that tool. Below you can find the steps to import and export the plugin's data.


3.1.1 How to export prices by country and availability by country

To export the prices and availability data for the configured countries, please proceed as follows:

1. Open the Product Export tool, located at WooCommerce > Products > Export.

2. In the field labelled "Which columns should be exported?", select the following columns:

  1. Prices by Country (JSON encoded)
  2. Availability by Country (JSON encoded)


Note: if you translated the plugin, the names of the columns might have been changed to their equivalent in your language. Please make sure that you select the correct columns. 

3. Export the products. The resulting CSV file will include the selected columns.


3.1.2 How to import prices by country and availability by country

To import the prices and availability data for the configured countries, please proceed as follows:

1. Open the Product Import tool, located at WooCommerce > Products > Import.

2. Select a CSV file to import.

3. In the field mapping section, scroll until you find the following fields:

  1. Prices by Country (JSON encoded)
  2. Availability by Country (JSON encoded)

Note: if you translated the plugin, the names of the columns might have been changed to their equivalent in your language. Please make sure that you select the correct columns.

4. Click on "Run the importer" to import the products. The content of the custom fields used by the Prices by Country plugin will be processed automatically and stored against each product.


4. Review the imported prices

After you ran the import process, go to the Edit Product page for one of the imported products. If the import was successful, you should see the new prices in the "Prices by Country" section (see below).



You can purchase the Prices by Country plugin from our online shop.