Answer the question
In order to leave comments, you need to log in
How correctly am I setting the promotional price for all products?
I created a page in the admin panel where you can enter and apply a percentage discount to all products. In functions.php, I take all the products and run through them with this code. Tell me, is this what I do?
$cid = get_the_id();
$reg_price = get_post_meta($cid, '_regular_price', 1);
$promo_price = '';
if(!$discount) {
$mysqli->query("UPDATE wp_postmeta SET meta_value='".$promo_price."' WHERE post_id='".$cid."' AND meta_key='_sale_price'");
$mysqli->query("UPDATE wp_postmeta SET meta_value='".$reg_price."' WHERE post_id='".$cid."' AND meta_key='_price'");
$mysqli->query("UPDATE wp_postmeta SET meta_value='' WHERE post_id='".$cid."' AND meta_key='_sale_price_dates_from'");
$mysqli->query("UPDATE wp_postmeta SET meta_value='' WHERE post_id='".$cid."' AND meta_key='_sale_price_dates_to'");
} else {
$promo_price = ceil($reg_price - ($reg_price / 100 * $discount));
$mysqli->query("UPDATE wp_postmeta SET meta_value='".$promo_price."' WHERE post_id='".$cid."' AND meta_key='_sale_price'");
$mysqli->query("UPDATE wp_postmeta SET meta_value='".$promo_price."' WHERE post_id='".$cid."' AND meta_key='_price'");
$mysqli->query("UPDATE wp_postmeta SET meta_value='' WHERE post_id='".$cid."' AND meta_key='_sale_price_dates_from'");
$mysqli->query("UPDATE wp_postmeta SET meta_value='' WHERE post_id='".$cid."' AND meta_key='_sale_price_dates_to'");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question