Home / eCommerce / Add custom text to WooCommerce Email Templates for Wholesale Customers
Duplicate Snippet

Embed Snippet on Your Site

Add custom text to WooCommerce Email Templates for Wholesale Customers

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 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 ( ! $customer_id ) return;
    $wholesale_roles = [ 'wholesale_customer', 'wholesale_vip' ];
    $user = get_userdata( $customer_id );
    if ( ! $user || ! array_intersect( $wholesale_roles, (array) $user->roles ) ) {
        return; 
    }
    if ( $plain_text ) {
        echo "\n\nThank you for your wholesale order! Your dedicated account manager will be in touch shortly.\n\n";
    } else {
        echo '
        <div style="margin-bottom: 20px; padding: 15px; background-color: #f8f8f8; border-left: 4px solid #333;">
            <p style="margin: 0; font-size: 14px; color: #333;">
                <strong>Thank you for your wholesale order!</strong><br>
                Your dedicated account manager will be in touch shortly. 
                If you have any questions, reply to this email or call us on <strong>+1 800 123 456</strong>.
            </p>
        </div>';
    }
}, 10, 4 );

Comments

Add a Comment