Replace WooCommerce variable products price range

2020-04-26 11:06发布

问题:

With my Woocommerce webshop, I sell services using variable products and I would like to replace the price range by "Prices starting at" ++ the lowest price.

I have tried changing the code in many ways but I didn't get it working.

How can I hide price range in Woocommerce and show only the lowest one on variable products?

回答1:

The following will replace the variable price range by "Prices starting at" with the lowest price:

add_filter( 'woocommerce_variable_sale_price_html', 'custom_variable_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_variable_price_range', 10, 2 );
function custom_variable_price_range( $price_html, $product ) {

    $prefix     = __('Prices starting at', 'woocommerce');
    $min_price  = $product->get_variation_price( 'min', true );

    return $prefix . ' ' . wc_price( $min_price );
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Related: Replace WooCommerce variable products price range with 'Up to' and the max price