Hello guys how are you? Welcome back to my blog therichpost.com. Guys today in this post, I will tell show you Automate sending a welcome email to new vendors in Dokan.
Guys if you are new in WordPress or in WooCommerce then please check the below links for some good tutorials:
Here is the working steps and please follow carefully:
Yes! You can automate sending a welcome email to new vendors in Dokan using a custom code snippet. Below is a PHP function that hooks into the user registration process and sends an email to newly registered vendors.
Custom Code to Send a Welcome Email to New Vendors in Dokan
Add the following code to your theme’s functions.php
file or a custom plugin:
function send_welcome_email_to_new_vendor( $user_id ) {
$user = get_userdata( $user_id );
// Check if the user is a vendor (Dokan assigns the role "seller" to vendors)
if ( in_array( 'seller', (array) $user->roles ) ) {
$to = $user->user_email;
$subject = "Welcome to Our Marketplace!";
$message = "Hi " . $user->first_name . ",\n\n";
$message .= "Welcome to our marketplace! We're excited to have you on board.\n";
$message .= "You can now log in and start setting up your store.\n\n";
$message .= "Visit your dashboard here: " . home_url('/dashboard/') . "\n\n";
$message .= "Best,\nYour Marketplace Team";
// Email headers
$headers = array('Content-Type: text/html; charset=UTF-8');
// Send email
wp_mail( $to, $subject, nl2br($message), $headers );
}
}
add_action( 'user_register', 'send_welcome_email_to_new_vendor' );
How This Works:
- It hooks into
user_register
, which triggers when a new user registers. - It checks if the registered user has the “seller” role (Dokan assigns this role to vendors).
- If the user is a vendor, it sends a custom welcome email with login instructions.
Optional Enhancements:
- Use
wp_new_user_notification
Hook if you want to integrate with WordPress’s built-in email system. - Modify the Email Template to use HTML and make it look more professional.
- Add Attachments like a vendor guide PDF using
wp_mail()
.
Okay guys this is it and if you will have any query then feel free to comment below.
Ajay
Thanks