Вы находитесь на странице: 1из 5

Queries for updating all prices including variati... https://gist.github.com/yanknudtskov/9e725d5...

Instantly share code, notes, and snippets.

yanknudtskov / woocommerce-update-prices.sql
Last active 16 days ago

Embed <script src="https://gist.github.com/ya


Download ZIP

Queries for updating all prices including variations in WooCommerceIn this instance all prices are
subtracted 20% (0.8)#woocommerce #mysql

woocommerce-update-prices.sql

1 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_regular_price


2 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_sale_price
3 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_price' AND
4 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_regular_price_tmp
5 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_sale_price_tmp
6 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_price_tmp
7 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_min_variation_price
8 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_max_variation_price
9 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_min_variation_regula
10 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_max_variation_regula
11 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_min_variation_sale_p
12 UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_max_variation_sale_p
13 DELETE FROM wp_options WHERE (option_name LIKE '_transient_wc_var_prices_%' OR

doubleedesign commented on Feb 19, 2018

Thanks for sharing, you just saved me quite a bit of time which in turn has saved my
client hoooourrrrrsss of manual updating! :)

1manfactory commented on May 17, 2018

You also have to delete price caching. Otherwise you won't see any changes.

DELETE FROM wp_options WHERE (option_name LIKE


'_transient_wc_var_prices_%' OR option_name LIKE
'_transient_timeout_wc_var_prices_%')

1 of 5 7/19/20, 11:23 PM
Queries for updating all prices including variati... https://gist.github.com/yanknudtskov/9e725d5...

Martydesign commented on Feb 16, 2019 • edited

Great, this is very helpful. Is there any way to update a price only if the price is lower
than 100$? Is it:
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key =
'_sale_price' AND meta_value <= '100'
?

joeyblack835 commented on Feb 20, 2019 • edited

Great, this is very helpful. Is there any way to update a price only if the price is
lower than 100$? Is it:
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key =
'_sale_price' AND meta_value <= '100'
?

Please be aware of two things.

1. Use 100 instead of '100'. You should compare numbers not strings.
Also add a condition to avoid warnings.
Also you might want to update only lower than 100 not equal.
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key =
'_sale_price' AND meta_value != '' AND meta_value < 100

2. Do not forget to update '_price' fields following the logic of woocommerce.

Martydesign commented on Mar 8, 2019

Great, this is very helpful. Is there any way to update a price only if the
price is lower than 100$? Is it:
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE
meta_key = '_sale_price' AND meta_value <= '100'
?

Please be aware of two things.

1. Use 100 instead of '100'. You should compare numbers not strings.
Also add a condition to avoid warnings.
Also you might want to update only lower than 100 not equal.
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE

2 of 5 7/19/20, 11:23 PM
Queries for updating all prices including variati... https://gist.github.com/yanknudtskov/9e725d5...

meta_key = '_sale_price' AND meta_value != '' AND meta_value <


100

2. Do not forget to update '_price' fields following the logic of woocommerce.

Thank you Joey!

curdaneta commented on Jan 16

Hello. Is there any way to update the current _sale_price increasing it's value 35%?

sczimmerman commented on Feb 13

Hello. Is there any way to update the current _sale_price increasing it's value
35%?

You should be able to do this by changing


SET meta_value = meta_value*0.8
to
SET meta_value = meta_value*1.35

yanknudtskov commented on Feb 13 Owner Author

You also have to delete price caching. Otherwise you won't see any changes.

DELETE FROM wp_options WHERE (option_name LIKE


'_transient_wc_var_prices_%' OR option_name LIKE
'_transient_timeout_wc_var_prices_%')

Thanks :-)

Enforcer69 commented on Mar 3

Hello, how to update prices for products in a certain category only?

yanknudtskov commented on Mar 3 • edited Owner Author

3 of 5 7/19/20, 11:23 PM
Queries for updating all prices including variati... https://gist.github.com/yanknudtskov/9e725d5...

You could probably do something like this to get all products in a category,

SELECT ID as post
INNER JOIN wp_term_relationships rs ON rs.object_id = post.ID
WHERE post_type = "post" //post type post for my example
AND post_status = "publish"
AND rs.term_taxonomy_id = 1 //term_taxanomy_id is 1 for my example

You could then use something like this to update it

UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key =


'_regular_price' AND meta_value != '' IN (**See Query from Above**)

Enforcer69 commented on Mar 4

You could probably do something like this to get all products in a category,

SELECT ID as post
INNER JOIN wp_term_relationships rs ON rs.object_id = post.ID
WHERE post_type = "post" //post type post for my example
AND post_status = "publish"
AND rs.term_taxonomy_id = 1 //term_taxanomy_id is 1 for my example

You could then use something like this to update it

UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key =


'_regular_price' AND meta_value != '' IN (**See Query from Above**)

Thank you for anwer.


But is more likely:
SELECT ID as post FROM wp_posts
INNER JOIN wp_term_relationships rs ON rs.object_id = ID
WHERE post_type = "product"
AND post_status = "publish"
AND rs.term_taxonomy_id = 1; // or AND rs.term_taxonomy_id IN (1,2,3...X) -
categories ID

To get categories ID (term_taxonomy_id):


SELECT t., tt.
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
WHERE tt.taxonomy ='product_cat'
ORDER BY t.name ASC;

4 of 5 7/19/20, 11:23 PM
Queries for updating all prices including variati... https://gist.github.com/yanknudtskov/9e725d5...

To update products prices on selected categories:


UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key =
'_regular_price' AND meta_value != '' AND post_id IN(first query);

Hope it helps.

yanknudtskov commented on Mar 4 Owner Author

Great :-) Thanks for pitching in

5 of 5 7/19/20, 11:23 PM

Вам также может понравиться