Saturday, April 25, 2015

Easily Redirect WooCommerce User After Login

Via:MyTutorialGuru.com

In WooCommerce shop by default user is been redirected to my account page after they login to their account. but you can easily change this by adding a simple function in your theme function. We have done this recently for one of our cients. Lets see the code snippet.


Following code snippet will redirect your customer to shop page after they login. Add this in your themes functions.php


add_filter('woocommerce_login_redirect', 'ras_login_redirect');

function ras_login_redirect( $redirect_to )

$redirect_to = 'http://www.example.com/shop/';

return $redirect_to;


We have added a static URL. If you want dynamic home URL then add code as follows:


add_filter('woocommerce_login_redirect', 'ras_login_redirect');

function ras_login_redirect( $redirect_to )

$redirect_to = home_url()."/shop/";

return $redirect_to;


You can practically redirect to any URL you want. For example you might want them to redirect them to home page then add the following code:


add_filter('woocommerce_login_redirect', 'ras_login_redirect');

function ras_login_redirect( $redirect_to )

$redirect_to = home_url();

return $redirect_to;


Or you can use unique page ID rather than static URL. Get the page ID from admin and use as follows:


add_filter('woocommerce_login_redirect', 'ras_login_redirect');

function ras_login_redirect( $redirect_to )

$redirect_to = get_permalink( 1066 );

return $redirect_to;


If you have a private shop and want only registered user have access to the shop then you might want to keep the shop page private and force them to login. See How to redirect WooCommerce User to Login Page.

No comments:

Post a Comment