After a successful payment, What hook is triggered in Woocommerce

前端 未结 2 760
花落未央
花落未央 2021-01-22 05:12

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

This

相关标签:
2条回答
  • 2021-01-22 05:37
     add_action('woocommerce_payment_complete','this_is_custom_function');
     function this_is_custom_function($order_id){
            $order = new WC_Order( $order_id );
     }
    

    use "woocommerce_payment_complete" hook

    0 讨论(0)
  • 2021-01-22 05:38

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

    You should try also to replace array( &$this, by array( $this, instead.

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

    You should try also to replace array( &$this, by array( $this, instead.

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

    You should try also to replace array( &$this, by array( $this, instead.

    Code goes in your plugin file…


    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 );
    
    0 讨论(0)
提交回复
热议问题