在WooCommerce中取代可变产品定价

问题描述 投票:3回答:1

我想删除我正在处理的WooCommerce网站中为变量产品显示的价格范围。在非产品页面上,我想用“来自:[最低价格]”替换它,在产品页面上,我只想用所选变体的价格替换它。

任何想法我怎么能以这种方式工作?

谢谢,

达伦

wordpress woocommerce
1个回答
1
投票

做你想做的最好的方法是你在非产品页面上更改它并从产品页面中删除它。在产品页面上选择变量时,其价格和剩余库存将显示在下拉列表下方。因此,您无需在上面显示它。如果您仍想这样做,您将需要一个js解决方案。

试试这个,这是经过测试的解决方案我已经评论了案例,以便在需要时提供更好的指导和改变。

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 );
© www.soinside.com 2019 - 2024. All rights reserved.