在woocommerce上,我使用下面的代码来渲染一些产品自定义字段,在购物车和结帐时:
add_filter( 'woocommerce_get_item_data', 'rendering_meta_field_on_cart_and_checkout', 10, 2 );
function rendering_meta_field_on_cart_and_checkout( $cart_data, $cart_item ) {
$custom_items = array();
if( !empty( $cart_data ) ) {
$custom_items = $cart_data;
}
if( isset( $cart_item['wccpf_enter_product_id'] ) ) {
$diamond = $cart_item['wccpf_enter_product_id'];
$pacolor = get_the_terms($diamond, 'pa_color');
foreach ( $pacolor as $pacolor ) {
$color= $pacolor ->name;
}
$custom_items[] = array( "name" => "color", "value" => $color);
}
return $custom_items;
}
如何在订单中显示自定义产品字段wccpf_enter_product_id'的值?
谢谢 .
1 回答
您可以使用挂钩在woocommerce_add_order_item_meta动作钩子中的自定义函数来实现此目的 .
所以你的代码将是这样的:
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .
这应该工作
Related answers:
Adding user custom field value to order items details
Add custom Product data dynamically as item meta data on the Order
Displaying custom product data in Order items view