1
votes

I am integrating WooCommerce with a third party inventory API. When the Place Order button is clicked, I hook into the woocommerce_review_order_before_submit hook.

Here I grab the SKU's of all the products in the cart and send them to the API for a quick inventory check. This is all working.

If the remote system returns that not enough inventory is present for any of the SKU's we need to stop the purchase.

Is there a way to stop processing the order from the woocommerce_review_order_before_submit hook?

If not what is the proper way to handle this scenario in WooCommerce?

Thanks

1

1 Answers

1
votes

based on the result of an API
There is a way to stop processing the order!

if($apiError){
    wc_add_notice( __( 'Error in API! Order Not placed' ), 'error' );
    wp_safe_redirect( wc_get_page_permalink( 'cart' ) );
} else {
    //place order
}