我注意到暂停订单电子邮件的客户不可用,所以我尝试用一个可以发送相应电子邮件的操作来替换这些操作。
除了暂停状态外,这似乎有效。我不知道暂停和处理案例之间的区别是什么,而不是$available_emails
class-wc-meta-box-order-actions.php
中的 function ulmh_resend1( $actions ) {
$actions['ulmh_resend'] = __( 'Resend Email', 'text_domain' );
return $actions;
}
function ulmh_resend2( $order ) {
$mailer = WC()->mailer();
$mails = $mailer->get_emails();
if ($order->has_status( 'on-hold' )) {
$eml = 'customer_on_hold_order';
}elseif ($order->has_status( 'processing' )) {
$eml = 'customer_processing_order';
}elseif ($order->has_status( 'completed' )) {
$eml = 'customer_completed_order';
} else {
$eml = "nothing";
}
if ( ! empty( $mails ) ) {
foreach ( $mails as $mail ) {
if ( $mail->id == eml ) {
$mail->trigger( $order->id );
}
}
}
}
function ulmh_resend3( $order_emails ) {
$remove = array( 'new_order', 'cancelled_order', 'customer_processing_order', 'customer_completed_order', 'customer_invoice' );
$order_emails = array_diff( $order_emails, $remove );
return $order_emails;
}
add_action( 'woocommerce_order_actions', 'ulmh_resend1' );
add_action( 'woocommerce_order_action_ulmh_resend', 'ulmh_resend2' );
add_filter( 'woocommerce_resend_order_emails_available', 'ulmh_resend3' );
,我已经删除了所有其他案例,但它们仍然有效。
我做错了什么?是否可以实现这一目标?
我的代码是:
.redrawGroup()
答案 0 :(得分:1)
我已经重新访问并压缩了您的代码,因为某些错误(例如if ( $mail->id == eml ){
中的 eml
中的拼写错误作为变量名称...也是为了获取订单ID WC_Order
对象应使用 $order->get_id()
方法而不是$order->id
。
以下是这个新的功能代码:
add_action( 'woocommerce_order_actions', 'ulmh_resend1' );
function ulmh_resend1( $actions ) {
$actions['ulmh_resend'] = __( 'Resend Email', 'text_domain' );
return $actions;
}
add_action( 'woocommerce_order_action_ulmh_resend', 'ulmh_resend2' );
function ulmh_resend2( $order ) {
$wc_emails = WC()->mailer()->get_emails();
if( empty( $wc_emails ) ) return;
if ($order->has_status( 'on-hold' ))
$email_id = 'customer_on_hold_order';
elseif ($order->has_status( 'processing' ))
$email_id = 'customer_processing_order';
elseif ($order->has_status( 'completed' ))
$email_id = 'customer_completed_order';
else
$email_id = "nothing";
foreach ( $wc_emails as $wc_mail )
if ( $wc_mail->id == $email_id )
$wc_mail->trigger( $order->get_id() );
}
add_filter( 'woocommerce_resend_order_emails_available', 'ulmh_resend3' );
function ulmh_resend3( $order_emails ) {
$remove = array( 'new_order', 'cancelled_order', 'customer_processing_order', 'customer_completed_order', 'customer_invoice' );
$order_emails = array_diff( $order_emails, $remove );
return $order_emails;
}
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中。
此代码在WooCommerce 3+中进行测试,现在可以正常处理暂停订单状态电子邮件通知,重新发送时