我已经管理了以下代码,使用以下代码将重量或件的特定属性放在价格后面:
function pakiranje() {
global $product;
$attribute = 'pakiranje';
$abv = $product->get_attribute($attribute);
if(!empty($abv))
{
return '/' . $abv;
}
}
add_filter('woocommerce_get_price_suffix', 'pakiranje',15);
屏幕截图看起来像这样:
但是,我还需要将其应用于购物车结帐,因为那里不可见。
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 );