How to Hide Trailing Zeros WooCommerce

WooCommerce Hide Trailing ZerosIf you are planning to build your first online store but are overwhelmed by the choices, WooCommerce is one of the best options for you. Additionally, if you are not happy with your current eCommerce platform, you should give WooCommerce a chance. This is because WooCommerce is flexible for customization.

Moreover, settling on a theme in WooCommerce can be difficult because there are tens of thousands from which to choose. However, WooCommerce Storefront is one of the most widely used of all the themes on the market today. This is because it comes with a clean and minimal design that is open for any customization, like WooCommerce. In this tutorial, I will use the Storefront theme for illustration purposes.

WooCommerce Hide Trailing Zeros

WooCommerce, by default, displays prices with trailing zeros. Moreover, WooCommerce does not have an option to hide or disable this feature. If you are looking for a way to hide trailing zeros in your WooCommerce store, you are in the right place. In this post, we will use a custom PHP script that I have prepared for this purpose.WooCommerce trailing zeros

Steps to Hide Trailing Zeros on Prices

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to hide trailing zeros on prices in your WooCommerce store.
  3. Click anywhere on the text editor and scroll to the bottom of the functions.php file. Paste the code at the end:
// Hide trailing zeros on prices.

add_filter( 'woocommerce_price_trim_zeros', 'njengah_hide_trailing_zeros', 10, 1 );

function njengah_hide_trailing_zeros( $trim ) {

        return true;

    }
  1. Click on the Save changes button at the bottom of the text editor screen.
  2. Now you have successfully added the code snippet required to hide trailing zeros. This will be the outcome on the front end:WooCommerce hide trailing zeros

However, if you are using an older version of WooCommerce and it does not display trailing zeros, you can show trailing zeros by following the steps below.

Steps to Show Trailing Zeros on Prices

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to show trailing zeros on prices in your WooCommerce store.
  3. Click anywhere on the text editor and scroll to the bottom of the functions.php file. Paste the code at the end:
// Show trailing zeros on prices.

add_filter( 'woocommerce_price_trim_zeros', 'wc_hide_trailing_zeros', 10, 1 );

function wc_hide_trailing_zeros( $trim ) {

return false;

}
  1. This will be the outcome:WooCommerce trailing zeros

Conclusion

In summary, this post shares how to hide and display WooCommerce trailing zeros on prices. All you need to do is paste the custom PHP snippet I have shared in the functions.php file, as indicated in the tutorial. However, if you are not familiar with code, please contact a qualified WordPress developer so that you do not break your site.

Similar Articles