支付成功后,Woocommerce 中会触发什么 hook

Mil*_*imi 5 php wordpress payment woocommerce 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();
}
Run Code Online (Sandbox Code Playgroud)

所需的挂钩应该位于我的代码的第二行。

任何帮助将不胜感激。

Loi*_*tec 4

您应该尝试使用woocommerce_payment_complete专门为此制作并位于WC_Order payment_completed()method中的操作钩子。付款成功后立即触发。所以尝试:

\n
if ( isset( $this->options[\'wc_notify_customer_payment_successful_enable\'] ) ) {\n    add_action( \'woocommerce_payment_complete\', array( &$this, \'successful_payment_notification_client\' ) );\n}\n
Run Code Online (Sandbox Code Playgroud)\n
\n

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

\n
\n

或者使用woocommerce_payment_complete_order_status_processing钩子:

\n
if ( isset( $this->options[\'wc_notify_customer_payment_successful_enable\'] ) ) {\n    add_action( \'woocommerce_payment_complete_order_status_processing\', array( &$this, \'successful_payment_notification_client\' ) );\n}\n
Run Code Online (Sandbox Code Playgroud)\n
\n

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

\n
\n

或使用woocommerce_order_status_processinghook (但有 2 个参数:$order_id$order

\n
if ( isset( $this->options[\'wc_notify_customer_payment_successful_enable\'] ) ) {\n    add_action( \'woocommerce_order_status_processing\', array( &$this, \'successful_payment_notification_client\' ) );\n}\n
Run Code Online (Sandbox Code Playgroud)\n
\n

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

\n
\n

代码位于您的插件文件\xe2\x80\xa6中

\n
\n
\n

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

\n
 add_action( \'the_hook\', \'the_hooked_function\', $priority, $nb_of_args );\n
Run Code Online (Sandbox Code Playgroud)\n
\n