I develop an online store with woocommerce and I would like to display the price of the product with 3 decimals when the price contains 3 (example 1). But when the last number of the price is 0, I want to display only 2 decimals (example 2). Do you know how to do this please ?
I found a filter, but it affects all the prices at the same time :
add_filter( 'wc_get_price_decimals' , 'custom_price_decimals', 20, 1 );
function custom_price_decimals( $decimals ) {
if( is_product() || is_shop() || is_product_category() || is_product_tag() || is_cart() || is_checkout() ){
$decimals = 3;
return $decimals;
}
}
Thank you for your help :)
Example 1
(source: noelshack.com)
Example 2
(source: noelshack.com)