付款成功后,Woocommerce会触发什么钩子

时间:2018-01-26 15:32:52

标签: php wordpress woocommerce payment hook-woocommerce

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

但我没有发现任何钩子

这是我的插件代码:

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

所需的钩子应该是我的代码的第二行。

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

您应该尝试使用 woocommerce_payment_complete 操作挂钩,该挂钩只是专门为此设置的佣人,位于WC_Order payment_completed() method。它在成功付款后触发了jus。所以试试:

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

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

代码放在你的插件文件中......

  

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

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

答案 1 :(得分:0)

 add_action('woocommerce_payment_complete','this_is_custom_function');
 function this_is_custom_function($order_id){
        $order = new WC_Order( $order_id );
 }

使用“ woocommerce_payment_complete”挂钩