woocommerce offtopic – Format decimals of get_price_html


One of the stores I manage is currently facing a bug that is not solved yet by WooCommerce, regarding rounding prices introduced without tax. So far one of the temp fixes that work is changing the whole store to 4 decimals to improve accuracy. Now the problem is that some new clients seem to believe our prices are in another currency other than USD because of the 6 digits that get presented (19.998). I’m wondering if there is a way to format the output of woocommerce_get_price_html using something like number_format. I’m a bit lost because the output of this is escaped html to style the price, so something like this

add_filter( 'woocommerce_get_price_html', 'rounded_price_html', 100, 2 );
function rounded_price_html( $price, $product ){
    return number_format( $price, 2, ',', '.');

would not work. So basically what I’m asking is, is there any way I can format the price of this function without interfering with the HTML? This should only affect the front end as we don’t care about the four digits in the back. Creating something using JS is not an option as our theme is AJAX based and that would just create more work

Jose 1 year 2021-07-29T21:15:37-05:00 0 Answers 0 views 0

Leave an answer