• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Damien Carbery - Website Development

Getting You Online & Keeping You There

Getting You Online & Keeping You There Get Started
  • Home
  • Services
  • Maintenance Plans
  • Portfolio
  • Blog
  • About Me
  • Contact
You are here: Home / Website Development / Remove order details from WooCommerce emails

Remove order details from WooCommerce emails

Published: September 25, 2023

Remove order details from WooCommerce emails
Remove the order details table (listing items ordered) from order emails. Optionally remove billing and shipping details.

I am working on a site with a number of custom order statuses for a custom built product. As some of the statuses are just to keep the customer informed of the order progress I felt that the order details tables may not be needed in those emails. So, I investigated.

$this – uh oh – long story to the solution

I always groan when I see an add_action() call that references $this as it may mean that I cannot remove_action() the call. It depends on how the class is instantiated.

The table listing the items ordered is in templates/emails/email-order-items.php. This is loaded in the WC_Emails class function order_details() in includes/class-wc-emails.php and called via an add_action() call in the same file:

add_action( 'woocommerce_email_order_details', array( $this, 'order_details' ), 10, 4 );

I then went looking to find out how the WC_Emails class was instantiated. In includes/class-woocommerce.php I found:

add_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) );

Although WC_Emails has an instance variable that limits it to one instance of the class, it is not set when init_transactional_emails() is called. That said, the WooCommerce class (in includes/class-woocommerce.php has a function mailer() that returns a reference to the WC_Emails instance.

To make a long story short, mailer() can be used to replace $this in my remove_action() call.

Screenshots

The three screenshots of the Order Completed email show the unmodified email, then when the order items table has been removed, and finally, with the billing and shipping information also removed.

Enhancement ideas

In the code below I include a check for the email ID, in case you would like to limit the removal of the order items table to a specific email (or emails).

I also commented out the code that removes the customer billing and shipping details.

When the order items table is removed the email seems rather empty. In this case it might be an opportunity to add more information about the current status. In my client’s case, one of the custom statuses is “In CAD Design.” This may not be very clear to a customer so a short paragraph explaining this status would be very helpful.

The code

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Blog Categories

  • Being Green
  • Food
  • Grammar
  • Just Strange
  • Laziness
  • Personal
  • Portfolio
  • Race Reports
  • Shudder
  • Typo
  • Website Development
  • WooCommerce Tips
  • Facebook
  • Twitter

Copyright © 2013–2023 Damien Carbery · Using Genesis Framework · Privacy Policy