Show free label if product price is 0 (zero)
Below is the code to show label free instead of product price 0:
// Cart items displayed prices and line item subtotal
add_filter( 'woocommerce_cart_item_subtotal', 'free_cart_item_price_custom_label', 20, 3 );
add_filter( 'woocommerce_cart_item_price', 'free_cart_item_price_custom_label', 20, 3 );
function free_cart_item_price_custom_label( $price, $cart_item, $cart_item_key ) {
// HERE your custom free price label
$free_label = '<span class="amount">FREE</span>';
if( $cart_item['data']->get_price() > 0 )
return $price;
else
return $free_label;
}
// Order items displayed prices (and also email notifications)
add_filter( 'woocommerce_order_formatted_line_subtotal', 'free_order_item_price_custom_label', 20, 3 );
function free_order_item_price_custom_label( $subtotal, $item, $order ) {
// HERE your custom free price label
$free_label = '<span class="amount">FREE</span>';
if( $order->get_line_subtotal( $item ) > 0 )
return $subtotal;
else
return $free_label;
}