成功付款后,在Woocommerce中触发了什么挂钩 [英] After a successful payment, What hook is triggered in Woocommerce

查看:325
本文介绍了成功付款后,在Woocommerce中触发了什么挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Woocommerce中,要将短信付款信息发送给客户,我需要在成功付款后激活触发器.

In Woocommerce, to send sms payment information to the customer, I need to activate a trigger after a successful payment.

但是我没有发现任何钩子

But I didn't find any hook do it

这是我的插件代码:

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();
}

所需的钩子应该在我的代码的第二行.

The desired hook should come in line two of my code.

任何帮助将不胜感激.

推荐答案

您应该尝试使用 woocommerce_payment_complete 操作挂钩,该挂钩是专门为此创建的,位于

You should try to use woocommerce_payment_complete action hook that is just made specifically for that and located in WC_Order payment_completed() method. It's triggered jus after a successful payment. So try:

if ( isset( $this->options['wc_notify_customer_payment_successful_enable'] ) ) {
    add_action( 'woocommerce_payment_complete', array( &$this, 'successful_payment_notification_client' ) );
}

您还应该尝试将array( &$this,替换为array( $this,.

或使用 woocommerce_payment_complete_order_status_processing 钩子:

Or using woocommerce_payment_complete_order_status_processing hook:

if ( isset( $this->options['wc_notify_customer_payment_successful_enable'] ) ) {
    add_action( 'woocommerce_payment_complete_order_status_processing', array( &$this, 'successful_payment_notification_client' ) );
}

您还应该尝试将array( &$this,替换为array( $this,.

或使用woocommerce_order_status_processing钩子(但带有2个参数:$order_id$order):

or using woocommerce_order_status_processing hook (but with 2 arguments: $order_id and $order):

if ( isset( $this->options['wc_notify_customer_payment_successful_enable'] ) ) {
    add_action( 'woocommerce_order_status_processing', array( &$this, 'successful_payment_notification_client' ) );
}

您还应该尝试将array( &$this,替换为array( $this,.

代码在您的插件文件中...

Code goes in your plugin file…

如果没有构造函数(如类)或实例化对象,则应使用add()动作函数:

 add_action( 'the_hook', 'the_hooked_function', $priority, $nb_of_args );

这篇关于成功付款后,在Woocommerce中触发了什么挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