默认的订单action动作中有三个,如黄框中所示。
但是,我想添加一个其他操作,比如把订单同步到其他平台,或者是发送一个自定义的邮件内容,我们可以这么做,我这里以只发送订单信息为例子:
1、添加action动作,并发送invoice邮件:
//后台添加action
add_filter( 'woocommerce_order_actions','woocommerce_order_actions_function',10,2);
function woocommerce_order_actions_function($actions, $order){
$actions['send_order_details_customer'] = __( '只发送订单详情邮件给用户', 'woocommerce' );
return $actions;
}
//添加只发送订单详情给用户,并在customer-invoice.php中修改,具体查看文件中send_order_details_customer判断
add_action('woocommerce_order_action_send_order_details_customer','woocommerce_order_action_send_order_details_customer_function',10,1);
function woocommerce_order_action_send_order_details_customer_function($order){
// Send the customer invoice email.
WC()->payment_gateways();
WC()->shipping();
WC()->mailer()->customer_invoice( $order );
}
2、对invoice邮件进行编辑(/woocommerce/emails/customer-invoice.php):
<?php $action = wc_clean( wp_unslash( $_POST['wc_order_action'] ) );
if($action != "send_order_details_customer"){
//action的内容
}else{
//原来的内容
}
© 版权声明
THE END