Change the Price Text of Variable Products

Add the text “From” highlighting the starting price of each variable product.

PHP
/**
 * Snippet Name:     Change the Price Text of Variable Products
 * Snippet Author:   coding-bunny.com
 * Description:      Add the custom text highlighting the starting price of each variable product.
 */
 
 // Hook into WooCommerce's price range formatting filter.
add_filter( 'woocommerce_format_price_range', 'cb_variation_price_format_min', 9999, 3 );

/**
 * Customizes the display of variable product price ranges in WooCommerce.
 *
 * This function ensures that the price range always shows "Starting from" 
 * with the minimum price, improving clarity for customers.
 *
 * @param string $price The original price range string.
 * @param mixed  $from  The minimum price in the range.
 * @param mixed  $to    The maximum price in the range (not used here).
 * @return string Modified price range string.
 */
function cb_variation_price_format_min( $price, $from, $to ) {
    // Ensure the $from value is safely formatted as a price using WooCommerce's wc_price().
    $formatted_from = is_numeric( $from ) ? wc_price( $from ) : esc_html( $from );

    // Return the formatted price string with a translatable string for "Starting from".
    return sprintf( 
        esc_html_x( 'Starting from %1$s', 'Price range: from', 'cb' ), 
        $formatted_from 
    );
}

How To Implement This Solution?

Leave a Reply

Your email address will not be published. Required fields are marked *

My Agile Privacy
This site uses technical and profiling cookies. You can accept, decline or customize cookies by pressing the desired buttons. By closing this policy you will continue without accepting.

Need help?

Choose one of the following options:

Powered by CodingBunny