0
votes

I am writing a simple plugin which updates meta values for woocommerce products. Did some good research and worked on it, got 90% of what I wanted, a simple process is missing though. Let me explain the issue with a simple example.

Product A with Variations

 --------------------------------------
 variations:      500 gms | 1 kg | 2 kg
  --------------------------------------
 Regular Price:   100     | 200  | 400
 --------------------------------------
 Sale Price :     90      | 180  | 360  

Now I am using the function update_post_meta to update the prices from my plugin. It works perfectly for filled values, but let say if we don't want to use that variation and make both values (sale price and regular price) blank and do the same process,database values updated blank but in display it shows 0 value.

Where as If we make blank value from product edit page Wordpress, it works as expected.

Can anybody please tell me what I am missing here ?

1
simply you can check the difference in meta table ... compare both ... when you create it from wp admin section and when you create it from plugin code.Gopal S Rathore
that was the first thing I did. I had a variation post id 62 so checked all meta values for 62 id and compared it by taking screenshots but no luck.Dhaval Kakkad

1 Answers

0
votes

I think I figured this out. As I was saying something was missing , this is it.

$id = get_the_ID(); WC_Product_Variable::sync( $id );

variables sync process is needed in order to make this work.

I hope it helps.