Home / eCommerce / Add vendor’s details on customer’s order email
Duplicate Snippet

Embed Snippet on Your Site

Add vendor’s details on customer’s order email

Use this code snippet to add the following information to be included in the purchase email sent to the customer: store name, phone number, and email address.

Code Preview
php
<?php
add_action('woocommerce_email_after_order_table', 'wcv_add_vendor_info_to_email', 20, 4);
function wcv_add_vendor_info_to_email($order, $sent_to_admin, $plain_text, $email) {
    if (!class_exists('WCV_Vendors')) {
        return; // WC Vendors not active
    }
    // Collect vendor IDs from order items
    $vendor_ids = array();
    foreach ($order->get_items() as $item) {
        $product_id = $item->get_product_id();
        $vendor_id = WCV_Vendors::get_vendor_from_product($product_id);
        if ($vendor_id && !in_array($vendor_id, $vendor_ids)) {
            $vendor_ids[] = $vendor_id;
        }
    }
    if (!empty($vendor_ids)) {
        echo '<h3>Vendor Details</h3>';
        foreach ($vendor_ids as $vendor_id) {
            $store_name = WCV_Vendors::get_vendor_shop_name($vendor_id);
            $store_email = get_userdata($vendor_id)->user_email;
            $store_phone = get_user_meta($vendor_id, '_wcv_store_phone', true); // Assuming WC Vendors Pro store phone field
            echo '<p><strong>Store Name:</strong> ' . esc_html($store_name) . '</p>';
            echo '<p><strong>Email:</strong> ' . esc_html($store_email) . '</p>';
            if (!empty($store_phone)) {
                echo '<p><strong>Phone:</strong> ' . esc_html($store_phone) . '</p>';
            }
            echo '<hr>';
        }
    }
}

Comments

Add a Comment