Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing variable product pricing in WooCommerce

I want to remove the price range that is shown for variable products in the WooCommerce site I'm working on. On non-product pages I want to replace it with "from: [lowest price]" and on the product page I'd like to replace it simply with the price of the selected variation.

Any ideas how I can get it working that way?

Thanks,

Darren

like image 528
Darren Potter Avatar asked Mar 12 '26 15:03

Darren Potter


1 Answers

The best possible way to do what you want is that you change it on non-product page and remove it from product page. On product page when you select a variaion, its price and remaining stock is shown below the dropdown. So there is no need for you to show it above. If you still want to do it you will need a js solution.

Try this, this is tested solution. I have commented the cases for better guidance and changing if you want.

function sr_change_variable_price($price, $product) 
{
    if ( $product->is_type( 'variable' ) && !is_product() ) 
    {
        return 'From: '.$product->get_variation_price( 'min' ); // if variable product and non-product page
    } else if ( $product->is_type( 'variable' ) && is_product() )
    {
        return '';  // if variable product and product page
    } else
    {
        return $price;  // other cases
    }
}
add_filter( 'woocommerce_get_price_html', 'sr_change_variable_price', 10, 2 );
like image 68
shazyriver Avatar answered Mar 16 '26 03:03

shazyriver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!