I’m trying to update woocommerce variation prices with a php/mysql script outside of wordpress.
I have a script that updates the _price
and _regular_price
value of one product_variation
of a product
in wp_postmeta
table.
If I have more than one variation the correct price of the variation is displayed on the webpage – but the the price / price range coming from woocommerce`s price.php is not updated.
However, if I have only this one variation, the price in the table is updated, but not at all on the rendered webpage.
I also tried to edit the prices of the product
itself. But: I still get the old price on the rendered webpage.
Basically I now have the same new price in these fields:
in product-variation -> postmeta: _price, _regular_price
and in product -> postmeta: _price, _regular_price, _min_variation_price, _max_variation_price, _min_variation_regular_price, _max_variation_regular_price
I couldn’t find any other fields with a price – I’m stuck…
Did I miss anything? Is there any other table/field to be updated?
Thanks for your help!
-EDIT-
Maybe this helps: Apparently when having only one Variation my price is rendered with echo $product->get_price_html();
instead of echo $value['price_html'];
. So where is the price used in $product->get_price_html();
stored?
OK after some digging around and thanks to @helgatheviking who pointed me in the right direction I tried this:
WC_Product_Variable::sync( $post_id );
-> unfortunately this didn’t work for me. I just put it here because I think this is the right approach – hopefully it helps someone else.
What actually helped me was including this in my functions.php:
Please use the following script to bulk update the product variations.
Click here for full code. https://www.pearlbells.co.uk/bulk-update-product-variation-price-woocommerce/