Update or add sale price using php and mysql
-
Hello there,
I have a script in php that updates my prices via csv upload. All good except the products that are not on sale.
I have update on :
_regular_price – works fine
_price – works fine
_sale_price – working only on products that already have an discount.My query for _sale_price update is :
$query = ”
UPDATE wp3l_postmeta
SET
meta_value = ‘$saleprice’
WHERE wp3l_postmeta.meta_key = ‘_sale_price’ AND wp3l_postmeta.post_id = (SELECT post_id FROM wp3l_postmeta WHERE wp3l_postmeta.meta_key = ‘_sku’ AND wp3l_postmeta.meta_value = ‘$product_id’)
“;
The query works fine, but its imposible to update the products that do not have an active discount. In database is missing _sale_price if the product has no discount, and my update cant run.How can i fix this? Dunno how to create _sale_price for the products that have no discount on site, but in my csv will have a discount.
wordpress version 5.5.3
woocommerce version 4.3.2
- The topic ‘Update or add sale price using php and mysql’ is closed to new replies.