php - 支付成功后,Woocommerce 中触发了什么钩子(Hook)

标签 php wordpress woocommerce payment hook-woocommerce

在 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, by array( $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, by array( $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, by array( $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/

相关文章:

PHP MySQL OUTFILE 命令

php - Laravel 8 - 设置 cookie 响应不起作用

wordpress - 可捕获的 fatal error : Object of class WP_User could not be converted to string in/directory/on line 139

wordpress - 覆盖 wordpress 插件的 iframe 固定大小 iz 简码

wordpress - Woocommerce 通过产品 ID 获取图片库

php - 我如何在 PHP 中使用 FundAmerica RESTful API?

mysql - Wordpress Ajax 向 MySQL 插入数据

wordpress - WooCommerce - 标准支付需要通过 Paypal AppID

php - 禁用 woocommerce_checkout_update_customer_data

php - 通过 jquery 传递搜索参数