I need to perform additional checks when a user submits an order in WooCommerce. I tried using different add_filter
methods, but I couldn’t hook into a place_order
filter. Can someone help me with this?
Here is the code I’m using to achieve this:
add_action('woocommerce_after_checkout_validation', 'rei_after_checkout_validation');
function rei_after_checkout_validation( $posted ) {
// do all your logics here...
// adding wc_add_notice with a second parameter of "error" will stop the form...
// wc_add_notice( __( "OMG! You're not human!", 'woocommerce' ), 'error' );
if (empty($_POST['captcha'])) {
wc_add_notice( __( "Captcha is empty!", 'woocommerce' ), 'error' );
}
}
This code uses the woocommerce_after_checkout_validation
action to run additional checks after the checkout validation process. If the captcha field is empty, it adds an error notice and prevents the form from submitting.