我有customer-id
的自定义字段用于客户的订购系统,该字段有效,但由于某些奇怪的原因,它不会发送电子邮件或显示在管理区域的订单信息中。我有来自WooDocs的所有正确代码,但它似乎不起作用,我的代码如下。以下文档的链接。
Customizing checkout fields using actions and filters
/**
* Add the field to the checkout
**/
add_action('woocommerce_before_order_notes', 'my_custom_checkout_field',30);
function my_custom_checkout_field( $checkout ) {
woocommerce_form_field( 'customer_number', array(
'type' => 'text',
'class' => array('form-row-wide'),
'label' => __('Customer Number <small>(Enter a customer number or leave empty)</small>'),
'placeholder' => __('Enter a number'),
'required' => false,
), $checkout->get_value( 'customer_number' ));
}
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['customer_number'] ) ) {
update_post_meta( $order_id, 'Customer Number', sanitize_text_field( $_POST['customer_number'] ) );
}
}
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>'.__('Customer Number').':</strong> ' . get_post_meta( $order->id, 'Customer Number', true ) . '</p>';
}
add_filter('woocommerce_email_order_meta_keys', 'my_custom_order_meta_keys');
function my_custom_order_meta_keys( $keys ) {
$keys[] = 'Customer Number'; // This will look for a custom field called 'Customer Number' and add it to emails
return $keys;
}
提前致谢!