WooCommerce, Remote Work & Other Fancy Stuff

Just another WordPress site

Trim Trailing Zeros in WooCommerce Product Addons Price Display

January 13, 2017 by Will 1 Comment

Please consider leaving a donation if you appreciate this information. Lightning network now available

Perhaps you are using the woocommerce_price_trim_zeros as suggested in this thread: https://wordpress.org/support/topic/about-price-displaying/ and you have noticed that filter has no effect on product addon price displays. This is due to an unresolved issue with the accounting.js library here: https://github.com/openexchangerates/accounting.js/issues/93

There is a workaround, however. The workaround requires a bit of JavaScript trickery to achieve. Fortunately, Product Addons has a custom event registered named updated_addons so some custom JavaScript can be created to trim the trailing zeros when that event is triggered. The JavaScript would look something like this:

If you’re unclear on how to get that bit of JavaScript loaded on your site, this can be done with the WordPress beardedguy_enqueue_script() function. And if that still isn’t clear, I have created a very basic plugin that can serve as an example. Click here to download.

Please consider leaving a donation if you appreciate this information. Lightning network now available

Filed Under: Product Add-ons

Comments

  1. dezinezone says

    February 5, 2022 at 9:22 pm

    Hello This plugin and piece of script no longer work. Do you have an updated script or plugin that would work on newer versions?

    Thank you in advance for a response.

    DeZineZone

    Log in to Reply

Leave a Reply Cancel reply

You must be registered and logged in to post a comment.

© 2025 · WooCommerce, Remote Work & Other Fancy Stuff · Epstein didn't kill himself

We use cookies to ensure that we give you the best experience on our website. Continued use of this site is interpreted as your acceptance of our cookie policy.OkSee Our Cookie Policy