0
如何根據用戶的輸入操作忍者形式(3)郵件正文?操作忍者形式郵件正文
例如:
用戶填寫的zipcode
領域,我wan't將數據添加到最近的便利店的郵件正文。
我發現的唯一有用的過濾器是「ninja_forms_submit_data
」。但它只返回字段ID和用戶輸入。
我需要的是一個字段鍵,所以我可以使用它作爲參考。
如何根據用戶的輸入操作忍者形式(3)郵件正文?操作忍者形式郵件正文
例如:
用戶填寫的zipcode
領域,我wan't將數據添加到最近的便利店的郵件正文。
我發現的唯一有用的過濾器是「ninja_forms_submit_data
」。但它只返回字段ID和用戶輸入。
我需要的是一個字段鍵,所以我可以使用它作爲參考。
有一個名爲ninja_forms_action_email_message
的過濾器可用於自定義電子郵件正文。源代碼是here。
該過濾器具有三個參數:
$message
這是當前的電子郵件主體的(HTML)串$data
表格數據(包括有關的形式,並且用戶提交數據)$action_settings
PARAMS用於發送電子郵件(至地址等)例如:
function custom_email_body_content($message, $data, $action_settings) {
// You may want to check if the form needs to be customised here
// $data contains information about the form that was submitted
// Eg. if ($data[form_id]) === ...
// Convert the submitted form data to an associative array
$form_data = array();
foreach ($data['fields'] as $key => $field) {
$form_data[$field['key']] = $field['value'];
}
// Do something to the email body using the value of $form_data['zipcode']
// Maybe a str_replace of a token, or generate a new email body from a template
// Return the modified HTML email body
return $message;
}
add_filter('ninja_forms_action_email_message', 'custom_email_body_content', 10, 3);