I need to show default variation price in Woocommerce product.

I find this post and code works. –> Woocommerce Show default variation price

but thre is a problem : the backend is too slowly and the product page get error 504 gateway because the script think too long… the is any alternative solutions ?

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);

}

Read more here: display default variation price Woocommerce products


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: