WooCommerce 2.5: Add SKU On New Order Email
Update: This bug has been fixed in WooCommerce 2.5.1 for Admin New Order notifications only. If you are running WooCommerce 2.5, test the 2.5.1 upgrade on a staging server. Once you’ve determined everything is functioning normally, upgrade to WooCommerce 2.5.1 on your production (live) server.
The WooCommerce update to version 2.5 was a major update, and many improvements were made for performance and future scalability.
One thing that several people have pointed out, however, is the SKU numbers on the admin New Order Email notification have disappeared.
Many WooCommerce site owners use the SKUs found in the New Order emails they receive to quickly figure out what items they need to ship.
Other site owners use shipping and fulfillment partners to put together orders, and having partners log into the site as an admin just to figure out what items are in each order is not always convenient or desirable.
According to WooCommerce developer Mike Jolley, this will be fixed in a near-future version of WooCommerce, but here’s a way to fix this temporarily.
Adding Back SKUs In The WooCommerce 2.5 New Order Email
As some of you may already know, WooCommerce allows you to override the default plugin templates on a case-by-case basis.
If you’re using a premium theme, ideally you’re already using a WordPress child theme. Some of you may be using a custom built theme. The first step is find what theme you are using, and locate what folder it is in on your server.
For example, if you are using the Twenty Sixteen theme, you would find this on your server in a path like this:
/wp-content/themes/twentysixteen/
What we’re going to do is override a file called email-order-details.php.
Normally, this is found inside the WooCommerce plugin using this file path:
/woocommerce/templates/emails/email-order-details.php
If you wish to override any default WooCommerce file, what you’ll need to do is replicate the file path — minus the templates directory — inside the theme you are currently using.
Let’s go back to our example above, where we are using Twenty Sixteen as our theme.
If we want to override the email-order-details.php file, we#8217;ll create a directory (folder) inside our theme directory called woocommerce. Inside of that directory, we’ll create another directory called emails. Inside this directory, we’ll upload our replacement file for email-order-details.php.
The final folder path will look like this on our server:
/wp-content/themes/twentysixteen/woocommerce/emails/email-order-details.php
The Original Code
Here’s what the original email-order-details.php file looks like in WooCommerce 2.5 and 2.5.1.
<?php
/**
* Order details table shown in emails.
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-details.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* @see http://docs.woothemes.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
<?php if ( ! $sent_to_admin ) : ?>
<h2><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></h2>
<?php else : ?>
<h2><a class="link" href="<?php echo esc_url( admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ); ?>"><?php printf( __( 'Order #%s', 'woocommerce'), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $order->order_date ) ), date_i18n( wc_date_format(), strtotime( $order->order_date ) ) ); ?>)</h2>
<?php endif; ?>
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
<thead>
<tr>
<th class="td" scope="col" style="text-align:left;"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:left;"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:left;"><?php _e( 'Price', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php echo $order->email_order_items_table( array(
'show_sku' => $sent_to_admin,
'show_image' => false,
'$image_size' => array( 32, 32 ),
'plain_text' => $plain_text,
'sent_to_admin' => $sent_to_admin
) ); ?>
</tbody>
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
?><tr>
<th class="td" scope="row" colspan="2" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td class="td" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
Our Override Code
Here’s our replacement email-order-details.php file that we’re uploading via FTP or other means to the woocommerce/emails directory in our theme.
<?php
/**
* Order details table shown in emails.
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-details.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* @see http://docs.woothemes.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
<?php if ( ! $sent_to_admin ) : ?>
<h2><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></h2>
<?php else : ?>
<h2><a class="link" href="<?php echo esc_url( admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ); ?>"><?php printf( __( 'Order #%s', 'woocommerce'), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $order->order_date ) ), date_i18n( wc_date_format(), strtotime( $order->order_date ) ) ); ?>)</h2>
<?php endif; ?>
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
<thead>
<tr>
<th class="td" scope="col" style="text-align:left;"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:left;"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:left;"><?php _e( 'Price', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php echo $order->email_order_items_table( array(
'show_sku' => true,
'show_image' => false,
'$image_size' => array( 32, 32 ),
'plain_text' => $plain_text,
'sent_to_admin' => $sent_to_admin
) ); ?>
</tbody>
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
?><tr>
<th class="td" scope="row" colspan="2" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td class="td" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
What Did We Change?
Basically, we only changed one piece of code here.
The original line reads,
'show_sku' => $sent_to_admin,
and our modified line reads,
'show_sku' => true,
This is a temporary bug in WooCommerce. The WooThemes development team are aware of it, and are fixing this for Admin Notifications shortly.
Hello,
I tried your code and change ‘show_sku’ => true but didn’t work 🙁
Hi Mufaddal:
This bug was actually fixed in WooCommerce 2.5.1. You just need to upgrade to that version or later to fix the missing SKU on New Order emails.
Hello,
Thank you for your reply.
I have done with other solution 🙂 well i am using the latest version of woocommerce
Thanks
I have updated today to Woocommerce 2.6.2. I’ve added your “show_sku” => true, and I am now getting the sku on the customer notification email, but not on the admin new order – any ideas?
Not much info to be found on this – I’m also no longer showing the SKU cart, checkout or checkout complete pages. Help!
Hi Cindy:
If you’ve already updated to WooCommerce 2.6.2, you shouldn’t need this fix any longer, as it it was fixed in WooCommerce 2.5.1. It’s possible this may be part of your problem.
If you aren’t seeing your other pages (Cart, Checkout, etc.), look at Pages > All Pages to make sure those pages are still published. It sounds like there may be more than one thing going on. It’s hard to say without looking at the actual admin area of your site.
One thing you can do is go to WooCommerce > System Status and take a look to see if there are any items that may be flagged. This page will tell you if you have theme files that need to be updated, let you know if your hosting is running an old version of PHP, and let you troubleshoot some other common things that get missed.
It looks like you just moved to WordPress and WooCommerce about four or five months ago, so fully expect there to be a learning curve. WooCommerce (or any e-commerce platform) is much more complex than a regular website.
Hi, Im currently running Version 2.6.4 and I cant get the SKU to show on order emails to the admin? Can you help?
Hi Lee:
If you are running WooCommerce 2.6.4 with no override templates, you should be receiving the New Order Confirmation emails with the SKU. What’s your domain name? It’s hard to tell what’s going on without seeing what’s going on.
One thing that I would look for — If you are running a WordPress theme that you purchased form ThemeForest, it’s likely that you have WooCommerce bundled into the theme, and your theme may have override template files.
Login to your site, and go to WooCommerce > System Status and scroll to the bottom of the page. See if there are any theme-specific template files that need to be updated.
If this isn’t the case, we’d have to dig deeper to find the root of the problem.
Hello! Help me please! I created a new status of the order “wc-approval”, but he did not receive a letter (New Order online !)
How to solve it?
Hi Erik:
There can be many reasons you’re not receiving a New Order email. Without digging into the actual site, it’s pretty difficult to tell the exact reason why.
Here are some of the things I’ve encountered in the past that would prevent the shop owner from getting the New Order email:
mail()function, but oftentimes, you should be using a SMTP plugin or service to make sure you are getting emails from your site. I use the Postman SMTP plugin where a plugin will suffice. For very large stores, you will want to use a service like MailGun or SendGrid.These are just a few things that could be causing you to not get emails from WooCommerce. Make sure you can get emails from other internal site functions (like resetting your password, or a contact form) to determine whether it is WooCommerce or email on your site in general.
Hello:
How we get the order detail in WooCommerce 2.6.14?
The first thing I would check is your email notification settings. Make sure that the department that is supposed to be getting emails is receiving them.
If they are not receiving order emails, I would check to make sure your site is sending emails correctly. Sometimes you need to set up SMTP email, and add SPF and DKIM records to your domain name records.
It is almost always an issue with email being misconfigured if you are not getting order emails.