Importing Variable Products to WooCommerce

In-Depth Tutorial: How To Import Product Variations From a CSV, XML, or Excel File

About these docs: We have a few video tutorials covering different use-cases below. To learn more about the other features of the WooCommerce add-on such as syncing stock levels, use the documentation menu to the right. Below the videos is also text documentation explaining the same things as the videos – so watch if you prefer videos, or read if you prefer text. We recommend the videos!

Part 1: Importing Variations From CSV or XML



Part 2: Importing Variations Stored As Child Elements from XML

You’ll notice that in the above tutorial, I only import from CSV files. However, importing from an XML file that is structured in a similar way to a CSV file is exactly the same. For example, if your XML file contains many <product> elements, and each <product> element contains either a different product or variation, then the process is exactly the same.

However, some XML feeds store their variations as children of the main product element, for example:

<product>
  <title>My Product</title>
  <variations>
   <variation>
   <variation>
   <variation>
 </variations>
</product>

In this case, the next video tutorial explains what to do.



Part 3: Setting Up An Excel File To Import Product Variations

Maybe you want to manually create a file containing your variations, because you don’t already have a point of sale or inventory management system that does it for you, or don’t have a product feed from a dropshipper or affiliate network. Sad days… but here’s how to do it, using Excel:



Now for the text documentation…

When importing variations with WP All Import, choose “Variable Product” in the WooCommerce add-on in Step 3 of WP All Import.

Then, you must configure three things:

  • General tab: you must specify the price. WooCommerce won’t show variations on the frontend of your site unless the price is present.
  • Attributes tab: here you specify the variation attributes – for example Size or Color.
  • Variations tab: here you specify how WP All Import links multiple variations from your XML or CSV file together to form a single variable product.

It is highly recommended that you watch the video above before reading onwards, as the video will give you a big picture overview of how to import variations, while you can specific details below.


Linking Multiple Variations Together To Form A Variable Product

WooCommerce stores a variable product as a single “parent” product, with multiple “child” variations.

For example, a T-Shirt might have three “child” variations – Small, Medium, and Large.

WP All Import can import XML and CSV files that contain parent products with child variations, and it can also import files that only contain product variations, with no parent products.

On the Variations tab of the WooCommerce Add-On, you specify how WP All Import groups multiple product variations into a single variable product. Typically, for CSV files, you’ll have one product variation per row, and for XML files, one product variation per record.


Example A – Linking Variations To Parent Based On Parent SKU


storing product variations in a CSV file

In this example, you’ll notice there are two products (a mug and a t-shirt), with three variations each (based on Color).

In this example our file contains both the parent products and the variations.

The variations are grouped to their parent products using the SKU and Parent SKU columns. We can use the Parent SKU column to tell WP All Import to assign the variations to the parent product that has an SKU that is the same as the variation’s Parent SKU.

Download: CSV · XML



Example B – Product Variations Grouped By A Unique Identifier


variable products grouped together with a unique identifier

In this example, you’ll notice there are two products (Coca Cola and Sprite), with four variations each (based on Size).

The variations are grouped together with the Group ID column.

We can use the Group ID column to tell WP All Import to group all the variations with the same group ID into a single variable product.

In this example our CSV file contains only variations. There are no parent products, but since WooCommerce requires parent products, WP All Import will automatically create the parent products for us.

Download: CSV · XML



Example C – Variations Grouped By Title


matching by title

In this example, you’ll notice there are two products (Steak and Lamb), with three variations each, based on Weight for the Steak, and Quantity for the Lamb.

The Quantity attribute will be ignored for the Steak, and the the Weight attribute will be ignored for the Lamb.

In this example our file contains both the parent products and the variations.

The variations are grouped together by title. We can use the Product Title column to tell WP All Import to assign the variations to the parent product that has the same title.

Download: CSV · XML



Example D – Variations Grouped By Title, No Parent Products



In this example, you’ll notice there are two products (Apple tree and Orange tree), with four variations each, based on the tree height and type of rootstock.

In this example our file contains only variations, without parent products. WP All Import will automatically create the parent products.

