## php – wc_add_notice not working on cart page

Question

Does anyone know how to stop the transition to the checkout page after one clicks “proceed to checkout” on the cart page? I performed a validation on the checkout page that worked perfectly with wc_add_notice(“Some message here”). However, when I try to do the same proccess on the cart page, I am taken to the checkout page with the error message. I even tried redirecting users with the header(), but still get taken to the checkout page regardless.

Here is my code:

add_action('woocommerce_proceed_to_checkout', 'username_check');

if ( ! $_POST['username_value'] ) { wc_add_notice( __( 'Enter your correct username' ), 'error' ); } if ( !$_POST['password_value'] ) {