Articles on: Advanced Setup

Creating custom Terms and Conditions checkbox

Before going to the checkout you can set up the terms and conditions check and ensure that customers must mark it before proceeding.



On this page:


Setting up a custom checkbox
Classic checkbox and disabled button
Checkbox with alert

Setting up a custom checkbox



Classic checkbox and disabled button



If you want to set up a classic checkbox before proceeding to the checkout you will need to edit the theme code a little.

Navigate to the your Shopify admin panel.
Visit Online store and select Edit code option from the selection dropdown.
Create a new file in terms-and-conditions-checkbox called terms-and-conditions-checkbox.liquid or similar. Then paste the following code:

{{ 'terms-and-conditions-checkbox.css' | asset_url | stylesheet_tag }}

<div class="checkboxWrapper">
  <div class="checkbox-wrapper">
    <div class="cbx">
      <input id="cbx" type="checkbox">
      <label for="cbx"></label>
      <svg width="15" height="14" viewbox="0 0 15 14" fill="none">
        <path d="M2 8.36364L6.23077 12L13 2"></path>
      </svg>
    </div>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
      <defs>
        <filter id="goo">
          <fegaussianblur in="SourceGraphic" stddeviation="4" result="blur"></fegaussianblur>
          <fecolormatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 22 -7" result="goo"></fecolormatrix>
          <feblend in="SourceGraphic" in2="goo"></feblend>
        </filter>
      </defs>
    </svg>
  </div>
  <a id="terms-and-conditions-text" href="#"> I accept terms and conditions</a>
</div>

<script>
  const checkboxEl = document.getElementById('cbx');
  const checkoutBtnEl = document.getElementById('checkout');
   function checkboxSwitch() {
  if(!this.checked){
    checkoutBtnEl.setAttribute("disabled", "");
  } else{
        checkoutBtnEl.removeAttribute("disabled");
  };
   }
  checkboxEl.addEventListener('change',checkboxSwitch);
  window.addEventListener('load',checkboxSwitch());
</script>


You can change the content of the href="#" attribute so that it links to your terms and conditions page.

Create another file in assets called terms-and-conditions-checkbox.css. Paste the following code:

.checkboxWrapper {
  display:flex;
  flex-direction:row;
  align-items:center;
  column-gap: 10px;
  margin-top: 20px
}

#terms-and-conditions-text{
  color:#0a0a0a;
}

  .checkbox-wrapper {
    position: relative;
  }
  .checkbox-wrapper > svg {
    position: absolute;
    top: -130%;
    left: -170%;
    width: 110px;
    pointer-events: none;
  }
  .checkbox-wrapper * {
    box-sizing: border-box;
  }
  .checkbox-wrapper input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    margin: 0;
  }
  .checkbox-wrapper input[type="checkbox"]:focus {
    outline: 0;
  }
  .checkbox-wrapper .cbx {
    width: 24px;
    height: 24px;
    top: calc(50vh - 12px);
    left: calc(50vw - 12px);
  }
 .checkbox-wrapper .cbx input {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  border: 2px solid #bfbfc0;
  border-radius: 0; 
}
 .checkbox-wrapper .cbx label {
  width: 24px;
  height: 24px;
  background: none;
  border-radius: 0; 
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}
  .checkbox-wrapper .cbx svg {
    position: absolute;
    top: 5px;
    left: 4px;
    z-index: 1;
    pointer-events: none;
  }
  .checkbox-wrapper .cbx svg path {
    stroke: #fff;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 19;
    stroke-dashoffset: 19;
    transition: stroke-dashoffset 0.3s ease;
    transition-delay: 0.2s;
  }
  .checkbox-wrapper .cbx input:checked + label {
    animation: splash 0.6s ease forwards;
  }
  .checkbox-wrapper .cbx input:checked + label + svg path {
    stroke-dashoffset: 0;
  }
  @-moz-keyframes splash {
    40% {
      background: #0a0a0a;
      box-shadow: 0 -18px 0 -8px #0a0a0a, 16px -8px 0 -8px #0a0a0a, 16px 8px 0 -8px #0a0a0a, 0 18px 0 -8px #0a0a0a, -16px 8px 0 -8px #0a0a0a, -16px -8px 0 -8px #0a0a0a;
    }
    100% {
      background: #0a0a0a;
      box-shadow: 0 -36px 0 -10px transparent, 32px -16px 0 -10px transparent, 32px 16px 0 -10px transparent, 0 36px 0 -10px transparent, -32px 16px 0 -10px transparent, -32px -16px 0 -10px transparent;
    }
  }
  @-webkit-keyframes splash {
    40% {
      background: #0a0a0a;
      box-shadow: 0 -18px 0 -8px #0a0a0a, 16px -8px 0 -8px #0a0a0a, 16px 8px 0 -8px #0a0a0a, 0 18px 0 -8px #0a0a0a, -16px 8px 0 -8px #0a0a0a, -16px -8px 0 -8px #0a0a0a;
    }
    100% {
      background: #0a0a0a;
      box-shadow: 0 -36px 0 -10px transparent, 32px -16px 0 -10px transparent, 32px 16px 0 -10px transparent, 0 36px 0 -10px transparent, -32px 16px 0 -10px transparent, -32px -16px 0 -10px transparent;
    }
  }
  @-o-keyframes splash {
    40% {
      background: #0a0a0a;
      box-shadow: 0 -18px 0 -8px #0a0a0a, 16px -8px 0 -8px #0a0a0a, 16px 8px 0 -8px #0a0a0a, 0 18px 0 -8px #0a0a0a, -16px 8px 0 -8px #0a0a0a, -16px -8px 0 -8px #0a0a0a;
    }
    100% {
      background: #0a0a0a;
      box-shadow: 0 -36px 0 -10px transparent, 32px -16px 0 -10px transparent, 32px 16px 0 -10px transparent, 0 36px 0 -10px transparent, -32px 16px 0 -10px transparent, -32px -16px 0 -10px transparent;
    }
  }
 
