Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase all Woocommerce products prices by a percentage [closed]

I am using Woocommerce in my website and I should need to add 24% extra to all my products prices.

How this can be done in an easy way?

Using a database Query will be the best way my be. Any help is appreciated.

like image 219
Vachos Avatar asked Dec 18 '22 02:12

Vachos


1 Answers

Updated on July 2018
You can run the following SQL query, that will update all your product prices adding an extra 24% (and rounding prices too):

UPDATE `wp_postmeta` 
SET `meta_value` = ROUND(`meta_value` * 1.24, 2) 
WHERE meta_key LIKE '%_price%' 
AND (meta_value > 0 or `meta_value` != '')
AND `post_id` IN (
    SELECT `ID` 
    FROM `wp_posts` 
    WHERE `post_type` = 'product' 
    AND `post_status` = 'publish' 
    AND `ID` = `post_id`
);

This is tested and works.

Before running this SQL query do a database backup

You might need to delete products transient cache going to Settings -> Status -> Tools (tab) and in "WooCommerce transients" you will "clear transients";


Handle product variations too:

You just need to replace this line:

WHERE `post_type` = 'product'

By this line:

WHERE `post_type` IN ('product','product_variation')

Additionally you will also need to use:

DELETE
FROM `wp_options`
WHERE (`option_name` LIKE '_transient_wc_var_prices_%'
    OR `option_name` LIKE '_transient_timeout_wc_var_prices_%')
like image 187
LoicTheAztec Avatar answered Feb 22 '23 03:02

LoicTheAztec