• Resolved Peter Westerlund

    (@peter-westerlund)


    When a payment is complete this function is called.

    …it says above the function payment_complete() in class-wc-order.php that is called in WooCommerce when an order has been created and it’s checking if payment is completed so that the status of the order can be changed to completed and stock be reduced.

    It ends with either a 'woocommerce_payment_complete' hook or a 'woocommerce_payment_complete_order_status_[get-status] hook.

    I wanna know if it hooks. And print out variables in it. But it doesn’t work. The page doesn’t die when I’m making a test purchase and I’ve set print_r($order) followed by a die(); in the function I created to call to from those hooks.

    I am sure they are they are both set properly since I’ve checked by running this code right after:

    global $wp_filter
    echo '<pre>'.print_r($wp_filter, true).'</pre>'; exit;

    And they do exist there in the $wp_filter array.

    I have also tried to send me an email instead of trying to print print_r($order). But that doesn’t work either:

    function my_custom_payment_completed($order_id)
    {
    $order = wc_get_order( $order_id );
        
        if ( ! $order ) {
            return;
        }
        
    $to_email = 'my@mailaddress.com';
    $from     = get_option('woocommerce_email_from_name').' <'.sanitize_email(get_option('woocommerce_email_from_address')).'>';
    $headers  = 'Content-type: text/html;charset=utf-8' . "\r\n";
    $headers .= 'From: '.$from;
    wp_mail($to_email, 'Test', '<pre>'.print_r($order, true).'</pre>', $headers );
    }
    add_action( 'woocommerce_payment_complete', 'my_custom_payment_completed', 10, 1 );
    add_action( 'woocommerce_payment_complete_order_status_completed', 'my_custom_payment_completed', 10, 1 );
    ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WC hook ‘woocommerce_payment_complete_order_status_completed’ not triggering’ is closed to new replies.