我的产品页面产品属性上有一个名为“ mekos”的自定义字段。 在显示值之后,我想显示一些其他自定义文本,例如“厘米”。 The spot that I want the custom text "centimeters" to be displayed.
这是我到目前为止的代码:
function yourprefix_woocommerce_display_product_attributes($product_attributes, $product){
$mekos = get_post_meta($product->get_ID(), 'mekos', true);
if( get_field('mekos') ) {
$product_attributes['mekos'] = [
'label' => 'Μήκος',
'value' => $mekos ,
];
}
return $product_attributes;
}
add_filter('woocommerce_display_product_attributes', 'yourprefix_woocommerce_display_product_attributes', 10, 2);
答案 0 :(得分:1)
更改所需的if
if (get_field('mekos')) {
$product_attributes['mekos'] = [
'label' => 'Μήκος',
'value' => $mekos . ' centimeters'
];
}