在单个产品页面上的自定义字段后添加一些自定义文本

时间:2020-10-26 19:22:50

标签: php wordpress woocommerce

我的产品页面产品属性上有一个名为“ 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);

1 个答案:

答案 0 :(得分:1)

更改所需的if

if (get_field('mekos')) {
        $product_attributes['mekos'] = [
            'label' => 'Μήκος',
            'value' => $mekos . ' centimeters'
        ]; 
    }