This draft must be merged into the original article, not published as a new one. Publishing it directly creates a duplicate article at the wrong URL.
➡️ Review the draft, then run
/kb-publish 86cxuy4ru — it detects the rydm linkage and routes through the merge endpoint automatically.Original article: How To Set A Different New Order Email Subject For Wholesale Orders · ClickUp task: How To Set A Different New Order Email Subject For Wholesale Orders
If you're running a wholesale store, you may want your new order notification emails to clearly identify wholesale orders, and even show which wholesale role placed the order. WooCommerce Wholesale Prices Premium doesn't include a built-in way to override the email subject yet, but you can customise it using a code snippet. This article shows you how.
Prerequisites
- WooCommerce Wholesale Prices Premium installed and activated
- Access to your theme's
functions.phpfile or a code snippet plugin (such as WPCode)
How to customise the new order email subject for wholesale orders
By default, WooCommerce uses the same email subject for all new orders. The snippet below hooks into woocommerce_email_subject_new_order and adds the wholesale role's display name to the subject when the order is a wholesale order. For retail orders, the default WooCommerce subject is returned unchanged.
Add the following snippet to your child theme's functions.php file or a code snippet plugin:
// Custom New Order Subject - Adding the Wholesale Role Name in the Subject Line
add_filter( 'woocommerce_email_subject_new_order', 'wwpp_change_email_subject', 1, 2 );
function wwpp_change_email_subject( $subject, $order ) {
// Only customise the subject for wholesale orders.
$order_type = $order->get_meta( '_wwpp_order_type', true );
if ( 'wholesale' !== $order_type ) {
return $subject;
}
// Get the wholesale role slug stored on the order (e.g. 'wholesale_customer').
$role_slug = $order->get_meta( '_wwpp_wholesale_order_type', true );
// Look up the human-readable role name from the registered wholesale roles.
// getAllRegisteredWholesaleRoles() returns an array keyed by role slug,
// each entry containing a 'roleName' key with the display name.
$all_wholesale_roles = WWP_Wholesale_Roles::getInstance()->getAllRegisteredWholesaleRoles();
$role_label = isset( $all_wholesale_roles[ $role_slug ]['roleName'] )
? $all_wholesale_roles[ $role_slug ]['roleName']
: $role_slug; // Fallback to slug if the role is no longer registered.
// Build the custom subject using the readable role name.
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$subject = sprintf( '[%s] Order #%s - %s', $role_label, $order->get_id(), $blogname );
return $subject;
}
What _wwpp_order_type and _wwpp_wholesale_order_type store: Every order placed by a wholesale customer gets two meta values. _wwpp_order_type is either 'wholesale' or 'retail'. _wwpp_wholesale_order_type stores the wholesale role slug (e.g. wholesale_customer), not the display name. The snippet above uses getAllRegisteredWholesaleRoles() to convert the slug to the readable label you configured in your wholesale role settings.
Troubleshooting
The subject line is not changing. Check that the snippet has been saved correctly and that there are no PHP errors. The woocommerce_email_subject_new_order filter only runs when WooCommerce sends the new order email. Confirm the email is enabled under WooCommerce → Settings → Emails → New Order.
The subject shows the role slug instead of the display name. This happens if the wholesale role was deleted or renamed after the order was placed. The snippet falls back to the slug in that case. If you see slugs consistently, confirm the role is still registered under WooCommerce Wholesale Prices → Wholesale Roles.
Retail orders are also showing a modified subject. Make sure the snippet includes the _wwpp_order_type !== 'wholesale' early return (as shown above). Without it, the filter runs on retail orders too. Since _wwpp_wholesale_order_type is empty for retail orders, the subject would then show an empty bracket.
Need Help?
If you have a question or run into any issues, we're here to help.
- Premium users: Open a support ticket
- Free users: Visit our community forum
