Replace price range with lowest price for variable products in WooCommerce

if ( ! function_exists( 'wpcb_display_lowest_price_for_variable_products' ) ) {
    /**
     * wpcb_display_lowest_price_for_variable_products.
     *
     * @see https://wpcodebook.com/snippets/replace-price-range-with-lowest-price-for-variable-products-in-woocommerce/
     */
    function wpcb_display_lowest_price_for_variable_products( $price_html, $product ) {
        return ( $product->get_variation_price( 'max' ) != ( $min_price = $product->get_variation_price( 'min' ) ) ?
            sprintf( 'From: %s', wc_price( $min_price ) ) : $price_html );
    }
    add_filter( 'woocommerce_variable_price_html', 'wpcb_display_lowest_price_for_variable_products', PHP_INT_MAX, 2 );
}

You can add this snippet to your (child) theme's functions.php file.

No comments yet.

Leave a Reply