I have two ACF fields named as “price” and “reduced_price” now i have another field named as “price_filter” which should be filled with following conditions,
- If “price” is greater than “reduced_price” and “reduced_price” is not empty then “price_filter” = “reduced_price”
- If “price” is 0 or “price” is empty then “price_filter” = 0
- Else “price_filter” = “price”
Now everything was working fine but when I put “price = 117900” and “reduced_price = 99900” It should fulfill the first condition and display “price_filter” = “reduced_price” but its not working like that and showing “price_filter” = “price”
Here is my PHP code
function my_acf_save_post( $post_id ) {
$price = get_field(‘price’);
$reduced_price = get_field(‘reduced_price’);
if ($price > $reduced_price && !empty($reduced_price)) {
update_field(‘price_filter’, $reduced_price);
}
else if($price == “0” || empty($price)) {
update_field(‘price_filter’, ‘0’);
}
else {
update_field(‘price_filter’, $price);
}
}
add_action(‘acf/save_post’, ‘my_acf_save_post’, 20);
‘ vs '