在 Woocommerce 中,要向客户发送短信付款信息,我需要在付款成功后激活触发器。
但我没有找到任何钩子(Hook)
这是我的插件代码:
if ( isset( $this->options['wc_notify_customer_payment_successful_enable'] ) ) {
add_action( '####Action to be used here#######', array( &$this, 'successful_payment_notification_client' ) );
}
/* WooCommerce Successful payment notification client
*
* @param $order_id
*/
public function successful_payment_notification_client ( $order_id ) {
// Check the mobile field is empty
if ( empty( $_REQUEST['mobile'] ) ) {
return;
}
$order = new WC_Order( $order_id );
$this->sms->to = array( $_REQUEST['mobile'] );
$template_vars = array(
'%order_id%' => $order_id,
'%order_number%' => $order->get_order_number(),
'%status%' => $order->get_status(),
'%billing_first_name%' => $_REQUEST['billing_first_name'],
'%billing_last_name%' => $_REQUEST['billing_last_name'],
'%transaction_id%' => get_post_meta( $order_id,'_payment_method_title', true ),
);
$message = str_replace( array_keys( $template_vars ), array_values( $template_vars ), $this->options['wc_notify_customer_payment_successful_message'] );
$this->sms->msg = $message;
$this->sms->SendSMS();
}
所需的钩子(Hook)应该出现在我的代码的第二行。
任何帮助将不胜感激。
最佳答案
您应该尝试使用 woocommerce_payment_complete
专门为此制作的 Action Hook ,位于 WC_Order
payment_completed()
method .付款成功后触发。所以试试:
if ( isset( $this->options['wc_notify_customer_payment_successful_enable'] ) ) {
add_action( 'woocommerce_payment_complete', array( &$this, 'successful_payment_notification_client' ) );
}
You should try also to replace
array( &$this,
byarray( $this,
instead.
或使用
woocommerce_payment_complete_order_status_processing
钩:if ( isset( $this->options['wc_notify_customer_payment_successful_enable'] ) ) {
add_action( 'woocommerce_payment_complete_order_status_processing', array( &$this, 'successful_payment_notification_client' ) );
}
You should try also to replace
array( &$this,
byarray( $this,
instead.
或使用
woocommerce_order_status_processing
钩子(Hook)(但有 2 个参数:$order_id
和 $order
):if ( isset( $this->options['wc_notify_customer_payment_successful_enable'] ) ) {
add_action( 'woocommerce_order_status_processing', array( &$this, 'successful_payment_notification_client' ) );
}
You should try also to replace
array( &$this,
byarray( $this,
instead.
代码进入您的插件文件...
If there is no constructor (like for a class) or no instantiated object, you should use
add()
action function this way:add_action( 'the_hook', 'the_hooked_function', $priority, $nb_of_args );
关于php - 支付成功后,Woocommerce 中触发了什么钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48464499/