Checkout Fields in emails
-
I created a custom gift message section on the checkout page using the checkout fields/other fields, which works great, but I would like to have the meta data from those fields to show up and display on the admin order confirmation email. Is there a way to do that? I see there is a setting in the products fields, but not the other type of fields for some reason. Please advise.
The page I need help with: [log in to see the link]
-
Hi, pls add the following snippet on your theme’s
functions.php
filefunction add_fields_on_order_email($_fields = array(), $_sent_to_admin, $_order) { if ($_sent_to_admin) { $_fields["Your Field Label"] = get_post_meta($_order->get_id(), "_custom_{Your Custom Field's Key}", true); } return $_fields; } add_filter("woocommerce_email_order_meta_fields", "add_fields_on_order_email", 10, 3);
Thanks for the reply. When we add this code to the functions file we get the following error. I am not sure why.
syntax error, unexpected ‘&’, expecting ‘]’
Please advise. Thanks!`
Following up on this. Please advise as to the Syntax error above. Any suggestions as to why we get this when we add the code your provided?
Hi, can you pls share your code here, so that I can try to validate.
Hi, so I checked today and I am not getting the error message now.
However, when I add the code and resubmit a test notice, the messaging is not showing up on the confirmation notice.
This is the code at the bottom of my functiions.php you can see yours at the bottom
add_action( 'ava_main_header', 'enfold_customization_header_widget_area' ); function enfold_customization_header_widget_area() { dynamic_sidebar( 'header_left' ); dynamic_sidebar( 'header_right' ); } add_theme_support('avia_template_builder_custom_css'); add_filter( 'avf_google_content_font', 'avia_add_content_font'); function avia_add_content_font($fonts) { $fonts['Roboto'] = 'Roboto:400,600,800'; return $fonts; } add_filter( 'avf_google_heading_font', 'avia_add_heading_font'); function avia_add_heading_font($fonts) { $fonts['Roboto'] = 'Roboto:400,600,800'; return $fonts; } /** * Sort the WC Shipping rates from low to high */ function ace_sort_woocommerce_available_shipping_methods( $rates, $package ) { uasort( $rates, function($a, $b) { return $b->get_cost() < $a->get_cost(); }); return $rates; } add_filter( 'woocommerce_package_rates' , 'ace_sort_woocommerce_available_shipping_methods', 10, 2 ); /** * Add custom fields to email notice */ function add_fields_on_order_email($_fields = array(), $_sent_to_admin, $_order) { if ($_sent_to_admin) { $_fields["Your Field Label"] = get_post_meta($_order->get_id(), "_custom_{Your Custom Field's Key}", true); } return $_fields; } add_filter("woocommerce_email_order_meta_fields", "add_fields_on_order_email", 10, 3);
Hi,
One clarification.
$_fields["Your Field Label"] = get_post_meta($_order->get_id(), "_custom_{Your Custom Field's Key}", true);
Here have you updated the
"_custom_{Your Custom Field's Key}"
key with your actual custom field’s key.?If yes and still facing issue, let me have a temp access, I will try to fix it.
Key? Where would I get this key from. It was a free download in the repository and there is no key displayed anywhere in th settings.
Following up on this as we need to get this working asap. I have no access to any key for this plugin. i have looked in every spot I could in the settings and there are no keys displayed. Please advise as to how I can get the key needed to get this script to work.
Hi pls send me your site URL, I will inspect your checkout page and let you know the field’s key.
thanks
function add_fields_on_order_email($_fields = array(), $_sent_to_admin, $_order) { if ($_sent_to_admin) { $_fields["Occasion"] = get_post_meta($_order->get_id(), "_custom_message", true); $_fields["Message"] = get_post_meta($_order->get_id(), "_custom_message_box", true); } return $_fields; } add_filter("woocommerce_email_order_meta_fields", "add_fields_on_order_email", 10, 3);
Let me if any issue.
- This reply was modified 2 years, 7 months ago by Saravana Kumar K.
OK, done. thanks for the advice.
Pls check now.
Here is the updated snippet for adding custom meta Order Notification Email.
function add_fields_on_order_email($_fields = array(), $_sent_to_admin, $_order) { if ($_sent_to_admin) { $_fields[] = array( "label" => "Your Label", "value" => get_post_meta($_order->get_id(), "_custom_{key}", true) ); } return $_fields; } add_filter("woocommerce_email_order_meta_fields", "add_fields_on_order_email", 10, 3);
@mycholan Right now, delete those credentials. If you accept that again you will lose access to these forums and possibly have your plugin removed from this site. It is that serious.
@g4wheeler I have archived your offer to send the developer temp login. If they accept or ask for that, they will be banned.
@mycholan While I know you have the best of intentions, it’s forum policy that you not ask users for admin or server access. Users on the forums aren’t your customers, they’re your open source collaborators, and requesting that kind of access can put you and them at high risk.
If they are paying customers (such as people who bought a premium service/product from you) then by all means, direct them to your official customer support system. But in all other cases, you need to help them here on the forums.
Thankfully are other ways to get information you need:
- Ask the user to install the Health Check plugin and get the data that way.
- Ask for a link to the https://pastebin.com/ or https://gist.github.com log of the user’s web server error log.
- Ask the user to create and post a link to their
phpinfo();
output. - Walk the user through enabling WP_DEBUG and how to log that output to a file and how to share that file.
- Walk the user through basic troubleshooting steps such and disabling all other plugins, clear their cache and cookies and try again (the Health Check plugin can do this without impacting any site vistors).
- Ask the user for the step-by-step directions on how they can reproduce the problem.
You get the idea.
We know volunteer support is not easy, and this guideline can feel needlessly restrictive. It’s actually there to protect you as much as end users. Should their site be hacked or have any issues after you accessed it, you could be held legally liable for damages. In addition, it’s difficult for end users to know the difference between helpful developers and people with malicious intentions. Because of that, we rely on plugin developers and long-standing volunteers (like you) to help us and uphold this particular guideline.
When you help users here and in public, you also help the next person with the same problem. They’ll be able to read the debugging and solution and educate themselves. That’s how we get the next generation of developers.
- The topic ‘Checkout Fields in emails’ is closed to new replies.