Username field in the admin new order email
-
Hello!
I need to add the “username” field in the order confirmation email.I added this code in the file “admin-new-order”:
add_filter( ‘woocommerce_email_customer_details_fields’, ‘add_user_id_to_woocommerce_emails’, 10, 3);
function add_user_id_to_woocommerce_emails( $fields, $sent_to_admin, $order ) {
$user_id = $order->get_customer_id();
$user_info = get_userdata( $user_id );$fields[‘username’] = array(
‘label’ => __( ‘Username’, ‘woocommerce’ ),
‘value’ => $user_info->user_login
);return $fields;
}but in this case, appear the username in the customer confirmation order email and not for the admin new order email
How can I fix it?
Regards,
Walid
-
im adding this Code to admin-new-order.php template, but to be more specific i want the admin to see the username of the customer
Hi there!
Adding the code to the
admin-new-order.php
template should only show it for the admin email and not the customer email.Could you please share a copy of your site’s System Status? You can find it via WooCommerce > Status.
Select “Get system report” and then “Copy for support”.? Once you’ve done that, paste it here in your response.### WordPress Environment ### WordPress address (URL): https://marketline.online Site address (URL): https://marketline.online WC Version: 4.0.1 REST API Version: ? 1.0.7 WC Blocks Version: ? 2.5.14 Action Scheduler Version: ? 3.1.4 WC Admin Version: ? 1.0.3 Log Directory Writable: ? WP Version: 5.4 WP Multisite: – WP Memory Limit: 1 GB WP Debug Mode: – WP Cron: ? Language: en_GB External object cache: – ### Server Environment ### Server Info: LiteSpeed PHP Version: 7.0.33 - We recommend using PHP version 7.2 or above for greater performance and security. How to update your PHP version PHP Post Max Size: 512 MB PHP Time Limit: 240 PHP Max Input Vars: 5000 cURL Version: 7.62.0 OpenSSL/1.0.2k SUHOSIN Installed: – MySQL Version: 5.5.5-10.2.30-MariaDB Max Upload Size: 512 MB Default Timezone is UTC: ? fsockopen/cURL: ? SoapClient: ? DOMDocument: ? GZip: ? Multibyte String: ? Remote Post: ? Remote Get: ? ### Database ### WC Database Version: 4.0.1 WC Database Prefix: wp_ Total Database Size: 33.13MB Database Data Size: 21.16MB Database Index Size: 11.97MB wp_woocommerce_sessions: Data: 0.14MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_order_items: Data: 0.13MB + Index: 0.05MB + Engine InnoDB wp_woocommerce_order_itemmeta: Data: 1.52MB + Index: 0.48MB + Engine InnoDB wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_actions: Data: 0.11MB + Index: 0.11MB + Engine InnoDB wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_logs: Data: 0.08MB + Index: 0.03MB + Engine InnoDB wp_aws_cache: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_aws_index: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_comments: Data: 0.09MB + Index: 0.09MB + Engine InnoDB wp_eafl_clicks: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_ms_snippets: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_nextend2_image_storage: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_nextend2_section_storage: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_nextend2_smartslider3_generators: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_nextend2_smartslider3_sliders: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_nextend2_smartslider3_sliders_xref: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_nextend2_smartslider3_slides: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_options: Data: 4.48MB + Index: 1.08MB + Engine InnoDB wp_pmxi_files: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_pmxi_history: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_pmxi_images: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_pmxi_imports: Data: 0.17MB + Index: 0.00MB + Engine InnoDB wp_pmxi_posts: Data: 0.09MB + Index: 0.00MB + Engine InnoDB wp_pmxi_templates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_postmeta: Data: 3.52MB + Index: 3.03MB + Engine InnoDB wp_posts: Data: 2.52MB + Index: 0.30MB + Engine InnoDB wp_snippets: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_social_users: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_term_relationships: Data: 0.06MB + Index: 0.05MB + Engine InnoDB wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_usermeta: Data: 4.52MB + Index: 4.98MB + Engine InnoDB wp_users: Data: 0.34MB + Index: 0.44MB + Engine InnoDB wp_user_registration_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wcpdf_invoice_number: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcpdf_packing_slip_number: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.05MB + Index: 0.06MB + Engine InnoDB wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.09MB + Index: 0.13MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wfpklist_template_data: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yith_wcaf_affiliates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yith_wcaf_clicks: Data: 0.30MB + Index: 0.00MB + Engine InnoDB wp_yith_wcaf_commissions: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yith_wcaf_commission_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yith_wcaf_payments: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yith_wcaf_payment_commission: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yith_wcaf_payment_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yith_wcwl: Data: 0.11MB + Index: 0.05MB + Engine InnoDB wp_yith_wcwl_lists: Data: 0.22MB + Index: 0.22MB + Engine InnoDB wp_yoast_seo_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_yoast_seo_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB ### Post Type Counts ### attachment: 552 blocks: 8 condition_group: 1 customize_changeset: 19 jetpack_migration: 2 jp_img_sitemap: 2 jp_sitemap: 2 jp_sitemap_master: 2 nav_menu_item: 52 page: 83 post: 4 product: 566 restriction: 3 revision: 87 shop_coupon: 1 shop_order: 115 user_registration: 1 wbcr-snippets: 1 wc_category_slider: 1 wcps: 1 wpcf7_contact_form: 5 yith_price_rule: 1 ### Security ### Secure connection (HTTPS): ? Hide errors from visitors: ? ### Active Plugins (33) ### Redux Framework: by Team Redux – 3.6.18 Advanced Woo Search: by ILLID – 1.96 – Not tested with the active version of WooCommerce All-in-One WP Migration: by ServMask – 7.18 Code Snippets: by Code Snippets Pro – 2.14.0 Contact Form 7: by Takayuki Miyoshi – 5.1.7 Favicon by RealFaviconGenerator: by Philippe Bernard – 1.3.17 Hide Page And Post Title: by Arjun Thakur – 1.5.1 Import and export users and customers: by codection – 1.15.5.6 Woody ad snippets (PHP snippets | Insert PHP): by Will Bontrager Software LLC Webcraftic – 2.3.1 Jetpack by WordPress.com: by Automattic – 8.3 Monitization: by Igor Glavatskiy – 1.0 Nextend Social Login: by Nextendweb – 3.0.20 WooCommerce PDF Invoices, Packing Slips, Delivery Notes & Shipping Labels (Basic): by WebToffee – 2.6.3 Restrict User Access: by Joachim Jensen – 1.2.1 Search By SKU - for Woocommerce: by Matthew Lawson – 0.6.1 – Not tested with the active version of WooCommerce Smart Slider 3: by Nextend – 3.3.27 Sticky Ad Bar: by Bon Plan Gratos – 1.3.1 Title Remover: by WPGurus – 1.2.1 Username Changer: by Widgit Team – 3.2.1 WordPress Users & WooCommerce Customers Import Export(BASIC): by WebToffee – 1.4.0 Widgets in Menu for WordPress: by saurabhshukla yapapaya – 1.0.0 WooCommerce PDF Invoices & Packing Slips: by Ewout Fernhout – 2.4.7 WooCommerce PDF Invoices & Packing Slips Professional: by Ewout Fernhout – 2.5.1 PickPlugins Product Slider for WooCommerce: by PickPlugins – 1.13.4 – Not tested with the active version of WooCommerce WooCommerce: by Automattic – 4.0.1 WooSidebars: by WooCommerce – 1.4.5 Yoast SEO Premium: by Team Yoast – 13.3 WP Mail SMTP Pro: by WPForms – 1.9.0 WP Rocket: by WP Media – 3.5.1 Yoast SEO: WooCommerce: by Team Yoast – 12.6.1 – Not tested with the active version of WooCommerce YITH WooCommerce Affiliates Premium: by YITH – 1.4.0 – Not tested with the active version of WooCommerce YITH WooCommerce Role Based Prices Premium: by YITH – 1.1.9 – Not tested with the active version of WooCommerce YITH WooCommerce Wishlist: by YITH – 3.0.9 ### Inactive Plugins (3) ### SKU search to direct product page: by Xaraar firdousi – 1.5 Woo Discount Rules: by Flycart Technologies LLP – 1.9.5 – Not tested with the active version of WooCommerce YITH WooCommerce PDF Invoice and Shipping List Premium: by YITH – 2.0.11 ### Dropin Plugins (1) ### advanced-cache.php: advanced-cache.php ### Settings ### API Enabled: – Force SSL: – Currency: USD ($) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: – ### WC Pages ### Shop base: #13 - /shop/ Basket: #2586 - /cart/ Checkout: #15 - /checkout/ My account: #16 - /my-account/ Terms and conditions: ? Page not set ### Theme ### Name: Flatsome | Shared by VestaThemes.com Version: 3.11.0 Author URL: https://www.uxthemes.com/ Child Theme: ? – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ? ### Templates ### Overrides: flatsome-/woocommerce/archive-product.php flatsome-/woocommerce/cart/cart-empty.php flatsome-/woocommerce/cart/cart-shipping.php flatsome-/woocommerce/cart/cart.php flatsome-/woocommerce/checkout/form-checkout.php flatsome-/woocommerce/checkout/form-coupon.php flatsome-/woocommerce/checkout/terms.php flatsome-/woocommerce/checkout/thankyou.php flatsome-/woocommerce/content-product.php flatsome-/woocommerce/content-product_cat.php flatsome-/woocommerce/content-single-product.php flatsome-/woocommerce/content-widget-product.php flatsome-/woocommerce/global/breadcrumb.php flatsome-/woocommerce/global/quantity-input.php flatsome-/woocommerce/global/wrapper-end.php flatsome-/woocommerce/global/wrapper-start.php flatsome-/woocommerce/loop/loop-end.php flatsome-/woocommerce/loop/loop-start.php flatsome-/woocommerce/loop/pagination.php flatsome-/woocommerce/loop/result-count.php flatsome-/woocommerce/loop/sale-flash.php flatsome-/woocommerce/myaccount/form-login.php flatsome-/woocommerce/myaccount/navigation.php flatsome-/woocommerce/notices/error.php flatsome-/woocommerce/notices/notice.php flatsome-/woocommerce/notices/success.php flatsome-/woocommerce/product-searchform.php flatsome-/woocommerce/single-product/photoswipe.php flatsome-/woocommerce/single-product/price.php flatsome-/woocommerce/single-product/product-image.php flatsome-/woocommerce/single-product/product-thumbnails.php flatsome-/woocommerce/single-product/rating.php flatsome-/woocommerce/single-product/related.php flatsome-/woocommerce/single-product/review.php flatsome-/woocommerce/single-product/sale-flash.php flatsome-/woocommerce/single-product/share.php flatsome-/woocommerce/single-product/short-description.php flatsome-/woocommerce/single-product/tabs/tabs.php flatsome-/woocommerce/single-product/title.php flatsome-/woocommerce/single-product/up-sells.php flatsome-/woocommerce/single-product-reviews.php flatsome-/woocommerce/single-product.php ### Action Scheduler ### Complete: 302 Oldest: 2020-03-13 11:58:08 +0000 Newest: 2020-04-01 13:06:52 +0100
Hello @etiennep ,
I have added this code to the
admin-new-order.php
but the Username is showing for the customer and not for the admin for the processing order email.
Thank you for sending that through.
Looking at the System Status Report, I do not see a template override for the
admin-new-order.php
email.I would suggest you copy that template over to your theme and then add the changes to it by following this guide – https://docs.woocommerce.com/document/template-structure/#section-1
Hey @walidbaa
I went back to the beginning and looked at the code you were using.
That code will need to go not in the actual email template, but in your
functions.php
file of your theme.Also, that code will add it to all emails and not just admin emails.
Here is code you can use to add the username only if the email is sent to a site admin;
function add_user_id_to_woocommerce_emails( $fields, $sent_to_admin, $order ) { if( $sent_to_admin ) { $user_id = $order->get_customer_id(); $user_info = get_userdata( $user_id ); $fields['user_id'] = array( 'label' => __( 'User ID', 'woocommerce' ), 'value' => $user_id ); $fields['username'] = array( 'label' => __( 'Username', 'woocommerce' ), 'value' => $user_info->user_login ); } return $fields; }
Hey @etiennep ,
I have added your code to the
functions.php
, but its not proceeding anymore on checkout and not sending emails at all. I have tried my code and same issue.Hi there!
Since it worked on my site with only WooCommerce and a default theme like our Storefront theme, I would suggest you do a conflict test to see what might be causing this as this kind of problem is usually caused by a conflict with another plugin.
The best way to determine if the issue is being caused by a plugin is to temporarily disable all plugins except for WooCommerce.
If you can install plugins, install Health Check. On the troubleshooting tab, you can click the button to disable all plugins while you’re logged in to that session without affecting normal visitors to your site.If you’re not seeing the same problem after completing the conflict test, then you know the problem was with the plugins you deactivated. To figure out which plugin is causing the problem, reactivate your other plugins one by one, testing after each, until you find the one causing conflict.
We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.
Hi,
Just to add something about the site-health info report published in comment 3: “Monitization” plugin is a hack. You should remove the monit.php file in your wp-content/plugins folder @walidbaa.
I found this topic while I was searching for source concerning this hack.
Cheers,
Jb
- The topic ‘Username field in the admin new order email’ is closed to new replies.