Есть магазин с товарами на wordpress+woocommerce. Пробую посчитать скидку на товар при распродаже, но что-то не получается - на выходе получаю формат 1.35
а не 1.350
руб..Что делаю не так?
<p class="economy">
<?php
function extract_unit($string, $start, $end)
{
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three); // remove whitespaces
return $unit;
}
global $product;
$price=$product->get_price_html();
$saleprice = extract_unit($price,'<ins><span class="amount">','<ruble title="руб.">a</ruble></span></ins>');
$regprice = extract_unit($price,'<del><span class="amount">','<ruble title="руб.">a</ruble></span></del>');
$economy= $regprice - $saleprice;
echo $economy." <ruble title='руб.'>a</ruble>"; ?>
</p>
echo $product->get_price_html();
выводится в таком виде:
<p class="price">
<del><span class="amount">21.150 <ruble title="руб.">a</ruble>
</span></del>
<ins><span class="amount">19.800 <ruble title="руб.">a</ruble>
</span></ins>
</p>