1
votes

I have variable products in my WooCommerce store and instead of displaying the range of prices, I'd like to display just the default price that shows up below when someone first visits my product page.

For the attached image, the default price is $395. Which changes based on the choices a person makes after they've loaded the product page. But I would like the $395 number to stay at the top of the page with something like "Starting at $395" or "Baseline Price" or something like that.

But getting that $395 number out of WooCommerce has been challenging to me so I'm reaching out.

Product Page

This was answered here: Woocommerce variation product price to show default

But it's for a WooCommerce 2.0 store and I'm using the latest version 2.5.5 and this persons code just gives me the minimum fee instead of the default fee and I don't know what to change based on updated WooCommerce code.

Any suggestions?

I have tried so many versions of code that to include them here would be confusing probably. If I don't hear from anyone, I'll include some.

1

1 Answers

2
votes

I cant find answer for this question anywhere (how to display price from default product variation instead of price range?) so i created the code:

    add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);

function custom_variation_price( $price, $product ) {

    foreach($product->get_available_variations() as $pav){
        $def=true;
        foreach($product->get_variation_default_attributes() as $defkey=>$defval){
            if($pav['attributes']['attribute_'.$defkey]!=$defval){
                $def=false;             
            }   
        }
        if($def){
            $price = $pav['display_price'];         
        }
    }   

    return woocommerce_price($price);

}

This plugin show price from default variation, of course if you set default values before. Tested on woocommerce version 2.6.2.