WooCommerce Price: How to set Free as a Price

Version audio de cet article
Woocommerce Price: Here’s a short tutorial on how to display free as a price once an item’s price is set at 0$.
We will use the woocommerce_get_price_html filter which will verify if an item’s price is 0$ or empty and then return the text with the $price variable.
Add this filter in your functions.php file.
///////////////////////////////////////
// Get Free if the price Woocommerce = 0
///////////////////////////////////////
add_filter( 'woocommerce_get_price_html', 'themepress_price_html', 10, 2 );
function themepress_price_html( $price, $product ) {
if( $product->get_price() == 0 || $product->get_price() == '') {
$price = '<span class="woocommerce-Price-amount amount">Gratuit</span>';
}
return $price;
}Once the condition is configured, you can display the text you want insde the woocommerce-Price-amount span tag.