How to show only 2 decimals in woocommerce prices using php?

Member

by samara , in category: PHP CMS , a month ago

How to show only 2 decimals in woocommerce prices using php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , a month ago

@samara 

You can use the woocommerce_price_format filter in your theme's functions.php file to change the price format to display only 2 decimal places. Here's an example code snippet:

1
2
3
4
function custom_price_format($price) {
    return number_format($price, 2);
}
add_filter('woocommerce_price_format', 'custom_price_format');


This code snippet will apply the number_format() function to all prices in WooCommerce, rounding them to 2 decimal places. This will ensure that all displayed prices will only show 2 decimal places.