Redirecting New Customers After Registration

New Member
1 0 1

Hello! By default (or at least I think it's default) new and returning customers are directed to the "account" page after logging in. I want to redirect them to the "cart" page. I was able to do this and it worked perfectly for returning customers by adding the below code to the login.liquid:  


				{% form 'customer_login' %}
              <input type="hidden" name="checkout_url" value="/cart" />

 

I tried adding the same code to register.liquid under {% form 'create_customer' %} with no luck. 

I also tried to add the following code to activate_account.liquid with no luck either:

 

  {% form 'activate_customer_password' %}
  <input type="hidden" name="return_to" value="/cart" />
  

 

Does anyone know how to redirect new customers after registration to the cart page rather than the account page? Thank you!

1 Like
Shopify Expert
103 0 21

Place this in script tags at the bottom of your registration liquid template. It's not a great way, but it's the only way i know of that works.

 

jQuery(function() {
jQuery('#create_customer').submit(function(event) {
  event.preventDefault();
  var data = jQuery(this).serialize();

 //create new account
  jQuery.post('/account', data)
    .done(function(data){
    var logErrors = jQuery(data).find('.errors').text();

    //if there are errors show them in the html form
    if (logErrors != "" && logErrors != 'undefined'){
        jQuery('#create_customer .errors').html(logErrors);
        jQuery('#create_customer .errors').show();

    //if account creation is successful show checkout page
    }else{
       console.log('success');
      document.location.href = '/checkout';
    }
    }).fail(function(){console.log('error');});
   return false;
}); 
});
0 Likes
New Member
4 0 0

Hi, here is my solution. Redirect user to current product page after registration. (works with captcha too);

$(document).ready(function(){
  if($('#shopify-section-product-template').length > 0){//if product page
    localStorage.setItem('product-url', window.location.pathname);//set product url ot local storage
  }else{
    if($('#CustomerLoginForm').length){//shkip if login page
    }else if($('#RegisterForm').length > 0){//if registration page
      if(localStorage.getItem('product-url')){//if local storage has product url

        // !!! paste (<input type="hidden" name="return_to" value="" />) to templates/customers/register.liquid file inside form
        $('#RegisterForm [name="return_to"]').val(localStorage.getItem('product-url'));//set product url to return_to input 

      }
    }else if($('#g-recaptcha').length){//if captcha
     if(localStorage.getItem('product-url')){
      var $newInput = $('<input type="hidden" name="return_to" value="'+localStorage.getItem('product-url')+'" />');
      $newInput.insertBefore($('.shopify-challenge__container input[type="submit"]'));
    }

  }else{
   localStorage.removeItem('product-url');//else remove product url from local storage
 }
}
});
Shopify dev.
cocolocomococo@gmail.com
0 Likes
New Member
2 0 0

Hi, where do you paste this code as I'm really keen to use it.

 

Many thanks!

0 Likes
Shopify Partner
8 0 0

Mate it is not working , can you recheck?

0 Likes