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' ) );
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
To make a long story short,
mailer() can be used to replace
$this in my
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.
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.