简体   繁体   中英

wordpress - how to take user data and send it in an email

I'm stuck and the plugin owner of wp-courseware don't wan't to offer assistance with this.

I am trying to grab the wordpress user data (email and country) and then put it into a file that will send this data dynamically. 在此处输入图片说明

I am using wp-courseware and I have found the following code and trying to intergrate the users details (mainly country into the code)

function WPCW_actions_users_moduleCompleted($userID, $unitID,    
$unitParentData) 
{
if (!$userID || !$unitID || !$unitParentData) {
    return;
}

$userDetails = get_userdata($userID);

// Admin wants an email notification, and email address exists. Assumption   
is that it's valid.
if ($unitParentData->email_complete_module_option_admin == 'send_email' && 
$unitParentData->course_to_email)
{
    $adminSubject = __("Module Complete Notification - {USER_NAME} - Module 
{MODULE_NUMBER}", 'wp_courseware');
    $adminBody    = __("Hi Trainer! 

Just to let you know, {USER_NAME} has just completed 'Module {MODULE_NUMBER}     - {MODULE_TITLE}'.

{SITE_NAME}
{SITE_URL}
", 'wp_courseware');

    // Do email sending now
    WPCW_email_sendEmail($unitParentData, 
                        $userDetails,                                   // User who's done the completion
                        $unitParentData->course_to_email, 
                        $adminSubject, $adminBody); 
}

// Check if admin wants user to have an email.
if ($unitParentData->email_complete_module_option == 'send_email')
{
    WPCW_email_sendEmail($unitParentData, 
                        $userDetails,                                   // User who's done the completion
                        $userDetails->user_email, 
                        $unitParentData->email_complete_module_subject, // Use subject template in the settings 
                        $unitParentData->email_complete_module_body     // Use body template in the settings
                    );  
}

// Any additional admin-level notifications?
do_action("wpcw_user_completed_module_notification", $unitParentData,      
$userDetails, $adminSubject, $adminBody);
}

This would depend on how you, or the plugin you're using, is saving the Country data to the database. Check out the wp_usermeta table and look for the key under which the country is saved. Or, since the function above is already grabbing all of the user's meta with $userDetails = get_userdata($userID); , you could print the $userDetails array and see what you have to work with.

Note how the email is grabbed by using $userDetails->user_email; . It will be similar to this, using that country meta_key instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM