如何在woommerce/wordpress中编辑价格输出


how to edit the output of price in woocommerce/wordpress

就像标题说我想去掉价格后面的小数。

现在看起来是8.00,但应该是8

我尝试了trim()和substr($price_html,1,1),但什么都没发生

我的代码:

<?php if ( $price_html = $product->get_price_html() ) : ?>
            <span class="price">PREIS:<span class="amount">
<?php echo $price_html; ?></span></span><p class="stock-m13"><?php echo $product->get_stock_quantity(); ?>stk.</p>
<?php endif; ?>

你知道我如何从价格输出中去掉.00吗(js?操纵mysqli查询?)

编辑:我在我的wp/woocommerce后端没有"删除零"选项(对于那些会问的人)

来自danyo的解决方案:

$price_html = $product->get_price_html();
$new_price = preg_replace('/.00/', '', $price_html);

转到WooCommerce设置,向下滚动到定价选项,然后选中选项"尾随零"。

这将删除后面的零。

编辑

由于某些原因,你没有这个选项,你可以试试这个:

$price_html = $product->get_price_html();
$new_price = preg_replace('/.00/', '', $price_html);

使用floatval函数

echo floatval('8.00');
// 125

或使用8.00+0//8

我认为这将适用于

substr($price_html,0,-3)

尝试使其工作:

$price_html = $product->get_price_html();
$new_price = preg_replace('/.00/', '', $price_html);

但既然我是PHP的新手,有人能告诉我如何使用它吗?