Bil*_*son 2 php wordpress woocommerce
就像标题所说我希望在我的价格之后摆脱小数.
它现在看起来像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; ?>
Run Code Online (Sandbox Code Playgroud)
任何想法我如何从价格输出中削减.00(js?操纵mysqli查询?)
编辑:我没有在我的wp/woocommerce后端"删除零"选项(对于那些会问的人)
来自danyo的解决方案:
$price_html = $product->get_price_html();
$new_price = preg_replace('/.00/', '', $price_html);
Run Code Online (Sandbox Code Playgroud)
转到WooCommerce设置,向下滚动到定价选项,然后选中"尾随零"选项.
然后,这将删除尾随零.
编辑
由于某些原因你没有这个选项,你可以试试这个:
$price_html = $product->get_price_html();
$new_price = preg_replace('/.00/', '', $price_html);
Run Code Online (Sandbox Code Playgroud)