如何正确格式化woocommerce订单电子邮件中自定义字段的输出

时间:2013-04-09 18:27:29

标签: woocommerce

这一切都有效 - 除了电子邮件通知打印丑陋的字段名称 - 而不是标签

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
 $fields['billing']['billing_extra_adult_member'] = array(
'label'     => __('2nd Adult Member', 'woocommerce'),
'placeholder'   => _x('Name', 'placeholder', 'woocommerce'),
'required'  => false,
'class'     => array('form-row-first'),
'clear'     => true
 );
 $fields['billing']['billing_extra_child_member1'] = array(
'label'     => __('1st Child Member', 'woocommerce'),
'placeholder'   => _x('Name', 'placeholder', 'woocommerce'),
'required'  => false,
'class'     => array('form-row-first'),
'clear'     => true
 );

return $fields;
}
/**
* Add the field to order
**/
function your_custom_field_function_name($order){
echo "<p><strong>Extra adult member:</strong> " .             
$order->order_custom_fields['_billing_extra_adult_member'][0] . "</p>";
}

add_action( 'woocommerce_admin_order_data_after_billing_address',    
'your_custom_field_function_name', 10, 1 );

/**
* Add the field to order emails
**/
add_filter('woocommerce_email_order_meta_keys',    
'my_custom_checkout_field_order_meta_keys');

function my_custom_checkout_field_order_meta_keys( $keys ) {
$keys[] = '_billing_extra_adult_member';
return $keys;
}

电子邮件通知包含:

_billing_extra_adult_member:Joe Snow

我想这样做:

额外成人:Joe snow

有谁帮忙?

1 个答案:

答案 0 :(得分:-1)

$keys['Extra adult member'] = '_billing_extra_adult_member';