Replacing price with price change in WooCommerce

I want to remove the price range that is shown for variable products on a WooCommerce site that I am working on. On non-product pages, I want to replace it with "from: [lowest price]", and on the product page, I would like to replace it simply with the price of the option selected.

Any ideas how I can get it to work this way?

Thank,

Darren

+3


source to share


2 answers


The best way to do what you want is to change it on the no product page and remove it from the product page. On the product page, when you select a variaion, its price and remaining stock are shown below the dropdown. So you don't need to show it above. If you still want to do this, you need a js solution.

Try this, this is a tried and tested solution. I have commented out the cases for better guidance and change 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 );

      

+1


source


Is there an updated code for this?



0


source







All Articles