How to trim zeros from round decimal prices in WooCommerce. See https://hookturn.io/remove-trailing-zeros-woocommerce-prices/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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