我有以下代码使用我自己的值在 woocommerce 中创建附加信息选项卡,但是我想从内置产品自定义字段中提取信息。
add_filter( 'woocommerce_display_product_attributes', 'custom_product_additional_information', 10, 2 );
function custom_product_additional_information( $product_attributes, $product ) {
// First row
$product_attributes[ 'attribute_' . 'custom-one' ] = array(
'label' => __('Label One'),
'value' => __('Value 1'),
);
// Second row
$product_attributes[ 'attribute_' . 'custom-two' ] = array(
'label' => __('Label Two'),
'value' => __('Value 2'),
);
return $product_attributes;
}
这是我用来输出自定义字段的当前代码,如何在上面工作代码的functions.php文件中的值1中输出它?
echo get_post_meta( get_the_ID(), 'Size', true );
答案 0 :(得分:3)
在您的代码中尝试以下替换:
'value' => __('Value 1'),
与:
'value' => $product->get_meta('Size'),
它应该可以工作。