display default variation price Woocommerce products

你。 提交于 2021-02-08 05:12:49

问题


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

}

来源:https://stackoverflow.com/questions/43997575/display-default-variation-price-woocommerce-products

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!