@keyframes splash {
  40% {
    background: #0a0a0a; 
    box-shadow: 0 -18px 0 -8px #0a0a0a, 16px -8px 0 -8px #0a0a0a, 16px 8px 0 -8px #0a0a0a,
      0 18px 0 -8px #0a0a0a, -16px 8px 0 -8px #0a0a0a, -16px -8px 0 -8px #0a0a0a;
  }
  100% {
    background: #0a0a0a;
    box-shadow: 0 -36px 0 -10px transparent, 32px -16px 0 -10px transparent,
      32px 16px 0 -10px transparent, 0 36px 0 -10px transparent,
      -32px 16px 0 -10px transparent, -32px -16px 0 -10px transparent;
  }
}


Navigate to the main-cart-footer.liquid and paste code shown in the picture:



{% render 'terms-and-conditions-checkbox' %}


Preview your store and check if you can see the terms and conditions checkbox.



Checkbox with alert



To use a checkbox with alert that prevents custoemr to proceed if he had not accepter the terms and conditions paste the following code in the terms-and-conditions-checkbox.liquid that we made in previous section:

{{ 'terms-and-conditions-checkbox.css' | asset_url | stylesheet_tag }}

<div class="checkboxWrapper">
  <div class="checkbox-wrapper">
    <div class="cbx">
      <input id="cbx" type="checkbox">
      <label for="cbx"></label>
      <svg width="15" height="14" viewbox="0 0 15 14" fill="none">
        <path d="M2 8.36364L6.23077 12L13 2"></path>
      </svg>
    </div>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
      <defs>
        <filter id="goo">
          <fegaussianblur in="SourceGraphic" stddeviation="4" result="blur"></fegaussianblur>
          <fecolormatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 22 -7" result="goo"></fecolormatrix>
          <feblend in="SourceGraphic" in2="goo"></feblend>
        </filter>
      </defs>
    </svg>
  </div>
  <a id="terms-and-conditions-text" href="#"> I accept terms and conditions</a>
</div>

<script>
  document.addEventListener('DOMContentLoaded', function() {
    const checkboxEl = document.getElementById('cbx');
    const checkoutBtnEl = document.getElementById('checkout');

    checkoutBtnEl.addEventListener('click', function(event) {
      if (!checkboxEl.checked) {
        event.preventDefault();
        window.alert('Please agree to our Terms and Conditions before proceeding.');
      }
    });
  });
</script>


The result should look like this:

Updated on: 11/03/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!