在WooCommerce中,我想在结帐时添加一些自定义字段,这些字段将显示在电子邮件确认的 billing 部分下 . 我的自定义字段及其值,显示在结帐表单和后端的订单页面上(WooCommerce - > Orders) . 到目前为止一切都很好 .
The problem is that the e-mail that i receive does not contain the custom fields and their values.
代码如下所示:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_field_testing'] = array(
'label' => __('TestingField', 'woocommerce'),
'placeholder' => _x('TestingField', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order)
{
echo '<p><strong>'.__('TestingField').':</strong> ' . get_post_meta( $order->id, '_billing_field_testing', true ) . '</p>';
}
请帮忙 .
提前致谢
2 回答
Updated: 要在帐单邮寄地址下方的电子邮件通知中显示自定义结帐字段,请使用此函数挂钩在优先级高于20的 woocommerce_email_customer_details 操作挂钩中:
代码在您的活动子主题(或主题)的function.php文件中或在任何插件文件中 .
此代码经过测试并可以使用 .
您需要在woocommerce / templates / emails /下定制电子邮件模板到您的主题/ woocommerce /电子邮件/
你可以覆盖你想要的任何模板,最后在那里添加自定义字段 .
或者,您也可以使用以下代码中的钩子添加它们: