在 Woocommerce Admin、Orders 和电子邮件中显示自定义付款字段 [英] Display custom payment field in Woocommerce Admin, Orders and emails
问题描述
我需要在管理订单页面、thank_you 和电子邮件通知中显示我的自定义结帐字段.
我正在使用
如何正确显示字段?
以下代码将在订单和电子邮件通知中显示您的Udfyld EAN"自定义字段值:
1) 在 Woocommerce 订单管理单页面中显示:
//在管理订单编辑页面显示字段值add_action('woocommerce_admin_order_data_after_shipping_address', 'custom_field_admin_display_order_meta', 10, 1);函数 custom_field_admin_display_order_meta( $order ){$business_address = get_post_meta( $order->get_id(), 'Business Address?', true );if( $udfyld_ean = $order->get_meta('_udfyld_ean') )echo '<p><strong>'.__('Udfyld EAN', 'woocommerce').': </strong>' .$udfyld_ean .'</p>';}
代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.
2) 要在收到的订单、订单视图和电子邮件通知上显示,您将使用:
add_filter( 'woocommerce_get_order_item_totals', 'add_udfyld_ean_row_to_order_totals', 10, 3 );函数 add_udfyld_ean_row_to_order_totals( $total_rows, $order, $tax_display ) {;$new_total_rows = [];foreach($total_rows 作为 $key => $total ){$new_total_rows[$key] = $total;if( $order->get_meta('_udfyld_ean') && 'payment_method' === $key ){$new_total_rows['udfyld_ean'] = 数组('标签' =>__('Udfyld EAN', 'woocommerce'),'价值' =>esc_html( $order->get_meta('_udfyld_ean') ),);}}返回 $new_total_rows;}
代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.
I need to display my custom checkout fields in admin orders page, thank_you and email notifications.
I am using Validate and save additional checkout field for specific payment gateway in Woocommerce answer code to show, validate and save my custom field.
From Woocommerce display custom field data on admin order details I am trying to display my custom field saved inputted value.
This is the code I have so far:
// Display field value on the order edit page
add_action( 'woocommerce_admin_order_data_after_billing_address',
'show_Ean_nummer_in_admin', 10, 1 );
function show_Ean_nummer_in_admin ( $order ){
// Get "ean" custom field value
$udfyld_ean = get_post_meta( $order_id, '_udfyld_ean', true );
// Display "ean" custom field value
echo '<p>'.__('EAN', 'woocommerce') . $udfyld_ean . '</p>';
}
// Display field value on the order emails
add_action( 'woocommerce_email_order_details', 'ean_in_emails' 50, 1 );
function ean_in_emails( $order, $sent_to_admin, $plain_text, $email ){
// Get "ean" custom field value
$udfyld_ean = get_post_meta( $order_id, '_udfyld_ean', true );
// Display "ean" custom field value
echo '<p>'.__('EAN', 'woocommerce') . $udfyld_ean . '</p>';
}
// Display field value in thank you
add_action( 'woocommerce_thankyou', 'ean_in_thankyou' );
function ean_in_thankyou() {
// Get "ean" custom field value
$udfyld_ean = get_post_meta( $order_id, '_udfyld_ean', true );
// Display "ean" custom field value
echo '<p>'.__('EAN', 'woocommerce') . $udfyld_ean . '</p>';
}
But It's not working. The field does get appended to the database, but does not display anywhere:
How can I display the field properly?
The following code will display your "Udfyld EAN" custom field value in orders and email notifications:
1) To display that in Woocommerce order admin single pages:
// Display field value on the admin order edit page
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'custom_field_admin_display_order_meta', 10, 1 );
function custom_field_admin_display_order_meta( $order ){
$business_address = get_post_meta( $order->get_id(), 'Business Address?', true );
if( $udfyld_ean = $order->get_meta('_udfyld_ean') )
echo '<p><strong>'.__('Udfyld EAN', 'woocommerce').': </strong> ' . $udfyld_ean . '</p>';
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
2) To display that on Order received, Order view and email notifications you will use:
add_filter( 'woocommerce_get_order_item_totals', 'add_udfyld_ean_row_to_order_totals', 10, 3 );
function add_udfyld_ean_row_to_order_totals( $total_rows, $order, $tax_display ) {;
$new_total_rows = [];
foreach($total_rows as $key => $total ){
$new_total_rows[$key] = $total;
if( $order->get_meta('_udfyld_ean') && 'payment_method' === $key ){
$new_total_rows['udfyld_ean'] = array(
'label' => __('Udfyld EAN', 'woocommerce'),
'value' => esc_html( $order->get_meta('_udfyld_ean') ),
);
}
}
return $new_total_rows;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
这篇关于在 Woocommerce Admin、Orders 和电子邮件中显示自定义付款字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!