Capture value of checkbox when customer place order

Solved
digitalcloudali
New Member
3 1 0

Hello,

        We are shopify Plus and have access to checkout.liquid file. I manage to add the checkbox in first step of checkout process to accept the terms and condition before customer proceed with checkout step 2. How can i store this checked value with customer data in backend with the order ?

 

<script type = "text/javascript" >
    (function($) {

        $(document).on("page:load page:change", function() {
            if (Shopify.Checkout.step === "contact_information") {
            st = '<div class="field field--show-floating-label">' +
            '<div class="checkbox-wrapper">' +
            '<div class="checkbox__input">' +
            '<input class="input-checkbox" data-backup="terms_check" type="checkbox" value="1" name="checkout[terms_check]" id="checkout_terms_check" required>' +
            '</div>' +
            '<label class="checkbox__label" for="checkout_terms_check"> I agree to the terms & conditions </label>' +
            '</div>' +
            '</div>';

            $('.fieldset').append(st);
              
                $("#continue_button").on("click", function(e) {
                    e.preventDefault();

                    if ($('#checkout_terms_check').is(':checked')) {
                        $(".form").submit();
                    } else {
                       alert("You must agree with the terms and conditions of sales to check out.");
                    }
                });

                $(".form").on("keyup", function(e) {
                    if (e.keycode === 13) {
                        e.preventDefault();
                        $("#continue_button").trigger("click");
                    }
                });
            }
        });

    })(Checkout.$);
</script>

 

Accepted Solution (1)

Accepted Solutions
digitalcloudali
New Member
3 1 0

This is an accepted solution.

Ok i solved it my self.

Just need to change this line

 

 '<input class="input-checkbox" data-backup="terms_check" type="checkbox" value="1" name="checkout[terms_check]" id="checkout_terms_check" required>' +

 

To this

'<input type="checkbox" name="checkout[attributes][terms_check]" class="input-checkbox" id="checkout_terms_check" value="Yes" required>' +
'</div>' +

 

 

View solution in original post

Reply 1 (1)
digitalcloudali
New Member
3 1 0

This is an accepted solution.

Ok i solved it my self.

Just need to change this line

 

 '<input class="input-checkbox" data-backup="terms_check" type="checkbox" value="1" name="checkout[terms_check]" id="checkout_terms_check" required>' +

 

To this

'<input type="checkbox" name="checkout[attributes][terms_check]" class="input-checkbox" id="checkout_terms_check" value="Yes" required>' +
'</div>' +