woocommerce_thankyou被叫4次

We are using woocommerce_thankyou to execute an action on checkout. However, in a simple test, if I set the action and just "echo 'Test';" it happens 4 times. This is the code

class OrderController 
{ 
    public function __construct() 
    { 
        add_action('woocommerce_thankyou', array($this, 'orderSubmit')); 
    } 

    function orderSubmit() 
    { 
        global $woocommerce;
        echo "test"; // happens 4 times 
    } 
}

I was experiencing the same issue earlier today.

I went into server file viewer (or local host) and went to wp-content/plugins/woocommerce/templates/checkout

Inside the checkout folder there is a php file called thankyou.php.

Around line 65 or so there will be code that says

<?php do_action( 'woocommerce_thankyou' . $order->payment_method, $order->id ); ?>

Or something similiar

The issue in mine is that it had 2 of these action executions.

Get rid of all them except one and this should fix your problem.

Be sure to test your woocommerce afterwards to ensure you didn't delete the wrong one