2

I activate the terms and conditions for default onepage checkout on Magento 2.

I want that for default the agreements be checked.

I tried to modify these line on vendor/magento/module-checkout-agreements/view/frontend/web/template/checkout/checkout-agreements.html:

<input type="checkbox"
                        data-bind="attr: {
                                    'id': 'agreement_' + agreementId,
                                    'name': 'agreement[' + agreementId + ']',
                                    'value': agreementId
                                    }"
                        data-validate="{required:true}"
                        checked="checked"
                        />

Adding checked="checked".

But i think that as it is a js, it do not marked as checked.

Any idea?

4

First remove checkout-agreements.html from

pub/static/frontend/Magento/luma/en_US/Magento_Checkout/template

Then add 'checked': 'checked' in data-bind attributes

<input type="checkbox"
    data-bind="attr: {
                'id': 'agreement_' + agreementId,
                'name': 'agreement[' + agreementId + ']',
                'value': agreementId,
                'checked': 'checked',
                }"
    data-validate="{required:true}"
 />

Then clear cache and try

  • @Albert - El Corriol Please check and let me know if not working – Prince Patel May 25 '17 at 8:34
  • @Albert This is a correct answer. Its solved my same problem. – Nitesh Sep 4 '17 at 8:34
  • I apply your code. But, I want more. I want to apply if terms and condition checkbox not checked then error validation display when click on place order. Can you please tell me how to do it.? – Rohan Hapani Apr 12 '18 at 5:27
1

Make sure you have remove old file in pub/static

<input type="checkbox"
                        data-bind="attr: {
                                    'id': 'agreement_' + agreementId,
                                    'name': 'agreement[' + agreementId + ']',
                                    'value': agreementId,
                                    'checked': 'checked',
                                    }"
                        data-validate="{required:true}"

                        />

run command to deploy new content php bin/magento setup:static-content:deploy

  • Finally it works!!Thank you!! I remove all files on /pub/static/ and recreate the static files. – Albert May 26 '17 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.