In Magento 2.4.x EE, How to add Terms and condition with modal popup in customer registration page?
1 Answer
Change in following files:
/vendor/magento/module-customer/view/frontend/templates/form/register.phtml
(Append below code - after override this file in your theme)
<?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>
Note : Override form/phtml file into your module, Don't change in core module directly.