在woocommerce单一产品变化产品中隐藏隐藏(然后打折)的价格

时间:2019-10-15 01:49:00

标签: php wordpress woocommerce hook-woocommerce

我没有获得正确的方法来摆脱这种价格→

enter image description here

在woocommerce单一产品页面中。

我尝试了许多Internet上可用的方法,但是无法摆脱任何remove_action

1 个答案:

答案 0 :(得分:1)

请尝试以下代码段。

add_filter('woocommerce_get_price_html', "wt_hide_regular_price", 99, 2);

function wt_hide_regular_price($price, $product)
{
    if(!is_cart() && !is_checkout() && !is_ajax()){
        if ($product->is_type('simple') || $product->is_type('variation')) {
            return wt_regular_price_for_product($price, $product);
        } 
    }
        return $price;            

}

function wt_regular_price_for_product($price, $product){
    return wc_price($product->get_price());
}