Home / eCommerce / WWPP – Add custom text to the Completed Order email for non-wholesale customers only
Duplicate Snippet

Embed Snippet on Your Site

WWPP – Add custom text to the Completed Order email for non-wholesale customers only

If you want to place content elsewhere in the email, swap the hook:
woocommerce_email_before_order_table: Above the order table
woocommerce_email_after_order_table: Below the order table
woocommerce_email_order_meta: In the order meta section
woocommerce_email_customer_details: In the customer details section

More info at: https://woocommerce.com/document/configuring-woocommerce-settings/emails/#custom-email-templates

Code Preview
php
<?php
/**
 * Add custom text to the Completed Order email for non-wholesale customers only.
 */
add_action( 'woocommerce_email_before_order_table', function( $order, $sent_to_admin, $plain_text, $email ) {
    // Only target the Completed Order email
    if ( 'customer_completed_order' !== $email->id ) {
        return;
    }
    $customer_id = $order->get_customer_id();
    
    // If it's a guest order, we treat them as non-wholesale/retail
    if ( $customer_id ) {
        $user = get_userdata( $customer_id );
        $wholesale_roles = [ 'wholesale_customer', 'wholesale_vip' ]; // Add any other custom wholesale roles here
        // If the user has a wholesale role, we return early and do not show the message
        if ( $user && array_intersect( $wholesale_roles, (array) $user->roles ) ) {
            return;
        }
    }
    // Custom message for Retail/Non-Wholesale customers
    if ( $plain_text ) {
        echo "\n\nThank you for your order! We appreciate your business.\n\n";
    } else {
        echo '
        <div style="margin-bottom: 20px; padding: 15px; background-color: #f8f8f8; border-left: 4px solid #ebebeb;">
            <p style="margin: 0; font-size: 14px; color: #333;">
                <strong>Thank you for your order!</strong><br>
                We are processing your items and will notify you once they have shipped. 
                If you have any questions, feel free to reply to this email.
            </p>
        </div>';
    }
}, 10, 4 );

Comments

Add a Comment