Skip to content

Instantly share code, notes, and snippets.

@softiconic
Created April 14, 2024 08:59
Show Gist options
  • Save softiconic/20383b0a4af900cda4d2c9f82854e387 to your computer and use it in GitHub Desktop.
Save softiconic/20383b0a4af900cda4d2c9f82854e387 to your computer and use it in GitHub Desktop.
Custom redirect to a thank you page after a customer creates an account on Shopify
Navigate to your Shopify Admin dashboard.
Go to Online Store > Themes.
Click on Actions > Edit code for the theme you are currently using.
In the Sections folder, locate or create a file named register.liquid.
Add the following code to the register.liquid file:
<script>
document.addEventListener("DOMContentLoaded", function() {
document.querySelector('#create_customer').addEventListener('submit', function(event) {
var form = this;
var formData = new FormData(form);
// Send a request to Shopify's customer creation endpoint
fetch('/account', {
method: 'POST',
body: formData
})
.then(function(response) {
if (response.ok) {
// Redirect to the thank you page upon successful account creation
window.location.href = '/pages/thank-you'; // Replace '/pages/thank-you' with the URL of your thank you page
} else {
// Handle errors if needed
console.error('Failed to create customer account');
}
})
.catch(function(error) {
console.error('Error:', error);
});
// Prevent the form from submitting normally
event.preventDefault();
});
});
</script>
Replace '/pages/thank-you' with the actual URL of your thank you page.
Save the changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment