How to duplicate attribute to custom field?

Going to each product page to duplicate the attribute to a custom field can be time consuming. There are more efficient ways to accomplish this task:

Note: Always take a database backup first!

Method 1: Import / export products

  • Use the woocommerce import / export product facility to first export the products as a CSV file. This file can be viewed as a spreadsheet via Excel (Windows) or Numbers (Mac).
  • In that exported CSV file, products are listed in rows and their properties are listed in column. You need to create a new column that will contain a new custom field for the products. This new column needs to have the heading ‘Meta: *attribute name*’ where your need to replace *attribute name* with the name of the actual attribute (Color, Size, etc) or custom field name that you want to use. Before continuing with this step, please refer to the ‘Important notes on creating the new meta column’ section below.

  • After you have added the new meta field column to the file, you need to save the file as CSV. Now import this modified csv file into your site again. During import, ensure you check the option to ‘Update existing products’. After the import process (could take some time depending on the number of products and properties) you should have the new custom field prepared for each product based on the mtea column you created in the import file.

Important note on creating the new meta column:

In the exported excel file please notice 2 things:

  • Attribute information is split over multiple columns: Name, Values, Visible, Global, Default. Only the Name and Values column are relevant to us here, so we will ignore the rest. The Name column helps us identify which attribute(s) this column pertains to and the values are needed to be copied over to the new duplicate meta column.
  • Second thing to notice – in the above screenshot Attribute 1 name column only contains the Color attribute. So you might be tempted to simply duplicate its values column, rename the heading of the duplicate to Meta: Color and be done with the process. While this may work in this particular case, please keep in mind that the attribute columns in your export file might contains information about multiple attributes in the same column.
  • For example, in the screenshot below notice that the ‘Attribute 2 name’ column contains 2 distinct attributes – Size and Logo. So, in this case, duplicating the ‘Attribute 2 value(s)’ column to create a new meta column for Size attribute will be a mistake. As you can imagine, such a duplicate column will also contains values for Logo attribute. So, you will need to be careful that only relevant values are copied over to the new meta column.
  • In this example, to create a meta column for the Size attribute, we can duplicate the values column, but then we need to carefully go over the column values in our duplicate and delete the values that are not related to Size.

If you have any confusion about this method and need more clarity please do not hesitate to write into support to receive prompt assistance with this.

Method 2: Bulk product editor plugin

This method may be a little slower than the previous one, but users might find this simpler. There are several woocommerce bulk product editor plugins available that will allow you to edit several products at a go using a simple UI. Some notable ones:

The above links are for the free versions of the plugin. Some features are only available in the PRO version.

Method 3: Automate via PHP Code

You can also write PHP code to create a solution that automatically duplicates your current attribute values to custom fields as well as ensures future attribute values also automatically get duplicated to custom fields without any additional updates required at your end.

In many ways this is the best solution, but it requires programming knowledge and since the solution works on its own into the future, it is important the code doesn’t have errors that can cause problems later on.

Such code is not in the scope of this doc. Please contact an experienced PHP dev or write in for a custom solution if you want to go ahead with this method.