In WooCommerce you can add attributes to a product in two ways.
method #1
a. Create an attribute in Product->Attributes, set a name for it (i.e color), define it wether to be a select-field or a text-field. Save.
b. Edit product switch to attributes-tab, select “color” from the dropdown, fill in some values. Save.
method #2
Edit product, switch to attributes-tab, select “add custom attribute”, set a name, fill in some values. Save.
Well, in method #1, the attributes are saved and connected over three tables. wp_terms, wp_term_taxonomies and wp_term_relationship
In method #2, the attributes are serialized and saved in wp_postmeta with ‘_product_attributes’ as meta_key.
my problem
What I would like to do now is to move all attributes that are stored in the wp_postmeta table, to the wp_meta table and connect them correctly via wp_term_taxonomies and wp_term_relationship.
Is there any solution or plugin for that?
Moving them manually is not an option since there are over 500 of them.
Cheers,
There is a WooCommerce-REST-API that allows me to do that.
http://woothemes.github.io/woocommerce-rest-api-docs/
First I had to get the slugs and names of all attributes (not their values) that are stored in the wp_term_relathionship. Since there are just a few, I wrote them down.
Example:
Product has two attributes called “Color”. The one attribute is stored in wp_term_relationships and has name “Color” and slug “pa_attr_color”. The other color is stored in wp_postmeta as pa_attributes, and has name “Color” and slug “wrong_color”. Now I want to move that values to the pa_attr_color.
All I have to do now is to move the options from wrong_color to pa_attr_color.
If there’s no pa_attr_color, than I simply had to create one.