WooCommerce: Redirect Users to Shop Page After Login

Guide your users to a seamless shopping experience by redirecting them to the shop page immediately after logging in on your WooCommerce website. This simple customization ensures that users can swiftly resume browsing and exploring your product offerings upon completing the login process. In this tutorial, we’ll walk through the steps to modify the redirect URL of the login button, directing users to the shop page upon successful login.

/**
* Snippet Name:  Change redirect URL of login button to shop page
* Snippet Author:  wpsnippets.dev
*/
// Change redirect URL of login button to shop page
function wps_custom_login_redirect( $redirect_to, $user ) {
    // Redirect to the shop page URL
    $redirect_to = get_permalink( wc_get_page_id( 'shop' ) );
    return $redirect_to;
}
add_filter( 'woocommerce_login_redirect', 'wps_custom_login_redirect', 10, 2 );  

Code Explanation

  • This code snippet modifies the default redirect behavior of the WooCommerce login process by changing the destination URL to the shop page. The woocommerce_login_redirect filter hook is utilized to intercept the redirect URL before it is applied, allowing us to replace it with a custom URL.
  • The $redirect_to parameter represents the original redirect destination, while the $user parameter contains information about the logged-in user (if applicable). In this snippet, we set the $redirect_to variable to the permalink of the shop page using the wc_get_page_id('shop') function.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top