Change product price which is equal to zero to be displayed as free in WooCommerce

Change product price which is equal to zero to be displayed as free in WooCommerce on your child site.

Snippet Type

Execute on Child Sites

Snippet

// Cart and minicart
add_filter( 'woocommerce_cart_item_price', 'change_cart_item_price_html', 10, 3 );
function change_cart_item_price_html( $price_html, $cart_item, $cart_item_key ) {
    if( $cart_item['data']->get_price() == 0 ) {
        return '<span class="woocommerce-Price-amount amount">'.__("FREE", "woocommerce").'</span>';
    }
    return $price_html;
}

// Cart and Checkout
add_filter( 'woocommerce_cart_item_subtotal', 'change_checkout_item_subtotal_html', 10, 3 );
function change_checkout_item_subtotal_html( $subtotal_html, $cart_item, $cart_item_key ) {
    if( $cart_item['data']->get_price() == 0 ) {
        return '<span class="woocommerce-Price-amount amount">'.__("FREE", "woocommerce").'</span>';
    }
    return $subtotal_html;
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.