启用向后价格后缀到在WooCommerce中显示自定义产品价格的功能

我正在使用在Woocommerce中为已登录用户启用销售价格并为未登录用户启用常规价格”的第一个功能代码,它隐藏了销售价格。这样,我可以使用已登录用户的销售价格和常规价格,而不是未登录用户的价格,它就像一个魅力。

我遇到的问题是,它还会杀死设置中的woocommerce_price_suffix字段,我想将其包含在函数中,但不知道如何。

LoicTheAztec

以下将添加价格后缀:

//Variable and simple product displayed prices (removing sale price range)
add_filter( 'woocommerce_get_price_html', 'custom_get_price_html', 20, 2 );
function custom_get_price_html( $price, $product ) {
    if( $product->is_type('variable') )
    {
        if( is_user_logged_in() ){
            $price_min  = wc_get_price_to_display( $product, array( 'price' => $product->get_variation_sale_price('min') ) );
            $price_max  = wc_get_price_to_display( $product, array( 'price' => $product->get_variation_sale_price('max') ) );
        } else {
            $price_min  = wc_get_price_to_display( $product, array( 'price' => $product->get_variation_regular_price('min') ) );
            $price_max  = wc_get_price_to_display( $product, array( 'price' => $product->get_variation_regular_price('max') ) );
        }

        if( $price_min != $price_max ){
            if( $price_min == 0 && $price_max > 0 )
                $price = wc_price( $price_max );
            elseif( $price_min > 0 && $price_max == 0 )
                $price = wc_price( $price_min );
            else
                $price = wc_format_price_range( $price_min, $price_max );
        } else {
            if( $price_min > 0 )
                $price = wc_price( $price_min);
        }
        $price .= $product->get_price_suffix()
    }
    elseif( $product->is_type('simple') )
    {
        if( is_user_logged_in() )
            $active_price = wc_get_price_to_display( $product, array( 'price' => $product->get_sale_price() ) );
        else
            $active_price = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) );

        if( $active_price > 0 )
            $price = wc_price($active_price) . $product->get_price_suffix();
    }
    return $price;
}

代码进入您的活动子主题(或活动主题)的functions.php文件中经过测试和工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Woocommerce单个产品页面中显示高于产品价格的自定义字段

在WooCommerce折扣产品上显示自定义价格后缀

基于WooCommerce中产品的自定义产品价格后缀

显示WooCommerce产品价格的自定义简码:以零价格显示文本

在自定义模板中显示WooCommerce产品价格(带折扣)

产品类别的WooCommerce产品价格中的自定义小数

如何在自定义页面上按ID号显示Woocommerce产品价格?

通过自定义字段在Woocommerce中更改购物车中的产品价格

将自定义产品价格乘以WooCommerce购物车中的数量

根据woocommerce中的产品价格显示%

将自定义字段价格作为产品价格分配给WooCommerce中的特定用户角色

WooCommerce:从产品变型中获取自定义字段,并将其显示为变化价格的后缀

WooCommerce中可变产品的条件自定义价格后缀

如何在WooCommerce中为自定义产品类型启用价格和库存

自定义 Woocommerce 可变产品价格范围,用于多个活动变体

为产品价格添加自定义图标

在WooCommerce中自定义所选产品的变化价格

Woocommerce中特定产品的自定义价格

获取要在WooCommerce 3中显示的产品价格

在Woocommerce 3中更新和显示更新的产品价格

在Woocommerce 3中用自定义文本替换产品零显示的价格

显示在admin Woocommerce产品列表页面中的自定义价格计算

在简短描述产品WooCommerce中显示带有价格的自定义文本

在Woocommerce 3中获取产品价格

在WooCommerce中的价格显示之前添加自定义文本

根据产品类型向产品价格添加自定义文本标签

附加的自定义按钮,可在添加到Wovcommerce中的购物车之前更改产品价格

在Woocommerce单个产品页面中更改并保存产品价格

在WooCommerce产品上显示每米价格的自定义前缀