The variations are grouped together by title. We can use the Product Title column to tell WP All Import to create multiple variable products, with each one containing all the variations with the same title.

Download: CSV · XML



Example E – Variations As Child XML Elements

If you are importing an XML file and the variations are child elements of your product elements, instead of separate product elements, use this option.

In the example XML below, you can see all variations of a product are enclosed in a element, where one product can have any number number of variants.

<Product>
 <SKU>10027105</SKU>
 <Brand_Name>Adidas</Brand_Name>
 <Product_Name>Adidas Mens Climacool Boat Lace Shoes - Sale</Product_Name>
 <Long_Description>...</Long_Description>
 <Short_Description>...</Short_Description>
 <Category>Footwear</Category>
 <SubCategory>Casual</SubCategory>
 <Product_Group>Men's</Product_Group>
 <Thumb_URL>...</Thumb_URL>
 <Image_URL>...</Image_URL>
 <Buy_Link>...</Buy_Link>
 <Retail_Price>74.99</Retail_Price>
 <Sale_Price>59.99</Sale_Price>
 <Extended_Xml_Attributes>
  <variants>
   <variant>
    <sku>19301</sku>
    <upc>0886833708180</upc>
    <size>8</size>
    <color>Dark Indigo</color>
    <retail_price>74.99</retail_price>
    <sale_price>59.99</sale_price>
    <action_url>...</action_url>
   </variant>

   <variant></variant>

   ...

  </variants>
 </Extended_Xml_Attributes>
</Product>

When importing variations in this format, you don’t need to set anything in the General tab or the Attributes tab. You set the price and the attributes in the Variations tab.

For WP All Import to detect the variations, you must define the XML elements that contain them. You can do this by dragging & dropping one of the <variant> elements to the Variations XPath box.



You then set your attributes by dragging & dropping attributes from the popup XML tree containing the XML for the variation, instead of using the main XML tree.

You can set your price using the price in the popup XML tree if available, or if you want to set all the variation prices to the price of the parent product, you can drag the price from main XML tree. When dragging XPath from the main XML tree to any of the boxes below Variations XPath, you must check the XPath from Parent option.


importing variations from XML to woocommerce

In the screenshot above, you can see there are 10 total variants of the current product. Configure the options for just one, and WP All Import will automatically loop through the other 9 variations and create variations for all of them.


Configuring Variation Attributes

Attributes are those things that users can change to choose the variation they want. Each attribute can have multiple possible values – users select these values to choose the particular variation they want to purchase. For example, a T-Shirt could have Color and Size attributes.



In the example above, the two Attributes are Size and Depth. Attributes can be configured on the Attributes tab of the WooCommerce add-on.



Additional Information On Attributes

If your file has many types of variable products with different attributes – for example, t-shirts in your file have Size and Color attributes, and paintings and posters have Canvas Size and Depth attributes,  in the same file, just configure all the attributes in WP All Import. WP All Import will ignore the attributes when they don’t exist for a particular product in your file. So you won’t end up with t-shirts with Canvas Size and Depth attributes, or posters with Size and Color attributes.

Some attribute names are reserved. For example, you can’t use “Type”. If you can’t use a certain attribute name inside of WooCommerce, you can’t use it inside WP All Import either.


Additional Information

Importing Simple And Variable Products At The Same Time

Configure your import as if you were only importing variable products.

WP All Import will automatically create simple products for products that have no variations or only a single variation.

Using Link All Variations

On the Attributes tab, you’ll notice a Link All Variations option. Use this option if the data for your variations is stored all in a single row. It works just like the Link All Variations option inside WooCommerce.



In above example, ‘Baseball Cap’ is a product with 3 color variations and ‘Mug’ is one with 2 color variations.

Each color is separated by a pipe symbol – “|”.

Using the settings below, the WooCommerce add-on for WP All Import will automatically generate variations for each color.

If your file is using something other than a | as a separator, you can use a PHP function to replace the it with a |.

For example, if you had a Color column containing “Red,Blue,Green”, you’d replace the commas with pipes like this:

[str_replace(",", "|", {Color[1]})]