Skip to content

Instantly share code, notes, and snippets.

@tuongpgjz
Created July 18, 2022 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuongpgjz/330ea2e9c7285850b6f72922ee1afbfc to your computer and use it in GitHub Desktop.
Save tuongpgjz/330ea2e9c7285850b6f72922ee1afbfc to your computer and use it in GitHub Desktop.
Update product price base on category
-- SalesGen.io
-- Change 'category name' by your category name
-- Reduce current price 5
update `wp_postmeta` SET meta_value = meta_value - 5 WHERE meta_key IN ('_regular_price', '_price') AND meta_value <> '' AND post_id IN (SELECT object_id from wp_term_relationships WHERE term_taxonomy_id IN(SELECT term_taxonomy_id FROM `wp_term_taxonomy` WHERE taxonomy = 'product_cat' AND term_id IN (SELECT term_id FROM `wp_terms` WHERE name = 'category name')));
-- Increase current price 5
update `wp_postmeta` SET meta_value = meta_value + 5 WHERE meta_key IN ('_regular_price', '_price') AND meta_value <> '' AND post_id IN (SELECT object_id from wp_term_relationships WHERE term_taxonomy_id IN(SELECT term_taxonomy_id FROM `wp_term_taxonomy` WHERE taxonomy = 'product_cat' AND term_id IN (SELECT term_id FROM `wp_terms` WHERE name = 'category name')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment