0
votes

Our payment gateway and CRM and not supported by WooCommerce by default as a plugin, so I need to add custom code that sends data to our CRM and payment gateway whenever a customer places an order, then reject or accept the order depending on the payment gateway API response.

Where and how in the Woo code should I be intercepting the order submission?

1

1 Answers

0
votes

You should try woocommerce_checkout_process action hook where the billing provider's API response, should return an error notice to reject and stop the checkout process…

This hook is located in WC_Checkout process_checkout() method and it's before the order creation. The data is accessible through $_POST or through $posted_data = WC()->checkout->get_posted_data(); WC_Checkout method.

Or woocommerce_checkout_order_processed action hook where the order is already created (meaning that the order data is accessible through 3 arguments: $order_id, $posted_data and $order) but before payment… To stop the process the billing provider's API response should: throw new Exception()

So anyway the solution is one of the WC_Checkout available hooks…