WooCommerce单位(来自属性值),在购物车中的价格后为$ 9.99 / kg

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

我已经管理了以下代码,使用以下代码将重量或件的特定属性放在价格后面:

function pakiranje() {
    global $product;
    $attribute  = 'pakiranje';
    $abv        = $product->get_attribute($attribute);
    if(!empty($abv))
    {
       return '/' . $abv;
    }
}
add_filter('woocommerce_get_price_suffix', 'pakiranje',15);

屏幕截图看起来像这样:

enter image description here

但是,我还需要将其应用于购物车结帐,因为那里不可见。

wordpress woocommerce attributes price suffix
1个回答
0
投票

woocommerce_get_price_suffix()包含4个参数:$html, $product, $price, $qty。由于您未使用此功能,并且未使用global $product在结帐/购物车页面上运行,请尝试以下代码。

function pakiranje( $html, $product, $price, $qty ) {
    // Attribute
    $attribute  = 'pakiranje';

    // Get attribute
    $abv = $product->get_attribute($attribute);

    // NOT empty
    if( !empty( $abv ) ) {
       $html = '/' . $abv;
    }

    return $html;
}
add_filter( 'woocommerce_get_price_suffix', 'pakiranje', 10, 4 );
© www.soinside.com 2019 - 2024. All rights reserved.