Home > front end >  MySQL update price using SKU in WooCommerce
MySQL update price using SKU in WooCommerce

Time:02-05

I am trying to update prices in WooCommerce based on SKU. I have written some SQL but getting error 'You can't specify target table 'wp_postmeta' for update in FROM clause'. Is there any way to do the following better?

 UPDATE wp_postmeta SET meta_value = 144 WHERE 
meta_key = '_regular_price' AND 
post_id IN(SELECT post_id FROM wp_postmeta WHERE meta_key = '_sku' 
AND meta_value = SKU1451E51);

CodePudding user response:

UPDATE wp_postmeta as pm
INNER JOIN wp_postmeta as pm2 on pm.post_id = pm2.post_id
SET pm.meta_value = 144
WHERE pm.meta_key = '_regular_price'
AND pm2.meta_key = '_sku' 
AND pm2.meta_value = 'SKU1451E51'
  •  Tags:  
  • Related