Changing the email templates
The affiliate emails are built from template files that a theme can override, like WooCommerce’s own email templates. This article lists the templates, what they receive, and the hooks around the emails.
Override a template
Copy the template from the plugin’s templates/emails/ folder into your theme, keeping its path under woocommerce/:
| Theme path | |
|---|---|
| New order, HTML | yourtheme/woocommerce/emails/affiliate-new-order.php |
| New order, plain text | yourtheme/woocommerce/emails/plain/affiliate-new-order.php |
| Payment, HTML | yourtheme/woocommerce/emails/affiliate-payout.php |
| Payment, plain text | yourtheme/woocommerce/emails/plain/affiliate-payout.php |
Use a child theme, so a theme update does not remove your copy. On the email’s settings screen, WooCommerce also offers to copy the file to your theme for you, for users allowed to edit themes.
Note: Keep customer details out of your templates. The emails go to affiliates, who are not your customers.
What the templates receive
| Template | Variables |
|---|---|
| New order | $order, $affiliate (an array with email, name and coupon_code), $email_heading, $intro, $show_commission, $commission_amount, $commission_pending, $additional_content, $sent_to_admin, $plain_text, $email |
| Payment | $payout, $lines, $email_heading, $intro, $additional_content, $sent_to_admin, $plain_text, $email |
Hooks
The two emails are WooCommerce emails with the IDs hrcr_affiliate_new_order and hrcr_affiliate_payout, so WooCommerce’s per-email filters work with them, for example woocommerce_email_subject_hrcr_affiliate_new_order or woocommerce_email_recipient_hrcr_affiliate_payout.
The action hrcr_affiliate_new_order fires once for each affiliate address and order when the new order email is due, with the order ID and the $affiliate array. It fires even while the email is switched off, so a developer can use it to notify affiliates another way.
add_action( 'hrcr_affiliate_new_order', function ( $order_id, $affiliate ) {
error_log( sprintf( 'Order %d used %s, of %s', $order_id, $affiliate['coupon_code'], $affiliate['email'] ) );
}, 10, 2 );
For payment methods that collect on delivery, see Payment methods that collect on delivery.