skip to Main Content

I need visually remove the decimal place (00) from the price and maintain only the comma or point after the first integer.

E.g: $ 10,

E.g: $ 7,

This is the code:

$retorno .= "<div class='cc_btn_checkout_container d-none' data-price='".$product->get_price()."'><div 

The object receives the price: .$product->get_price(). = $ 10.00

The price is displayed here inside:

 <p id='cc_btn_amount'>$ 10.00</p>

I’m trying with this function….but until now nothing happens.

$retorno .= "<div class='cc_btn_checkout_container d-none' data-price='".number_format($product->get_price(), 0)."'><div 

The number need to be displayed like this: $ 10,

How can I do this? Is that the correct function to be used in this case?

Obs: I must maintain the comma after the price, I cannot in this case remove the comma or the point as others Woo functions does.

2

Answers


  1. You can use this filter
    http://hookr.io/filters/woocommerce_price_format/
    or this:

    add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
    
    Login or Signup to reply.
  2. Check out the functions in this article from Tyche Softwares

    Just remove $decimal from the return and the <sup> if you don’t need it.

    "If you want the decimal separator in the superscript, you can easily do that too. If you look at our filter, it has an argument called $decimal_separator. This is the same separator which we have set in the WooCommerce settings. We just have to include that in our final result. Here is an example –

    add_filter( 'formatted_woocommerce_price', 'ts_woo_decimal_price', 10, 5 );
    function ts_woo_decimal_price( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
        $unit = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator );
        $decimal = sprintf( '%02d', ( $price - intval( $price ) ) * 100 );
        return $unit . '<sup>' . $decimal_separator. $decimal . '</sup>';
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search