Woocommerce 附加信息选项卡:添加产品自定义字段值
Woocommerce Additional Information Tab: Adding product custom field value
我有以下代码使用我自己的值在 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 );
尝试在您的代码中进行以下替换:
'value' => __('Value 1'),
与:
'value' => $product->get_meta('Size'),
应该可以。
我有以下代码使用我自己的值在 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 );
尝试在您的代码中进行以下替换:
'value' => __('Value 1'),
与:
'value' => $product->get_meta('Size'),
应该可以。