Use GET variables to display a custom WooCommerce login error message

Use GET variables to display a custom WooCommerce login error message

I love the Basel theme (not sponsored). I’ve used it for several recent projects. It’s well written, easy to customize, always looks good, and is suitable for basically any website, particularly shop sites. If I ever find any time I’ll probably convert Spunmonkey.com over to Basel.

One problem a client brought to my attention is when the user passes incorrect login credentials they are redirected back to the login page but don’t receive any error message. I looked through the theme files and I don’t see any customization happening for this error. There is a custom template for the login page, but nothing out of the ordinary. The page also passes a GET variable after the login attempt, /?login=failed . This is our hook (in the facetious sense, not the wordpress sense) to be able to display a custom error message. Here’s the code.

add_action( 'woocommerce_init', 'sm_login_custom_notice' );

function sm_login_custom_notice() {
	if($_REQUEST['login'] == 'failed' ) {
	wc_add_notice( 'Incorrect username or password.', 'error' );
			}
        }
No Comments

Sorry, the comment form is closed at this time.