How to Increase all Woocommerce products prices by a percentage
If you are using Woocommerce in my website and I should need to add 24% extra to all my products prices.
Using a database Query will be the best way.
You can run the following SQL query, that will update all your product prices adding an extra 24% (and rounding prices too):
1 2 3 4 5 6 7 8 9 10 11 |
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` ); |
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:
1 2 |
WHERE <span class="hljs-string">`post_type`</span> = <span class="hljs-string">'product'</span> |
By this line:
1 2 |
WHERE <span class="hljs-string">`post_type`</span> IN (<span class="hljs-string">'product'</span>,<span class="hljs-string">'product_variation'</span>) |
Additionally you will also need to use:
1 2 3 4 |
<span class="hljs-keyword">DELETE</span> <span class="hljs-keyword">FROM</span> <span class="hljs-string">`wp_options`</span> <span class="hljs-keyword">WHERE</span> (<span class="hljs-string">`option_name`</span> <span class="hljs-keyword">LIKE</span> <span class="hljs-string">'_transient_wc_var_prices_%'</span> <span class="hljs-keyword">OR</span> <span class="hljs-string">`option_name`</span> <span class="hljs-keyword">LIKE</span> <span class="hljs-string">'_transient_timeout_wc_var_prices_%'</span>) |