Redirect after customer registration

Anonymous
Not applicable
0 0 54

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
 }
}
});
3 Likes
New Member
1 0 0

Is it not possible to handle the recaptcha? Is it possible to allow the Recaptcha and then do the redirection in it's success?? 

0 Likes
New Member
1 0 0

@HandHugs wrote:

Place this in script tags at the bottom of your registration form liquid page

It's the only way that shopify allows it.

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

Thanks, 

0 Likes
Excursionist
29 0 5

Any idea why I may be having an issue with regard to it reporting errors?  I have this tag directly below  {% form 'create_customer' %} in my register.liquid file.

{{ form.errors | default_errors }}

I see it returning the error in the console but the actual message never pops. 


Is it incumbent upon us who take this approach to render our own <div class="errors"></div> container for the script to toss errors into then?  

 

0 Likes
Highlighted
Shopify Partner
9 0 1

I think "Anonymous" at the top of the page offered the best solution so far. My only issue is that, if a user already has an account and tries to create an account with the same email address, the redirect occurs before the error message can be thrown. 

0 Likes