收到订单并感谢用户时触发 Woocommerce 挂钩
Woocommerce hook triggered when the order is received and thanks the user
在我的插件中,我想知道如何在用户完成通过电汇支付的订单时“拦截”,因为我需要知道订单金额才能计算其他内容并写入另一个 table.
我以为会是:
add_filter('woocommerce_thankyou_order_received_text', 'fn_payment_complete');
这是正确的方法还是有不同的方法?谢谢!干杯
woocommerce_thankyou_order_received_text 用于返回消息。您仍然可以使用它来访问订单,但我建议改用 woocommerce_thankyou。
使用 woocommerce_thankyou_order_received_text 挂钩
function wired_order_thank_you_msg($msg,$order) {
//$order is object
$payment_method = $order->get_payment_method(); //returns payment method bacs,cheque,cod etc
if($payment_method === 'bacs'):
//Do stuff
$status = $order->get_status();
$order_total = $order->get_formatted_order_total();
//Return custom msg if you want
$msg = array();
$msg[] .= $status;
$msg[] .= __('Custom msg','text');
$msg[] .= $order_total;
return sprintf('%s',implode($msg));
else:
return $msg;
endif;
}
add_action('woocommerce_thankyou_order_received_text','wired_order_thank_you_msg',10,2);
使用 woocommerce_thankyou 挂钩
function wired_order_thank_you($order_id) {
//$order is object
$order = wc_get_order( $order_id );
$payment_method = $order->get_payment_method(); //returns payment method bacs,cheque,cod etc
if($payment_method === 'bacs'):
//Do stuff
$order_total = $order->get_formatted_order_total();
endif;
}
add_action('woocommerce_thankyou','wired_order_thank_you',10,1);
在我的插件中,我想知道如何在用户完成通过电汇支付的订单时“拦截”,因为我需要知道订单金额才能计算其他内容并写入另一个 table. 我以为会是:
add_filter('woocommerce_thankyou_order_received_text', 'fn_payment_complete');
这是正确的方法还是有不同的方法?谢谢!干杯
woocommerce_thankyou_order_received_text 用于返回消息。您仍然可以使用它来访问订单,但我建议改用 woocommerce_thankyou。
使用 woocommerce_thankyou_order_received_text 挂钩
function wired_order_thank_you_msg($msg,$order) {
//$order is object
$payment_method = $order->get_payment_method(); //returns payment method bacs,cheque,cod etc
if($payment_method === 'bacs'):
//Do stuff
$status = $order->get_status();
$order_total = $order->get_formatted_order_total();
//Return custom msg if you want
$msg = array();
$msg[] .= $status;
$msg[] .= __('Custom msg','text');
$msg[] .= $order_total;
return sprintf('%s',implode($msg));
else:
return $msg;
endif;
}
add_action('woocommerce_thankyou_order_received_text','wired_order_thank_you_msg',10,2);
使用 woocommerce_thankyou 挂钩
function wired_order_thank_you($order_id) {
//$order is object
$order = wc_get_order( $order_id );
$payment_method = $order->get_payment_method(); //returns payment method bacs,cheque,cod etc
if($payment_method === 'bacs'):
//Do stuff
$order_total = $order->get_formatted_order_total();
endif;
}
add_action('woocommerce_thankyou','wired_order_thank_you',10,1);