0

I want to add Terms and Conditions checkobox on Account registration page in magento2. User should accept the terms and condition before creating an account

0

try with below file and update in following files: /vendor/magento/module-customer/view/frontend/templates/form/register.phtml (Append below code)

<?php   
     if (!$block->getAgreements()) {
            return;
        }

        /** @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection $argeementsCollection */
        $argeementsCollection = $block->getAgreements();
        $agreementMappedArray = [];
        /** @var \Magento\CheckoutAgreements\Model\Agreement $agreement */
        foreach ($argeementsCollection as $agreement) {
            if ($agreement->getIsActive()) {
                $agreementMappedArray[] = [
                    'mode' => $agreement->getMode(),
                    'agreementId' => $agreement->getAgreementId(),
                    'checkboxText' => $agreement->getCheckboxText(),
                    'content' => $agreement->getContent()
                ];
            }
        }
        $agreementJson = json_encode($agreementMappedArray);
        ?>
        <div data-bind="scope: 'checkout-agreements-component-scope'" class="checkout-agreements-block">
        <!-- ko template: getTemplate() --><!-- /ko -->
        </div>

Add below script :

<script type="text/x-magento-init">
 {
    "*": {
        "Magento_Ui/js/core/app": {
            "components": {
                "checkout-agreements-component-scope": {
                    "component": "Magento_CheckoutAgreements/js/view/checkout-agreements",
                    "agreements": <?php /* @noEscape */ echo $agreementJson; ?>,
                    "isVisible": true
                }
            }
        }
    }
}
</script>

I hope its work for you.

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.