1

I am trying to send a XML-mail to a stock when a purchase is completed in Woocommerce.

I've read about adding an action to: woocommerce_payment_complete in this thread.

The basic code is here and is almost working as it should.

add_action( 'woocommerce_payment_complete', 'it_mail_to_dafolo' );

function it_mail_to_dafolo( $order_id ){

    $to = 'some_mail@gmail.com';
    $subject = 'test';
    $message = '<Ordre>';
    $message .= '</Ordre>';

    wp_mail( $to, $subject, $message );

    var_dump("Hello?");

}

But: Nothing is showed by the var_dump("Hello?")

My problem is: I want to add product attributes and different data to the mail, and this is something with a lot of debugging and testing.

I've started, but the workflow of testing a purchase and checking your mail every time you want to check if something was done correct is terrifying.

What i have tried:

I've tested the amazing plugin: Debug Toolkit and some others, but none of them are working with this hook. They are working other places in my function.php and on my site perfectly.

Also: i've tried with different payment solution, and the problem is, that i have to 'complete a purchase', so i can't debug with the paying solution like bank transfer. Then the function is not called. So i have to set up a test pay like Bambora - (a danish plugin like Stripe). There is a lot of redirections going on, as you all may know. Maybe it has something to do with that.

I've also read about die() and tried with that after var_dump(), to exits the program’s execution, but still nothing.

I've found that you can export to your error_log from this thread - but is it really the best WordPress has to offer?

How can i create a workflow where i can check the variables and errors of this custom action in a better way than exporting it to an error_log?

1 Answers1

1

Woocommerce submits an order through jQuery ajax. You need to add the die(), and then catch the result in the return of the ajax call (in the submit function). It can be found on the following file:

/woocommerce/assets/js/frontend/checkout.js.

Add the breakpoint on the following line:

return raw_response;

To unminify the woocommerce javascript files (for debugging purposes), add this to your wp-config file:

define( 'SCRIPT_DEBUG', true );

Adina E
  • 141
  • 6