[英]Show custom fields in WooCommerce quick order preview
In WooCommerce admin orders list, clicking on the "eye icon" gives a quick preview for the order info.在 WooCommerce 管理订单列表中,单击“眼睛图标”可以快速预览订单信息。
I've added custom billing checkout fields, but they are not shown in this quick preview and instead under billing details it displays "N/A":我添加了自定义帐单结帐字段,但它们未显示在此快速预览中,而是在帐单详细信息下显示“不适用”:
However when choose the edit order page, I can see them.但是,在选择编辑订单页面时,我可以看到它们。
How to display that billing custom fields in order quick preview?如何显示计费自定义字段以便快速预览?
In the code below, for each of your billing custom fields, you will have to set the correct meta key .在下面的代码中,对于每个账单自定义字段,您必须设置正确的元键。 It will display your billing custom fields in the quick order preview under Billing section:
它将在账单部分下的快速订单预览中显示您的账单自定义字段:
add_filter( 'woocommerce_admin_order_preview_get_order_details', 'admin_order_preview_add_custom_billing_data', 10, 2 );
function admin_order_preview_add_custom_billing_data( $data, $order ) {
$custom_billing_data = []; // initializing
// Custom field 1: Replace '_custom_meta_key1' by the correct custom field metakey
if( $custom_value1 = $order->get_meta('_custom_meta_key1') ) {
$custom_billing_data[] = $custom_value1;
}
// Custom field 2: Replace '_custom_meta_key1' by the correct custom field metakey
if( $custom_value2 = $order->get_meta('_custom_meta_key1') ) {
$custom_billing_data[] = $custom_value2;
}
## ……… And so on (for each additional custom field).
// Check that our custom fields array is not empty
if( count($custom_billing_data) > 0 ) {
// Converting the array in a formatted string
$formatted_custom_billing_data = implode( '<br>', $custom_billing_data );
if( $data['formatted_billing_address'] === __( 'N/A', 'woocommerce' ) ) {
$data['formatted_billing_address'] = $formatted_custom_billing_data;
} else {
$data['formatted_billing_address'] .= '<br>' . $formatted_custom_billing_data;
}
}
return $data;
}
Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 It should work.
它应该工作。
Related: Display custom data on Woocommerce admin order preview相关: 在 Woocommerce 管理订单预览中显示自定义数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.