Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

woocommerce_thankyou get's called 4 times

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 
    } 
}

1 Answers

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

like image 132
Sam Alexander Avatar answered Dec 08 '25 17:12

Sam Alexander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!