Cart - Add an 'Agree to terms and conditions' checkbox

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:

Ik ga akkoord met de algemene voorwaarden.

{{ 'general.accessibility.error' | t }} {% include 'icon-error' %}

{%- if additional_checkout_buttons -%}

{{ content_for_additional_checkout_buttons }}
{%- endif -%}

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 -thank you doe this! So I am using Brooklyn theme. I completed your steps, “however” since your post of 2019 - perhaps the code changed a little?

this code doesn’t appear to be the same anymore :disappointed_face: I tried adding “//” in front of it, and it def didn’t work.

theme.checkoutIndicator();

I WAS able to add a check box at checkout - it says: I agree with the terms and conditions. BUT - it still allows users to click on CHECKOUT without clicking the box :disappointed_face:

If you can update this line of code, that would be awesome!!!

Hi There. This wasn’t my original post. My input here is from the last few weeks :slightly_smiling_face: I would say the code has changed a bit from 2019.

Hmmmm I am not sure what else to tell you. I wish I had something. I would try and add the // again and make sure you save it.

I somehow got mine to work. Maybe you can post a new thread? Best of luck. Sorry I can’t help further.

This is what my code section looks like:

theme.checkoutIndicator = function() {
// Add a loading indicator on the cart checkout button (/cart and drawer)
theme.cache.$body.on(‘click’, ‘.cart__checkout’, function() {
$(this).addClass(‘btn–loading’);
});
};

Thanks for this post, it’s very helpful.

How do I make the checkbox optional and how do I get that data on the product order?

I need to know if the customer checked or did not check the checkbox.

Hello - not sure if you are asking me or@gab33 ? This is not my original post.

I would ask @gab33

Wish I could assist but I don’t know the answers to your questions. I am not a developer or a guru. I used the code for my brooklyn theme and it worked.

https://goddessswag.com if you want to see my checkout set up.

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,

I have the same issue. Were you able to fix it?

Thank you

Thank you! Made my day! :slightly_smiling_face: Was about to have a mental breakdown.. hehe

I can see that the checkbox has been added to the “cart page” in the editor:

However, when the cart icon is clicked on the home page and the “quick view” is used it does not appear and can be bypassed:

I am using the Narrative theme, hoping someone can help me with a fix. Thanks!

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 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 tag with the color that I want for the link. You can remove it or change it whatever you like.


These are the results:

popup.png

cart.png

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.


  

    

      

        # {{ 'customer.register.title' | t }}

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

        
          

            
            
          

          
            
            
          

        

        
        

        
        

		

			
			
		

    
        
        

          
          {{ 'customer.register.cancel' | t }}                                                      
        

      {%endform%}
      

    

  

And this is the actual result:

register.png

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.

  1. Click Save, then go Sections->find Cart-template.liquid

  2. Look for this code using Ctrl+F and search for cart.general.checkout

{{ taxes_shipping_checkout }}
{%- unless section.settings.cart_ajax_enable -%} {%- endunless -%}
  1. Directly before the line <input type=“submit” name=“checkout” paste this code:

I agree with the terms and conditions.

So your final code looks like this:

{{ taxes_shipping_checkout }}
{%- unless section.settings.cart_ajax_enable -%} {%- endunless -%} **

** **** **** **I agree with the terms and conditions.** **** **

**
  1. Click Save, go check your shop if it works.

  2. To disable “Buy now” button go to Online store → Customize

  3. At the top left of the website preview (where Home Page is written by default) select “Product pages”

  4. In the Sections click Product Pages and disable “Show dynamic checkout button”

Any updates as to how to make this checkbox required? I can bypass it by clicking the checkout button.

are you able to do this? here is how if you are still interested

this is popup

I agree with the terms and conditions.

this is for new tab if you want

I agree with the terms and conditions.

Thanks Alibabyph

But unfortunately it does not work…

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.

Did you find the solution to this problem? Would love to know if you have.

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