Redirect after customer registration

Michael_Morales
Shopify Expert
195 0 23

I am looking to redirect customers to a specific page after they create an account on the store. Here's the code from customers/register.liquid : 

<div id="customer">
      <!-- Create Customer -->
      <div id="create-customer">

        {% form 'create_customer' %}
          {{ form.errors | default_errors }}

          <div id="first_name" class="clearfix large_form">
            <label for="first_name" class="login">{{ 'customer.register.first_name' | t }}</label>
            <input type="text" value="" name="customer[first_name]" id="first_name" class="large" size="30" />
          </div>

          <div id="last_name" class="clearfix large_form">
            <label for="last_name" class="login">{{ 'customer.register.last_name' | t }}</label>
            <input type="text" value="" name="customer[last_name]" id="last_name" class="large" size="30" />
          </div>

          <div id="email" class="clearfix large_form">
            <label for="email" class="login">{{ 'customer.register.email' | t }}</label>
            <input type="email" value="" name="customer[email]" id="email" class="large" size="30" />
          </div>

          <div id="password" class="clearfix large_form">
            <label for="password" class="login">{{ 'customer.register.password' | t }}</label>
            <input type="password" value="" name="customer[password]" id="password" class="large password" size="30" />
          </div>

          <p class="action_bottom">
            <input class="btn action_button" type="submit" value="{{ 'customer.register.sign_up' | t }}" />
            <span class="note">{{ 'customer.register.or' | t }} <a href="{{ shop.url }}">{{ 'customer.register.cancel' | t }}</a></span>
          </p>

        {% endform %}
      </div><!-- /#create-customer -->
    </div>

I looked at this doc, but it didn't work...

Any suggestions? 

Maukau - Shopify Experts in Paris, France
Dr__Pummel
New Member
1 0 0

I did this by adding the following after  {% form 'customer_login' %}

<input type="hidden" name="checkout_url" id="redirect_url" value="" />
      <script>
      $(document).ready(function() {
           var url =  document.referrer;
          $("#redirect_url").val(url);
        });
      </script>

0 Likes
Lowry
New Member
1 0 1

checkout_url works with customer login, but not works with customer register.

Noah_Jeffrey
Shopify Partner
14 0 3

Is there an alternative to checkout_url that would work with the customer registration form?

0 Likes
HandHugs
Shopify Expert
172 1 46

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;
}); 
});
Noah_Jeffrey
Shopify Partner
14 0 3

Thanks HandHugs! I ended up using this to redirect the customer back to the product page once they login/register from the product page:

 

<input type="hidden" name="checkout_url" value="{{product.url}}" />

 

0 Likes
HandHugs
Shopify Expert
172 1 46

For sure - that will work on the login  page, but will fail on the registration template - not sure about a page that has both forms on it. The code I posted will work as a workaround for the same function on a REGISTRATION form.

mstiv
Shopify Partner
5 0 0

Hey HandHugs,

Can you provide some more information regarding your script? I tried adding it in script tags on the account.register template but when I test creating an account and hit "Create" nothing happens.

0 Likes
mstiv
Shopify Partner
5 0 0

Update on this. When using this script, I noticed that due to Shopify enforcing the recapta page after more than 1 login attempt from the same IP address, this causes the form to go nowhere. Not good for testing. When you do create an account for the first time, this script works! Does anyone have any ideas on how to update the script to avoid nothing happening if they have attempted to create an account more than once from the same IP address? I doubt this will happen a lot but would create a bad user experience. 

0 Likes
HandHugs
Shopify Expert
172 1 46

You can either change the error script in the code so that it displays a message telling them to wait a few days or you can contact shopify support and have them turn off the spam filter. They don’t recommend it but I did it for testing.