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/

相关文章:

javascript - 在Divi Wordpress中随机播放幻灯片

javascript - WooCommerce-在选择以上一项之前,如何禁用属性选项菜单?

php - 在 Woocommerce 中隐藏一些结帐字段问题

php - .htpasswd 添加/删除/更新用户名和密码 - php windows

php - 如何在PHP中使用内部类?

php - 计算左联接的结果?

css - Wordpress HTML 代码标签无响应

php - Woocommerce 在结帐页面中显示运输方式?

php - 如何消除 WooCommerce Shop 中产品类别之间的差距?

php - 在同一表上同时更新和选择