0
votes

I'm building a wordpress eshop using woocommerce and I want to integrate it with an existing erp tool. I have complete the 90% of all the connections but I'm facing a problem with variable products and I can't find a solution by reading the documentation. I need some more info about how to create a variable product through the erp.

Below is what I'm currently doing:

I am creating an entry in wp_posts with post_type product and for the variation and I'm creating another entry on wp_posts with post_type product_variation and post_parent the ID of the product that holds the variation.

I believe that I'm missing something because doing only the above is not working as expected.

2
What problem are you facing?Vidish Purohit
i'm missing something Yes you are missing many thing, first of all there are various EXTRA meta fields that needs to be added in main product postmeta table, and also you have to add taxonomy, term for main product. Moreover you also have to add postmeta table with attribute name and value for which it is variable. I'm flagging this question as too broad because it will take atleast 2 page to explain the whole logicRaunak Gupta

2 Answers

2
votes

I will write what I am using.

update wp_postmeta set meta_value = 270 where post_id in (
    select id from wp_posts where post_parent = 46 and post_type = 'product_variation'
) and meta_key = '_regular_price';

... where 270 is my new price for all variable products.

... using select to test the solution:

select * from wp_postmeta where post_id in (
    select id from wp_posts where post_parent = 46 and post_type = 'product_variation'
) and (meta_key = '_regular_price' or meta_key = '_sale_price');

You can see all meta_key related to the wp_posts with:

select distinct meta_key from wp_postmeta where post_id = XX;

In my case, the 46 is the post_id. For you see what is your, open the product in wp-admin.

I hope that I was helpfull.

0
votes

I think you might be getting the types wrong. Variations are of the post_type "product_variation" not "product".

Also make sure you have the appropriate wp_postmeta values. For example if you have a product variation that has no price it will actually not work during checkout even if it's a free product.

To see what wp_postmeta values you need, simply search that table for a product id that you got from a product that you created through the WC back-end.