Shopify themes, liquid, logos, and UX
You can add an I agree with the terms and conditions checkbox to your cart page that customers must check before continuing to the checkout. If a customer doesn't check the checkbox before clicking the checkout button, an alert pop up will prevent them from continuing.
Tip: It's not possible to add the checkbox to the checkout pages. It can be added only to the cart page that exists at http://www.your-shop-URL.com/cart.
The steps for this tutorial differ depending on whether you are using a sectioned or a non-sectioned theme. A sectioned theme is a newer theme that lets you drag and drop to arrange the layout of your store's pages.
To figure out whether your theme supports sections, go to the theme's Edit code page. If there are files in the Sections directory, you are using a sectioned theme. Non-sectioned themes were released before October 2016, and do not have files in the Sections directory.
If you are using a sectioned theme, then click the Sectioned themes button and follow the instructions. If you are using an older, non-sectioned theme, then click the Non-sectioned themes button and follow the instructions.
TyW | Online Community Manager @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Thank you so so much!!! This mini tutorial is so incredibly helpful and it worked like a charm! Thank you very much for providing this for all of us ♥︎
I added the codes to my my Dawn Theme and able to see the terms and conditions box, but it is not alligned properly, how to allign it? Also the Check out Box became more height
Please help me
Hi everyone,
The question above is kind of old but in case someone comes across this same issue, I'm also using the Dawn theme, I solved it by placing the code that goes in the main-cart-footer.liquid just at the end of the section that begins with <small class="tax-note caption-large rte">, as follows:
And the checkbox looks like this:
Mike
id="agree" />
I agree with the terms
and conditions.
Hi Rasmus,
Yes, I added the code just before the </div> tag, as you can see below I placed it several lines before the line
<button type="submit" id="checkout" class="cart__checkout-button button"...
as follows:
Other suggestions I took to deal with the issue that it was possible to click on the Checkout button even if the checkbox was not selected were the following:
- Create custom.js in Assets and put in there the code that was supposed to go in theme.js or theme.js.liquid.
- Add the following in theme.liquid just before the </head> tag :
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
{{ 'custom.js' | asset_url | script_tag }}
After those changes it look like this in my case:
I hope it helps,
Mike
Hi,
I'm using the Dawn theme. I've added every piece of code and I'm seeing the accept terms and conditions checkbox. However I still can go to checkout without checking the box.
Hi Frank,
I also had that the same issue as you while implementing the proposed solution, I solved it by following the advice about putting the code in a new file called custom.json and Assests and adding the following in theme.liquid just before the </head> tag :
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
{{ 'custom.js' | asset_url | script_tag }}
I hope it helps,
Mike
thank you for this helpful tutorial, saved me some money 🙂
Thanks! This worked great in my debut theme but I'm having an issue with adding it to the line above the checkout button. I tried adding a <p> and a <br> right before the input tag but it doesn't seem to be working.
<p style="float: none; text-align: right; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align: middle;" type="checkbox" id="agree" />
<label style="display:inline; float:none" for="agree">
I agree with the <a href="/pages/terms-and-conditions">terms and conditions. </a>
<br>
<p></p>
</label>
<input type="submit" name="checkout"
class="cart__submit btn btn--small-wide"
value="{{ 'cart.general.checkout' | t }}">
</div>
Did you find the solution to this problem? Would love to know if you have.
Hello, this tutorial is really helpful and I manage to add a required checkbox on my cart page.
However, the "required" field doesn't prevent the customer to proceed with checkout through the additional checkout buttons (Google Pay, Apple Pay etc). Is there any way to block the user to compile required fields before heading to the quick checkout experience?
Thanks in advance
EDIT: I was able, in the meantime, to disable the buttons until the checkbox is selected:
theme.js
$("#additional-buttons-c").addClass("div-disabled"); $(document).ready(function() { $('body').on('click', '[name="agree"]', function() { if ($('#agree').is(':checked')) { $("#additional-buttons-c").removeClass("div-disabled"); } else { $("#additional-buttons-c").addClass("div-disabled"); } }); });
theme.scss.liquid:
.div-disabled { pointer-events: none; opacity: 0.4; }
cart template:
{%- if additional_checkout_buttons -%} <div id="additional-buttons-c" class="additional-checkout-buttons">{{ content_for_additional_checkout_buttons }}</div> {%- endif -%}
Hey thanks for the update Gab,
any chance you could send a screenshot of what it would look like incorporated into your code?
Thanks in Advance
@gab33 wrote:Hello, this tutorial is really helpful and I manage to add a required checkbox on my cart page.
However, the "required" field doesn't prevent the customer to proceed with checkout through the additional checkout buttons (Google Pay, Apple Pay etc). Is there any way to block the user to compile required fields before heading to the quick checkout experience?
Thanks in advance
EDIT: I was able, in the meantime, to disable the buttons until the checkbox is selected:
theme.js
$("#additional-buttons-c").addClass("div-disabled"); $(document).ready(function() { $('body').on('click', '[name="agree"]', function() { if ($('#agree').is(':checked')) { $("#additional-buttons-c").removeClass("div-disabled"); } else { $("#additional-buttons-c").addClass("div-disabled"); } }); });theme.scss.liquid:
.div-disabled { pointer-events: none; opacity: 0.4; }cart template:
{%- if additional_checkout_buttons -%} <div id="additional-buttons-c" class="additional-checkout-buttons">{{ content_for_additional_checkout_buttons }}</div> {%- endif -%}
The complete code is already pasted above.
Best regards
Does it matter where in the code your code is placed or can we just put it down on the bottom of the page?
hi there,
could you find a solution for the error in the "required" portion,i am still unable to find the perfect solution for this. Easily can be bypassed without giving tick mark in the check box.
Can you help me?
Hi,
Thanks a lot..i got the solution.....
Which expert to recommend please? i need it
@GARESIOVINI wrote:
Hello,
I've contacted for 25 dollars a shopify expert that worked on the code and
did a perfect job.
In just one day everything was working well. Honestly I'd advice this.
Best,
Which expert to recommend please? i need it
hi there,
could you find a solution for the error in the "required" portion,i am still unable to find the perfect solution for this. Easily can be bypassed without giving tick mark in the check box.
Can you help me?
Hi @gab33
Your function to disable the pay buttons like Google and Apple pay is extremely helpful, so thank you!
However, I do have a small issue. I copied your code exactly into my template (I am using the theme Debut), but the pay buttons stay greyed out and unclickable even after selecting the checkbox.
What am I doing wrong?
Cart-template.liquid:
<input type="submit" name="checkout"
class="cart__submit btn btn--small-wide"
value="{{ 'cart.general.checkout' | t }}">
</div>
<p style="float: none; text-align: right; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align: middle;" type="checkbox" id="agree" />
<label style="display:inline; float:none" for="agree">
Ik ga akkoord met de <a href="/policies/terms-of-service"><strong>algemene voorwaarden</strong></a>.
</label>
</p>
<div class="cart__error-message-wrapper hide" role="alert" data-cart-error-message-wrapper>
<span class="visually-hidden">{{ 'general.accessibility.error' | t }} </span>
{% include 'icon-error' %}
<span class="cart__error-message" data-cart-error-message></span>
</div>
{%- if additional_checkout_buttons -%}
<div id="additional-buttons-c" class="additional-checkout-buttons">{{ content_for_additional_checkout_buttons }}</div>
{%- endif -%}
</div>
</div>
</div>
</div>
theme.scss.liquid:
}
.div-disabled {
pointer-events: none;
opacity: 0.4;
}
theme.js:
}
$("#additional-buttons-c").addClass("div-disabled");
$(document).ready(function() {
$('body').on('click', '[name="agree"]', function() {
if ($('#agree').is(':checked')) {
$("#additional-buttons-c").removeClass("div-disabled");
}
else {
$("#additional-buttons-c").addClass("div-disabled");
}
});
});
$(theme.init);
$(document).ready(function() {
$('body').on('click', '[name="checkout"], [name="goto_pp"], [name="goto_gc"]', function() {
if ($('#agree').is(':checked')) {
$(this).submit();
}
else {
alert("Om de bestelling te kunnen plaatsen dien je akkoord te gaan met de algemene voorwaarden");
return false;
}
});
});
Hello,
I have the same issue. Were you able to fix it?
Thank you
Hi,
thanks for the tutorial. This really worked fine for me!
But I need more than 1 check box.
Can you give me code for second checkbox?
Thank you!!
Has anyone figured out how to solve the issue with being able to proceed to checkout even if the checkbox isn't checked?
I have spent several hours troubleshooting with JS and HTML and can't seem to figure it out.
I would greatly appreciate some help. I am using the Supply theme if that helps.
Thanks!
Hi,
i have added this in my registration page, you can add the below code in your respective page where you want to see the "terms and policy".
##If you want to add this in your cart page, then just add name="register" in the respective input button line.
##put the script tag below your html code, at the last part.
hope that it works out for you.
Here i have added the code which works well for me in my registration page before entering into my store.
HTML Part:
<p style="float: none; text-align: right; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align: middle;" type="checkbox" id="agree" required="required" />
<label style="display:inline; float:none" for="agree">
I agree with the <a href="your reference page link">terms and conditions</a>.
</label>
</p>
<p class="text-center">
<input id ="account_submit" type="submit" value="{{ 'customer.register.submit' | t }}" class="btn" name="register">
</p>
JS Part:
<script>
$(function() {
$('body').on('click', '[name="register"]', function() {
if ($('#agree').is(':checked')) {
$("#create_customer").submit();
}
else {
alert("You must agree with the terms and conditions of sales to register.");
return false;
}
});
});
</script>
Hi Ty,
Thanks for the info.
Any chance you could tell me how to display the terms and conditions page within a popup instead of leaving the cart page as it is now.
Thanks
Hi,
That is what i couldn't figure out how to add those terms and condition page
are you able to do this? here is how if you are still interested
this is popup
I agree with the <a href="/pages/terms-conditions" target="popup" onclick="window.open('http://alibaby.ph/pages/terms-conditions','popup','width=600,height=600'); return false;">terms and conditions</a>.
this is for new tab if you want
I agree with the <a href="/pages/terms-conditions" target="_blank">terms and conditions</a>.
I got it to work. Now I need to know how to make the error message inline instead of a popup. Like if they don't click the box, I want the error message to point to the box.
I'm looking for this as well, all i get is the native browser pop-up. But i want the error message appear in red underneath the checkbox, so it's in context.
This didnt work for me
Thank you!
I'm on theme Venture, it works but the text appears in uppercase...
How can I have it in a normal font, with a capital letter only when I put a capital letter?
I am currently using Parallax as theme.
Apparently with my theme it's very difficult to add this option on my checkout page. I tried to code it accordingly to the forum suggestions, but it didn't work. Can someone help me with it?
For me, I am in the Debut theme, and I had to insert the line of code for the checkbox below the submit to cart button. It was very finicky! Good luck!
Hello TyW,
Thanks for sharing such magical things to all of us.
I actually am not an expert on editing code, and please do me a favor.
I am using the theme Narrative with a drawer cart, and follow the instruction of the sectioned theme, yet the checkbox and sentence do not appear.
What information should I provide to let you figure it out?
Thank again.
Hello. I'm not an expert but reading all of the replies in here, I was able to do it on my Narrative theme.
I followed the steps posted here but I did some modifications to make it work on my theme.
I repeat, I"M NOT AN EXPERT I JUST DID THIS ON MY OWN haha! It may or may not work for you.
So here it is...
First, I put these codes on my custom.js and NOT in the theme.js:
$(document).ready(function() {
$('body').on('click', '[name="checkout"], [name="goto_pp"], [name="goto_gc"]', function() {
if ($('#agree').is(':checked')) {
$(this).submit();
}
else {
alert("You must agree with the terms and conditions of sales to check out.");
return false;
}
});
});
Second, my cart is a drawer, so I also put these codes on my cart-drawer.liquid. Not just on my cart-template.liquid.
NOTE: THESE CODES ARE MODIFIED. NOT THE ONE ORIGINALLY POSTED AT THE TUTORIAL.
I added attribute to the <a> tag. So my T&C will open as a POPUP.
If you want to open it in a NEW TAB instead, just change the target="popup" to target="blank" and remove the following words up to false;.
I also added a style property inside the <a> tag with the color that I want for the link. You can remove it or change it whatever you like.
<p style="text-align: center"; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align: middle;" type="checkbox" id="agree" required="required" />
<label style="display:inline; float:none" for="agree">
I agree with the <a href="/pages/terms-conditions" target="popup" onclick="window.open('http://alibaby.ph/pages/terms-conditions','popup','width=600,height=600'); return false;" style="color: #ff8da0">terms and conditions</a>.
</label>
</p>
These are the results:
BONUS:
I tried adding the same codes on my customers/register.liquid and voila! IT WORKED! LOL.
I added some style to make it centered.
This is how my liquid file looked like.
<!-- /templates/customers/register.liquid -->
<div class="page-width customers-register">
<div class="grid">
<div class="grid__item medium-up--four-fifths medium-up--push-one-tenth">
<div class="customers-register__container">
<h1 class="customer-form__title h2" style="text-align: center">{{ 'customer.register.title' | t }}</h1>
{% form 'create_customer' %}
{{ form.errors | default_errors }}
<div class="grid">
<div class="grid__item medium-up--one-half">
<label for="FirstName" class="label--hidden">{{ 'customer.register.first_name' | t }}</label>
<input type="text" name="customer[first_name]" id="FirstName" placeholder="{{ 'customer.register.first_name' | t }}" {% if form.first_name %}value="{{ form.first_name }}"{% endif %} autocapitalize="words" autofocus>
</div>
<div class="grid__item medium-up--one-half">
<label for="LastName" class="label--hidden">{{ 'customer.register.last_name' | t }}</label>
<input type="text" name="customer[last_name]" id="LastName" placeholder="{{ 'customer.register.last_name' | t }}" {% if form.last_name %}value="{{ form.last_name }}"{% endif %} autocapitalize="words">
</div>
</div>
<label for="Email" class="label--hidden">{{ 'customer.register.email' | t }}</label>
<input type="email" name="customer[email]" id="Email" class="{% if form.errors contains 'email' %} input--error{% endif %}" placeholder="{{ 'customer.register.email' | t }}" {% if form.email %} value="{{ form.email }}"{% endif %} autocorrect="off" autocapitalize="off">
<label for="CreatePassword" class="label--hidden">{{ 'customer.register.password' | t }}</label>
<input type="password" name="customer[password]" id="CreatePassword" class="{% if form.errors contains 'password' %} input--error{% endif %}" placeholder="{{ 'customer.register.password' | t }}">
<p style="text-align: center"; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align: middle;" type="checkbox" id="agree" required="required" />
<label style="display:inline; float:none" for="agree">
I agree with the <a href="/pages/terms-conditions" target="popup" onclick="window.open('http://alibaby.ph/pages/terms-conditions','popup','width=600,height=600'); return false;" style="color: #ff8da0">terms and conditions</a>.
</label>
</p>
<p style="text-align: center">
<input type="submit" value="{{ 'customer.register.submit' | t }}" class="btn">
<a href="{{ shop.url }}" class="btn btn--clear">{{ 'customer.register.cancel' | t }}</a>
</p>
{%endform%}
</div>
</div>
</div>
</div>
And this is the actual result:
THAT'S ALL! I HOPE THIS COMMENT HELPED YOU ON YOUR NARRATIVE THEME AS WELL! YOU CAN PRIVATE MESSAGE ME IF YOU HAVE QUESTIONS! THANKS!
Ok so people are not very good at explaining on how to do this for people who are not familiar with programming. I struggled and finally completed this, although half-way.
Did this on Debut theme, the "Accept to terms and conditions" warning shows up only after "Add to cart" is selected. If i select "Buy now" nothing happens as it bypasses the Cart directly to the Checkout so i had to disable Buy now button. Would appreciate if anyone could offer a solution so that the Terms and conditions checkbox appears in the window where customer must enter billing and shipping information (After clicking "Add to cart" or "Buy now"). I suppose it's called Contact_information / page.contact.liquid.
1. Go to "Online store"-> Select your live theme -> Actions -> Edit code
2. Select Assets folder, find theme.js
3. Go to the very end and paste the code:
$(document).ready(function() {
$('body').on('click', '[name="checkout"], [name="goto_pp"], [name="goto_gc"]', function() {
if ($('#agree').is(':checked')) { $(this).submit(); }
else {
alert("You must agree with the terms and conditions of sales to check out."); return false;
}
});
});
You can translate text "You must agree with the terms and conditions of sales to check out." to whatever language your shop is directly in the code.
4. Click Save, then go Sections->find Cart-template.liquid
5. Look for this code using Ctrl+F and search for cart.general.checkout
<div class="cart__shipping rte">{{ taxes_shipping_checkout }}</div>
<div class="cart__buttons-container">
<div class="cart__submit-controls">
{%- unless section.settings.cart_ajax_enable -%}
<input type="submit" name="update"
class="cart__submit btn btn--secondary"
value="{{ 'cart.general.update' | t }}">
{%- endunless -%}
<input type="submit" name="checkout"
class="cart__submit btn btn--small-wide"
value="{{ 'cart.general.checkout' | t }}">
</div>
6. Directly before the line <input type="submit" name="checkout" paste this code:
<p style="float: none; text-align: right; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align: middle;" type="checkbox" id="agree" required="required" />
<label style="display:inline; float:none" for="agree">
I agree with the<a href="/policies/terms-of-service"> terms and conditions</a>.
</label>
</p>
So your final code looks like this:
<div class="cart__shipping rte">{{ taxes_shipping_checkout }}</div>
<div class="cart__buttons-container">
<div class="cart__submit-controls">
{%- unless section.settings.cart_ajax_enable -%}
<input type="submit" name="update"
class="cart__submit btn btn--secondary"
value="{{ 'cart.general.update' | t }}">
{%- endunless -%}
<p style="float: none; text-align: right; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align: middle;" type="checkbox" id="agree" required="required" />
<label style="display:inline; float:none" for="agree">
I agree with the<a href="/policies/terms-of-service"> terms and conditions</a>.
</label>
</p>
<input type="submit" name="checkout"
class="cart__submit btn btn--small-wide"
value="{{ 'cart.general.checkout' | t }}">
</div>
7. Click Save, go check your shop if it works.
8. To disable "Buy now" button go to Online store -> Customize
9. At the top left of the website preview (where Home Page is written by default) select "Product pages"
10. In the Sections click Product Pages and disable "Show dynamic checkout button"
Hey guys!
I found this app can do the same trick for the cart page, also it seems it can create a pop-up for the Buy Now button. Anybody tested?
https://apps.shopify.com/terms-and-conditions-in-cart
Also found this free app with more reviews, but at my first look it doesn't have the Buy Now block feature. https://apps.shopify.com/tos
Thank you Alibabyph!!! You absolutely saved me time and money with this code!! It worked beautifully with my Narrative theme. And I absolutely love the extra bit in the create an account section. Perfect. 🙂
Thank you so much @alibabyph !!!!! If you got a donation link or something, please tell me! I'll send you a little gift for saving my life!
Is it possible to add a second box? I’ve added one but you’re only required to click the original box. You can just click the first box and continue on. I’d like it so both boxes must be checked before proceeding. Thank you much!!!
Hi!
I am using the theme Emerge. I followed these instructions however the check box is still not required! One disparity I noticed was that my cart.liquid under templates does not include any content except
{% render 'framework--cart', view: 'desktop' %}
{% render 'framework--cart', view: 'mobile' %}
I found framework--cart.liquid under snippets. Does this affect the code needed?
Thanks for anyone that can provide some insights!
Thank you. This was very helpful. I am curious if anyone knows how to hide this checkbox unless a particular item (or tags/collections/product types) is added to cart.
For example, I am going to be selling a combination of merchandise and in-store appointments. If a customer orders merch, they will not need this checkbox. If they order something from one of my other 3 collections they will need to accept the terms for service.
Thanks
What do you do if theme.js or theme.js.liquid isn't an option on your theme? We have Modular and I only see tms.js.
Thanks!
@TyW - Thank You!!
Question, is there a way to then add a comment into the Cart Comments when they tick the box?
We want to be able to store 'Authority To Leave' in the Comment box so that is then linked into the order in our IMS.
TIA
Thanks a lot for a great tutorial! Worked perfectly for me.
Hello @TyW
Many thanks for your help. I have a doubt with your solution. It would be very nice if you can help me.
Why did you comment the line :
In the Assets directory, click theme.js.liquid. Find this line of code:
theme.checkoutIndicator();Replace it with:
// theme.checkoutIndicator();
I'm using Debutify Theme and I did comment that line but the slideshow disapear after do it. I don't know what is wrong with that or my template.
hi there
im chris from denmark
i use narrative theme for mig shop. i tried to paste them codes in the right places. but no i agree button comes up.
what to do then
best regards chris
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024