Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active February 7, 2022 01:58
Show Gist options
  • Save mishterk/5dbde9a0848de70b81d7f8e0f004205a to your computer and use it in GitHub Desktop.
Save mishterk/5dbde9a0848de70b81d7f8e0f004205a to your computer and use it in GitHub Desktop.
How to trim zeros from round decimal prices in WooCommerce. See https://hookturn.io/remove-trailing-zeros-woocommerce-prices/
<?php
// Need to trim zeros from a price on the fly?
$price = 49.00; // Can be numeric or a string.
$price = wc_trim_zeros( $price ); // === '49'
<?php
// If a WooCommerce price is a full dollar value, trim the
// decimal & any trailing zeros.
// e.g; $49.00 will display as just $49
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment