I added the following code to the file – paypal-ipn.php
*The status of Pending is set to test the code.
//Message sending
if ($payment_status = 'Pending') {
$ds_first_name = sanitize_text_field($ipn_response['first_name']);
$ds_last_name = sanitize_text_field($ipn_response['last_name']);
$ds_payer_email = sanitize_text_field($ipn_response['payer_email']);
$ds_payment_gross = sanitize_text_field($ipn_response['payment_gross']);
$ds_item_name = sanitize_text_field($ipn_response['item_name']);
$ds_mc_currency = sanitize_text_field($ipn_response['mc_currency']);
$ds_mail = get_option('admin_email');
$ds_message = '<div><p style="font-size:16px;">You recive new order from Paypal</p><strong>User information.</strong><br>User name: '.$ds_first_name.' '.$ds_last_name.'<br>User email: '.$ds_payer_email.'<br>Product: '.$ds_item_name.'<br><strong>Amount: '.$ds_payment_gross.' '.$ds_mc_currency.'</strong></div>';
$ds_subject = 'New order';
$ds_from = get_option('blogname');
$headers[] = 'From: '.$ds_from.' <'.$ds_mail.'>';
$headers[] = 'Content-type: text/html; charset=utf-8';
wp_mail($ds_mail, $ds_subject, $ds_message, $headers, $attachments);
wp_paypal_debug_log("I send mail to admin", false);
return;
}
For the site administrator, this is enough.
But how to add a field with the WordPress editor in the plugin settings, in order to customize the email that will be sent to the user? Help me please.
Add enable or disable and setting on plugin page.
//User email (enable or disable)
if (get_option('paypal_email_enable') == '1') {
//User email body
$us_mail = get_option('admin_email'); //Email user to send message = sanitize_text_field($ipn_response['payer_email']);
$us_from_name = get_option('blogname');
$us_message = get_option('paypal_email_body');
$us_subject = get_option('paypal_email_subject');
$us_from_mail = get_option('paypal_email_from');
$us_headers[] = 'From: '.$us_from_name.' <'.$us_from_mail.'>';
$us_headers[] = 'Content-type: text/html; charset=utf-8';
wp_mail($us_mail, $us_subject, $us_message, $us_headers);
}
Last question.
How to use wp_editor () instead of textarea. And do not crop the html tags. Now I have such a code.
add_option('paypal_email_body', '');
update_option('paypal_email_body', trim($_POST["paypal_email_body"]));
<tr valign="top">
<th scope="row"><label for="paypal_email_body"><?Php _e('PayPal Email Body', 'wp-paypal');?></label></th>
<td>
<textarea name="paypal_email_body" rows="10" cols="45" id="paypal_email_body" class="regular-text"><?php echo get_option('paypal_email_body'); ?></textarea>
<p class="description"><?Php _e('Your client email body', 'wp-paypal');?></p></td>
</tr>
$paypal_email_body = get_option('paypal_email_body');