Created
April 14, 2019 15:56
-
-
Save damiencarbery/a9c29d598173e872589633387ae043ee to your computer and use it in GitHub Desktop.
Remove Zero Decimals from WooCommerce: Remove decimal portion of WooCommerce price if it is zero. https://www.damiencarbery.com/2019/04/remove-zero-decimals-from-wooCommerce/
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 | |
/* | |
Plugin Name: Remove Zero Decimals from WooCommerce | |
Plugin URI: Plugin URI: https://www.damiencarbery.com/ | |
Description: Remove decimal portion of WooCommerce price if it is zero. | |
Author: Damien Carbery | |
Author URI: https://www.damiencarbery.com | |
Version: 0.1 | |
*/ | |
add_filter( 'formatted_woocommerce_price', 'dcwd_remove_zero_decimals', 10, 5 ); | |
function dcwd_remove_zero_decimals( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) { | |
/* | |
// Leave decimals in on single product page. | |
if ( is_product() ) { | |
return $formatted_price; | |
} | |
*/ | |
if ( $price - intval( $price ) == 0 ) { | |
// Format units, including thousands separator if necessary. | |
return $unit = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator ); | |
} | |
else { | |
return $formatted_price; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment