Custom Checkout Fields Displaying TWO times
-
We are using woocommerce_email_order_meta hook to align the data in HTML format. But it is showing plain text format first and then shows our formated text:
Student First Name:PeterStudent Last name:Koehler
Custom Checkout Fields
Student First Name: Peter
Student Last name: KoehlerTWO times Order Meta Details displaying. How to solve this?
-
Hi,
Thanks for reaching out! Can you send an image of the code you’ve added? And could you also send a screenshot of your email being sent?Kindly,
HannahEmail Output Screenshot:
https://1ezconsulting.com/tester/Email-Screenshot.png
-
This reply was modified 2 years, 9 months ago by
webcritic.
Code using for displaying custom checkout fields:
————————————————-
add_action( ‘woocommerce_email_order_meta’, ‘rich_add_email_order_meta’, 10, 3 );
/*
* @param $order_obj Order Object
* @param $sent_to_admin If this email is for administrator or for a customer
* @param $plain_text HTML or Plain text (can be configured in WooCommerce > Settings > Emails)
*/
function rich_add_email_order_meta( $order_obj, $sent_to_admin, $plain_text ){
$g1 = get_post_meta( $order_obj->get_order_number(), ‘student-name’, true );
$g2 = get_post_meta( $order_obj->get_order_number(), ‘student-last’, true );
$g3 = get_post_meta( $order_obj->get_order_number(), ‘student-address’, true );
$g4 = get_post_meta( $order_obj->get_order_number(), ‘student-city’, true );
$g5 = get_post_meta( $order_obj->get_order_number(), ‘student-zip’, true );
$g6 = get_post_meta( $order_obj->get_order_number(), ‘student-home-phone’, true );
$g7 = get_post_meta( $order_obj->get_order_number(), ‘student-other-phone’, true );
$g8 = get_post_meta( $order_obj->get_order_number(), ‘student-email’, true );
$g9 = get_post_meta( $order_obj->get_order_number(), ‘student-hear-about-us’, true );
$g10 = get_post_meta( $order_obj->get_order_number(), ‘student-birth’, true );
$g11 = get_post_meta( $order_obj->get_order_number(), ‘student-graduation’, true );
$g12 = get_post_meta( $order_obj->get_order_number(), ‘parent1-first-name’, true );
$g13 = get_post_meta( $order_obj->get_order_number(), ‘parent1-last-name’, true );
$g14 = get_post_meta( $order_obj->get_order_number(), ‘parent2-first-name’, true );
$g15 = get_post_meta( $order_obj->get_order_number(), ‘parent2-last-name’, true );
$g16 = get_post_meta( $order_obj->get_order_number(), ‘parents-phone’, true );
$g17 = get_post_meta( $order_obj->get_order_number(), ‘notes-questions-comments’, true );if ( $plain_text === false ) {
// you shouldn’t have to worry about inline styles, WooCommerce adds them itself depending on the theme you use
echo ‘<h2>Custom Checkout Fields</h2>- Student First Name: ‘ . $g1 . ‘
- Student Last name: ‘ . $g2 . ‘
- Address 1: ‘ . $g3 . ‘
- City: ‘ . $g4 . ‘
- Residence Zip: ‘ . $g5 . ‘
- Home Phone: ‘ . $g6 . ‘
- Other Phone: ‘ . $g7 . ‘
- Email Address: ‘ . $g8 . ‘
- How Did You Hear About Us?: ‘ . $g9 . ‘
- Date of birth (mm/dd/yyyy): ‘ . $g10 . ‘
- HS Graduation Year: ‘ . $g11 . ‘
- Parents 1 First Name: ‘ . $g12 . ‘
- Parents 1 Last Name: ‘ . $g13 . ‘
- Parents 2 First Name: ‘ . $g14 . ‘
- Parents 2 Last Name: ‘ . $g15 . ‘
- Parents Phone Number: ‘ . $g16 . ‘
- Notes, Questions, Comments: ‘ . $g17 . ‘
‘;
} else {
echo “”;
}
}Thanks for this. I’ll forward to the dev team. Someone will respond very soon!
Thanks for your patience.Kindly,
HannahCan you send all of the code you are using, perhaps share a link to a gist so formatting is not lost?
Ben
We have given all the codes for displaying Custom Order Meta Fileds. The other part of the email contents displaying from your plugin itself. We have used your plugin for displaying woocommerce email. You can check your current version of the plugin. After updating your plugin 10 days back, we have this issue.
-
This reply was modified 2 years, 9 months ago by
webcritic.
The real issue is, that your plugin displays custom checkout fields TWO times. The first one is not using the action: woocommerce_email_order_meta and the second one is using the action: woocommerce_email_order_meta.
The following is our own code for displaying custom checkout fields:
add_action( ‘woocommerce_email_order_meta’, ‘rich_add_email_order_meta’, 10, 3 ); /* * @param $order_obj Order Object * @param $sent_to_admin If this email is for administrator or for a customer * @param $plain_text HTML or Plain text (can be configured in WooCommerce > Settings > Emails) */ function rich_add_email_order_meta( $order_obj, $sent_to_admin, $plain_text ){ $g1 = get_post_meta( $order_obj->get_order_number(), ‘student-name’, true ); $g2 = get_post_meta( $order_obj->get_order_number(), ‘student-last’, true ); $g3 = get_post_meta( $order_obj->get_order_number(), ‘student-address’, true ); $g4 = get_post_meta( $order_obj->get_order_number(), ‘student-city’, true ); $g5 = get_post_meta( $order_obj->get_order_number(), ‘student-zip’, true ); $g6 = get_post_meta( $order_obj->get_order_number(), ‘student-home-phone’, true ); $g7 = get_post_meta( $order_obj->get_order_number(), ‘student-other-phone’, true ); $g8 = get_post_meta( $order_obj->get_order_number(), ‘student-email’, true ); $g9 = get_post_meta( $order_obj->get_order_number(), ‘student-hear-about-us’, true ); $g10 = get_post_meta( $order_obj->get_order_number(), ‘student-birth’, true ); $g11 = get_post_meta( $order_obj->get_order_number(), ‘student-graduation’, true ); $g12 = get_post_meta( $order_obj->get_order_number(), ‘parent1-first-name’, true ); $g13 = get_post_meta( $order_obj->get_order_number(), ‘parent1-last-name’, true ); $g14 = get_post_meta( $order_obj->get_order_number(), ‘parent2-first-name’, true ); $g15 = get_post_meta( $order_obj->get_order_number(), ‘parent2-last-name’, true ); $g16 = get_post_meta( $order_obj->get_order_number(), ‘parents-phone’, true ); $g17 = get_post_meta( $order_obj->get_order_number(), ‘notes-questions-comments’, true ); if ( $plain_text === false ) { // you shouldn’t have to worry about inline styles, WooCommerce adds them itself depending on the theme you use echo ‘<h2>Custom Checkout Fields</h2> Student First Name: ‘ . $g1 . ‘ Student Last name: ‘ . $g2 . ‘ Address 1: ‘ . $g3 . ‘ City: ‘ . $g4 . ‘ Residence Zip: ‘ . $g5 . ‘ Home Phone: ‘ . $g6 . ‘ Other Phone: ‘ . $g7 . ‘ Email Address: ‘ . $g8 . ‘ How Did You Hear About Us?: ‘ . $g9 . ‘ Date of birth (mm/dd/yyyy): ‘ . $g10 . ‘ HS Graduation Year: ‘ . $g11 . ‘ Parents 1 First Name: ‘ . $g12 . ‘ Parents 1 Last Name: ‘ . $g13 . ‘ Parents 2 First Name: ‘ . $g14 . ‘ Parents 2 Last Name: ‘ . $g15 . ‘ Parents Phone Number: ‘ . $g16 . ‘ Notes, Questions, Comments: ‘ . $g17 . ‘ ‘; } else { echo “”; } }
Hi,
You wrote: “The real issue is, that your plugin displays custom checkout fields TWO times”I can’t recreate this. It seems likely that you have another plugin or have a template file that you are overriding that would be adding a second call to woocommerce_email_order_meta.
Have you tried deactivating all other plugins, and testing with a standard theme?
Ben
We have tried to remove our own woocommerce_email_order_meta hook, but it shows ONLY one set of custom checkout fields without alignments. Please see the screenshot below:
https://1ezconsulting.com/tester/without-align.jpg
Please note that your plugin did not format the custom checkout fields. That is the issue.
This is the screenshot with our own woocommerce_email_order_meta hook
https://1ezconsulting.com/tester/Email-Screenshot.pngHi, Our plugin doesn’t output custom checkout fields into emails. What plugin are you using that is adding custom checkout fields into emails.
Ben
As per your last comment, your plugin has NO function to display custom checkout fields into emails”. Most of the Woocommerce cart, we have to add custom fields to collect additional data from the users. Also we need to show that data in order emails. So in the future update, please add that function to show custom checkout fields into emails.
Thank you.
I think you are miss understanding. all the hooks are in place to hook in custom fields. The same way that you can hook in custom fields for checkout you can hook in custom fields into emails. Our plugin does add fields. Previously you stated:
“The real issue is, that your plugin displays custom checkout fields TWO times”I’m simply trying to clarify that if any custom fields show in the emails it’s not coming from us because that isn’t how this works. If you want to add custom fields you add them and style them however you want.
Does that make sense?
Ben
-
This reply was modified 2 years, 9 months ago by
- The topic ‘Custom Checkout Fields Displaying TWO times’ is closed to new replies.