Monday, Jul 18, 2022 / Magento / Ashvin Vora

How to Add HTML Tags to the Default Terms & Conditions of Magento 2

Have you set up your terms and conditions? Establishing clear guidelines will prevent misunderstandings and protect you from liability. As a result, we’ll help make this process as simple and easy as possible so that you can concentrate on what’s important.

Create Magento 2 Terms and Conditions in the admin panel.

Go to Stores > Terms and Conditions

Click “Add new conditions” Here.

Step-1:

app/code/VendorName/ModuleName/etc/di.xml

—————————————————————
<?xml version="1.0"?>

<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:ObjectManager/etc/config.xsd”>

<preference for=”Magento\CheckoutAgreements\Model\AgreementsConfigProvider” type=”VendorName\ModuleName\Model\AgreementsConfigProvider” />

</config>

You have to override this file path into your module

vendor/magento/module-checkout-agreements/Model/AgreementsConfigProvider.php

Step-2:

app/code/VendorName/ModuleName/Model/AgreementsConfigProvider.php

—————————————————————————————————–
scopeConfiguration = $scopeConfiguration;
$this->checkoutAgreementsRepository = $checkoutAgreementsRepository;
$this->escaper = $escaper;
$this->checkoutAgreementsList = $checkoutAgreementsList ?: ObjectManager::getInstance()->get(
\Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface::class
);
$this->activeStoreAgreementsFilter = $activeStoreAgreementsFilter ?: ObjectManager::getInstance()->get(
ActiveStoreAgreementsFilter::class
);
}

/**
* @inheritdoc
*/
public function getConfig()
{
$agreements = [];
$agreements['checkoutAgreements'] = $this->getAgreementsConfig();

return $agreements;
}

/**
* Returns agreements config.
*
* @return array
*/
protected function getAgreementsConfig()
{
$agreementConfiguration = [];
$isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(
\Magento\CheckoutAgreements\Model\AgreementsProvider::PATH_ENABLED,
ScopeInterface::SCOPE_STORE
);

$agreementsList = $this->checkoutAgreementsList->getList(
$this->activeStoreAgreementsFilter->buildSearchCriteria()
);
$agreementConfiguration['isEnabled'] = (bool)($isAgreementsEnabled && count($agreementsList) > 0);

foreach ($agreementsList as $agreement) {
$agreementConfiguration['agreements'][] = [
'content' => $agreement->getIsHtml()
? $agreement->getContent()
: nl2br($this->escaper->escapeHtml($agreement->getContent())),
'checkboxText' => htmlspecialchars_decode($agreement->getCheckboxText()),
'mode' => $agreement->getMode(),
'agreementId' => $agreement->getAgreementId(),
'contentHeight' => $agreement->getContentHeight()
];
}

return $agreementConfiguration;
}
}


Click on Save Page at the top right of the window, and you’re done!

Now, when you click on the link in your site’s default footer menu, your Terms and Conditions will display natively.

Voila and it’s done. Please let us know if there is anything we missed. Waiting for your comments. Stay tuned.

divider
author
Ashvin Vora
under Magento
line

You have a visionWe know the way to get you there.