Last active
March 21, 2018 09:54
-
-
Save ApoGouv/0ba5fc9a34ccb8f7c9206cfdcbbbc00c to your computer and use it in GitHub Desktop.
WordPress - WooCommerce product prices queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Update _price to be equal to _sales_price when there is a sales price set | |
*/ | |
UPDATE `wp_postmeta` AS p | |
LEFT JOIN `wp_postmeta` AS sp ON p.post_id = sp.post_id | |
SET p.meta_value = sp.meta_value | |
WHERE p.meta_key = '_price' | |
AND sp.meta_key = '_sale_price' | |
AND sp.meta_value != '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Update _sales_price to none ( '' ) when there is a sales price set | |
*/ | |
UPDATE `wp_postmeta` AS sp | |
SET sp.meta_value = '' | |
WHERE sp.meta_key = '_sale_price' | |
AND sp.meta_value != '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Get Products _sale_price, _regular_price and _price when _sale_price is not empty | |
*/ | |
SELECT sp.post_id AS ID, sp.meta_value AS SalesPrice, rp.meta_value AS RegulPrice, p.meta_value AS Price | |
FROM `wp_postmeta` AS sp | |
LEFT JOIN `wp_postmeta` AS rp ON sp.post_id = rp.post_id | |
LEFT JOIN `wp_postmeta` AS p ON sp.post_id = p.post_id | |
WHERE sp.meta_key = '_sale_price' | |
AND sp.meta_value != '' | |
AND rp.meta_key = '_regular_price' | |
AND p.meta_key = '_price' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Update _regular_price to be equal to _sales_price when there is a sales price set | |
*/ | |
UPDATE `wp_postmeta` AS rp | |
LEFT JOIN `wp_postmeta` AS sp ON rp.post_id = sp.post_id | |
SET rp.meta_value = sp.meta_value | |
WHERE rp.meta_key = '_regular_price' | |
AND sp.meta_key = '_sale_price' | |
AND sp.meta_value != '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment