Redirect after customer registration

Highlighted
Shopify Partner
16 0 3

This method didn't work for me. 

With the script in place, it actually disabled the form. 

 

Correct me if I'm wrong, but you have to wrap it in a "script" don't you?

 

I used the following: 

 

<script>
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;
}); 
});
</script>
Custom sites and stores by Squareflair.com
0 Likes
Highlighted
Shopify Partner
795 124 397
Use this code. This code is perfect
-put it in theme.liquid above tag.


$(document).ready(function(){
var $returnTo = $('<INPUT type="hidden" name="return_to" value="WHERE_YOU_WANT_TO_REDIRECT" />');

if ($('#create_customer').length &gt; 0){ //if registration form
$returnTo.insertBefore($('#create_customer input[type="submit"]')); // add return_to input
} else if ($('#g-recaptcha').length){ //if captcha form
$returnTo.insertBefore($('.shopify-challenge__container input[type="submit"]'));
}
});

-Give likes :)
0 Likes
Highlighted
Shopify Partner
795 124 397

@Alan_Houser  ,
use this code, this code works fine.

- put this code before </head> tag in Theme.liquid File.
File path: online store->themes->action->edit code->Layouts->theme.liquid

- you need to change some values in below code where i have given Suggestion in capital letters.

<script>
$(document).ready(function(){
var $returnTo = $('<INPUT type="hidden" name="return_to" value="WHERE_YOU_WANT_TO_REDIRECT(PAGE-URL)" />');
if ($('#create_customer').length > 0){ 
   $returnTo.insertBefore($('#create_customer input[type="submit"]')); // add return_to input
} else if ($('#g-recaptcha').length){
   $returnTo.insertBefore($('.shopify-challenge__container input[type="submit"]'));
});
</script>

-Give Likes :)
-Mark this as accepted solution.

Thank You

1 Like
Highlighted
New Member
5 0 0

@candiSoft wrote:

@Alan_Houser  ,
use this code, this code works fine.

- put this code before </head> tag in Theme.liquid File.
File path: online store->themes->action->edit code->Layouts->theme.liquid

- you need to change some values in below code where i have given Suggestion in capital letters.

<script>
$(document).ready(function(){
var $returnTo = $('<INPUT type="hidden" name="return_to" value="WHERE_YOU_WANT_TO_REDIRECT(PAGE-URL)" />');
if ($('#create_customer').length > 0){ 
   $returnTo.insertBefore($('#create_customer input[type="submit"]')); // add return_to input
} else if ($('#g-recaptcha').length){
   $returnTo.insertBefore($('.shopify-challenge__container input[type="submit"]'));
});
</script>

-Give Likes :)
-Mark this as accepted solution.

Thank You


@candiSoft  Just so someone doesn't get frustrated by the above code, there is a syntax err (missing curly brace). I fixed it below for the copy/pasters.

<script>
$(document).ready(function() {
	var $returnTo = $('<INPUT type="hidden" name="return_to" value="WHERE_YOU_WANT_TO_REDIRECT(PAGE-URL)" />');
	if ($('#create_customer').length > 0) {
		$returnTo.insertBefore($('#create_customer input[type="submit"]')); // add return_to input
	} else if ($('#g-recaptcha').length) {
		$returnTo.insertBefore($('.shopify-challenge__container input[type="submit"]'));
	}
});
</script>

This solution does not work for me. I am working on an old shopify store (probably 6-8 years old). I've even tried testing it with a new theme on this shop and every time it redirects me to the checkout. I was trying to redirect to /account/.

0 Likes
Highlighted

We just posted a blog about this topic today.

 

Add the following code near the bottom of layout/theme.liquid, just before </body>. In this example, we will redirect customers to Shopify’s Cart page. To redirect to a different page, simply replace '/checkout' with your desired redirect location:

<script>
  (function() {
    var REDIRECT_PATH = '/checkout';

    var selector = '#create_customer, form[action$="/account"][method="post"]',
        $form = document.querySelectorAll(selector)[0];

    if ($form) {
      $redirect = document.createElement('input');
      $redirect.setAttribute('name', 'return_to');
      $redirect.setAttribute('type', 'hidden');
      $redirect.value = REDIRECT_PATH;
      $form.appendChild($redirect);
    }
  })();
</script>
Michael | Business Development @ Helium
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution
Helium builds apps that merchants depend on:
Customer Fields app (since 2015)
Meteor Mega Menu app (since 2014)
2 Likes
Highlighted
Explorer
56 0 7

Hi @michael-helium thank you for this. I thought I could use your script for redirecting customers to home after they submit a form to reset their password (right now they are taken to the checkout page) 

I tried the following but it doesn't work - do you know what I am doing wrong? Thank you!

<script>
  (function() {
    var REDIRECT_PATH = '/';

    var selector = '#reset_customer_password, form[action$="/account"][method="post"]',
        $form = document.querySelectorAll(selector)[0];

    if ($form) {
      $redirect = document.createElement('input');
      $redirect.setAttribute('name', 'return_to');
      $redirect.setAttribute('type', 'hidden');
      $redirect.value = REDIRECT_PATH;
      $form.appendChild($redirect);
    }
  })();
</script>

 

 

 

0 Likes
Highlighted
New Member
2 0 0

Hello,

 

It shows an error status 429 error.

0 Likes
Highlighted
New Member
1 0 0

@michael-helium 

 

We would only like to redirect customers from a specific sign up page. How would we do this so that only that sign up page redirects a customer to a specific page? Thank you.

0 Likes
Highlighted

@BrilliantOC 

I would highly recommend Customer Fields for your use case. In the app, you can build multiple registration forms and control the redirect settings at the form level, or even use conditional logic to redirect certain users to certain pages.  

Michael | Business Development @ Helium
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution
Helium builds apps that merchants depend on:
Customer Fields app (since 2015)
Meteor Mega Menu app (since 2014)
0 Likes
Highlighted
Tourist
3 1 1

it doesn't work at all

0 Likes