[英]How to send a custom email in the admin panel of wordpress
好吧,我正在嘗試修改一個小插件。 該插件計算項目的押金,在用戶支付押金后,該插件會向用戶發送一封電子郵件,說明押金已經支付。
我想在woocommerce訂單的管理面板上添加一個按鈕,一旦單擊該按鈕,就會向該用戶發送並發送電子郵件,說明還剩多少錢。
首先,我添加了按鈕:
//New action button to send the remaining email
add_action('woocommerce_admin_order_totals_after_total', array($this, 'pay_remaining_email'));
public function pay_remaining_email(){
?>
<tr>
<button type="button" class="button pay_remaining button-primary" title="Send">
<span>Send remaining email</span>
</button>
</tr>
<?php
}
然后我通過jQuery得到這個:
/* This is will get the button from the admin panel to send the remianing email */
$('.pay_remaining').click(function(){
var test = 2;
if (test =! 0){
alert('It works');
} else {
alert('It isnt work');
}
});
顯然,這是一個測試,我想在此處將功能調用到自定義電子郵件中:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WC_Deposits_Email_Customer_Partially_Paid_Complete' ) ) :
/**
* Customer Partially Paid Email
*
* An email sent to the customer when an order is not been paid completed seven days before.
*
*/
class WC_Deposits_Email_Customer_Partially_Paid_Complete extends WC_Email {
/**
* Constructor
*/
function __construct() {
$this->id = 'customer_partially_paid';
$this->title = __( 'Partial Payment Received', 'woocommerce-deposits' );
$this->description = __( 'This is an order notification sent to the customer after payment the deposit, containing order details and a link to pay the remaining balance.', 'woocommerce-deposits' );
$this->heading = __( 'Thank you for your order', 'woocommerce-deposits' );
$this->subject = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce-deposits' );
$this->template_html = 'emails/customer-order-partially-paid.php';
$this->template_plain = 'emails/plain/customer-order-partially-paid.php';
// Triggers for this email
add_action( 'pay_remaining_email', array( $this, 'trigger' ) );
// Call parent constructor
parent::__construct();
$this->template_base = WC_DEPOSITS_TEMPLATE_PATH;
}
/**
* trigger function.
*
* @access public
* @return void
*/
function trigger( $order_id ) {
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
$this->recipient = $this->object->billing_email;
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-number'] = $this->object->get_order_number();
}
if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
return;
}
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
/**
* get_content_html function.
*
* @access public
* @return string
*/
function get_content_html() {
ob_start();
wc_get_template( $this->template_html, array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => false
), '', $this->template_base );
return ob_get_clean();
}
/**
* get_content_plain function.
*
* @access public
* @return string
*/
function get_content_plain() {
ob_start();
wc_get_template( $this->template_plain, array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => true
), '', $this->template_base );
return ob_get_clean();
}
}
endif;
return new WC_Deposits_Email_Customer_Partially_Paid_Complete();
有什么想法我該怎么做?
簡單來說:
注冊一個Ajax端點:
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(操作)
使用jQuery發送Ajax請求:
從Wordpress插件發送電子郵件:
https://developer.wordpress.org/reference/functions/wp_mail/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.