Home / eCommerce / WWPP – Customize the admin “New Order” email subject for wholesalers v1.1
Duplicate Snippet

Embed Snippet on Your Site

WWPP – Customize the admin “New Order” email subject for wholesalers v1.1

How to apply:
1. Replace the previous snippet with this one in your functions.php or Code Snippets plugin.
2. Place a test order with a wholesale account.
3. Verify that the admin notification subject includes the word "Wholesale".

Code Preview
php
<?php
/**
 * Customize the Admin "New Order" email subject using Wholesale Prices Premium logic
 */
add_filter( 'woocommerce_email_subject_new_order', function( $subject, $order ) {
    
    if ( ! $order ) {
        return $subject;
    }
    // Access the Wholesale Prices Premium global object
    global $wc_wholesale_prices_premium;
    // Get the customer ID from the order
    $customer_id = $order->get_customer_id();
    if ( ! $customer_id ) {
        return $subject;
    }
    // Use WWPP logic to find the customer's wholesale role
    $user_wholesale_role = $wc_wholesale_prices_premium->wwpp_wholesale_roles->getUserWholesaleRole( $customer_id );
    // If the customer has any wholesale role assigned
    if ( ! empty( $user_wholesale_role ) ) {
        // Returns: [{site_title}]: New Wholesale order #{order_number}
        return '[' . get_bloginfo( 'name' ) . ']: New Wholesale order #' . $order->get_order_number();
    }
    return $subject;
}, 10, 2 );

Comments

Add a Comment