/**
* Snippet Name: Rename price of free products
* Snippet Author: coding-bunny.com
* Description: Displays "Free" for products with a price of zero or empty.
*/
add_filter( 'woocommerce_get_price_html', 'cb_rename_free_product_price', 10, 2 );
/**
* Rename the price display for products that are free.
*
* @param string $price The price HTML.
* @param WC_Product $product The product object.
* @return string Modified price HTML.
*/
function cb_rename_free_product_price( string $price, WC_Product $product ): string {
// Check if the product price is empty or zero
if ( empty( $product->get_price() ) || $product->get_price() == 0 ) {
// Set the price display to "Free"
$price = __( 'Free', 'woocommerce' );
}
return $price;
}
Rename Price of Free Products
Displays "Free" for products with a price of zero or empty.