<div class="oldprice">Старая цена: <?php get_special_field('oldprice','',false); ?> руб.</div> 

The old price is substituted from the admin panel. If it is not there, it is necessary that the div block does not appear. Please help me how to do it.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Check directly on the server whether the value of the variable is filled with the old price and if it is not there, do not output a block

 <?php $price = get_special_field('oldprice','',false); if(!empty($price)) { ?> <div class="oldprice">Старая цена: <?= get_special_field('oldprice','',false) ?> руб.</div> <?php } ?> 
  • Thanks, the block does not appear, but now where is the old price, why does it indicate 1 ruble? - user205680
  • Corrected. Your function displays the price right inside, which is not very good and convenient, since you have to calculate it twice, make it so that it simply returns the value or split it into two - one calculates the value that you can navigate, the other does the formatting. If not difficult, give it a schematic content, what does it return? And how can you get the old price without resorting to this function? - cheops
  • Thank. Now the old price is displayed correctly, only 2 times: in the div and without it. I can not write answers to your questions, because I don’t understand ((. I don’t understand at all in php. - user205680
  • I instead of get_special_field wrote return_special_field and the price began to display correctly - user205680
  • Add to the question the contents of the function get_special_field () - cheops