How to Show Trailing Zeros on Prices in WooCommerce

Snippets by IsItWP

Are you looking for a way to add the trailing zeros to your WooCommerce prices? While there’s probably a plugin for this, we have created a quick code snippet that you can use to show trailing zeros on prices in WooCommerce.


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

add_filter( 'woocommerce_price_trim_zeros', 'wc_hide_trailing_zeros', 10, 1 );
function wc_hide_trailing_zeros( $trim ) {
    // set to false to show trailing zeros
    return false;

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 18 Jetpack alternatives to get the features without bloat and how to create a WordPress donation form.

Comments   Leave a Reply

  1. I’d guess its because the product object doesn’t have “id” available as a method.

    It’s $product->get_id()

    In reality this probably isn’t a good design of how to accomplish what OP wants to do. It’s probably best to have the price as normal and communicate those stipulations after the price.

  2. Thank you for sharing this tutorial. Can you guide me how can I change a display price for a specific product. I have used this code

    function change_product_html( $price_html, $product ) {
    if ( 22 === $product->id ) {
    $price_html = ‘$50.00 per Unit‘;
    return $price_html;
    add_filter( ‘woocommerce_get_price_html’, ‘change_product_html’, 10, 2 );
    function sv_change_product_price_cart( $price, $cart_item, $cart_item_key ) {
    if ( 22 === $cart_item[‘product_id’] ) {
    $price = ‘$50.00 per Unit(7-8 skewers per Unit)’;
    return $price;
    add_filter( ‘woocommerce_cart_item_price’, ‘sv_change_product_price_cart’, 10, 3 );

    I don’t know why I am having an error.

    1. Hi Alvina,
      What error message are you receiving?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!