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');

function username_check() {


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

        }

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

        }
    
}

0
John Lyons 2 months 2022-10-12T13:20:37-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse