Is there a way to show the terms and conditions on a page via .phtml
?
I have made a page via a module and now want to show the terms and conditions on that page.
Magento 2 Terms and Conditions – Show on Static Page
magento2modulestatic-contentterms and conditions
Related Solutions
Change 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>
Note : Override form/phtml file into your module, Don't change in core module directly.
at first you need create checkout_index_index.xml
in your theme, then need disable item before-place-order in 314 line:
<item name="before-place-order" xsi:type="array">
with:
<item name="before-place-order" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
Read more here Magento Custimize Checkout Step
Then you need re-add that element on the end of your Checkout, after place order button, like this:
<item name="after-place-agreements" xsi:type="array">
<item name="component" xsi:type="string">uiComponent</item>
<item name="displayArea" xsi:type="string">after-place-agreements</item>
<item name="dataScope" xsi:type="string">before-place-order</item>
<item name="provider" xsi:type="string">checkoutProvider</item>
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Magento_Checkout/payment/before-place-order</item>
</item>
<item name="children" xsi:type="array">
<item name="agreementss" xsi:type="array">
<item name="component" xsi:type="string">Magento_CheckoutAgreements/js/view/checkout-agreements</item>
<item name="sortOrder" xsi:type="string">100</item>
<item name="displayArea" xsi:type="string">after-place-agreements</item>
<item name="dataScope" xsi:type="string">checkoutAgreements</item>
<item name="provider" xsi:type="string">checkoutProvider</item>
</item>
</item>
</item>
Then copy in your default template(html) after place order:
<!-- ko foreach: getRegion('after-place-agreements') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
Good luck!! :)
Best Answer
Step:1 First add below code in your
termsconditions_index_index.xml
file.Step:2 Add below code in your .phtm file
Note: Please add your .phtml file path in
termsconditions_index_index.xml
I have putted currently
template="test/test.phtml"
After run below command: