Like the title says I want to get rid of the decimals after my price.
It now looks like this 8.00 but it should be 8.
i tried trim() and substr($price_html,1,1) but nothing happened
my code:
<?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; ?>
any ideas how I can cut of the .00 from the price output(js? manipulate the mysqli query?)
EDIT: i dont have the option “remove zeros” in my wp/woocommerce backend(for those who will ask)
SOLUTION from danyo:
$price_html = $product->get_price_html();
$new_price = preg_replace('/.00/', '', $price_html);
Goto WooCommerce Settings, scroll down to Pricing Options and then check the option “Trailing Zeros”.
This will then remove the trailing zeros.
EDIT
As you dont have this option for some reason you can try this:
Use floatval function
or use 8.00 + 0
// 8
I think this will work
Trying to get this to work:
But since I am a newbie to PHP, could someone please give me the exakt code how to use it?