how to edit the output of price in woocommerce/wordpress

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.

Read More

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);

Related posts

Leave a Reply

4 comments

  1. 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:

    $price_html = $product->get_price_html();
    $new_price = preg_replace('/.00/', '', $price_html);
    
  2. Trying to get this to work:

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

    But since I am a newbie to PHP, could someone please give me the exakt code how to use it?