How To Customize Terms and Conditions Magento 2?

How To Customize Terms and Conditions Magento 2?

Want to boost the legal compliance of your Magento 2 store?

Implementing terms and conditions magento 2 protects your business and informs customers. You can edit, update, and customize the terms and the checkbox appearance as per your needs.

In this tutorial, we'll explore adding and customizing Magento 2 terms and conditions.

Best Magento Hosting now

Key Takeaways

  • Customizing terms and conditions in Magento 2 boosts legal protection.

  • Editing the terms checkbox enhances user experience and agreement rates.

  • Magento 2 supports multiple languages for international customer compliance.

  • Mobile-friendly terms display improves accessibility for all users.

  • Automating terms updates simplifies management across store views.

What are Terms and Conditions in Magento 2?

Understanding Magento 2 Terms and Conditions

"Terms and conditions in Magento 2 are legal agreements between stores and customers. They outline rules and policies for website use and purchases."

These agreements typically cover:

  • Payment terms

  • Usage policies

  • Shipping and returns

  • Privacy and data handling

  • Intellectual property rights

Magento 2 offers built-in functionality to add and manage these agreements. Store owners can create multiple agreements and customize their content. They can also control how agreements are displayed during checkout. The feature helps businesses meet legal requirements and avoid disputes.

Legal Implications of Implementing Terms and Conditions

Legal Aspect Implication Example Magento 2 Implementation
Contract Formation Creates a binding agreement Customer agrees to pay for items as described Add a terms and conditions checkbox at checkout. Enable in Stores > Configuration > Sales > Checkout.
Consumer Rights Informs customers of their legal rights Right to cancel within 14 days for EU customers Include cancellation policy in terms text. Create in Stores > Terms and Conditions.
Data Protection Outlines how customer data is handled Explanation of data collection and usage practices Link privacy policy in terms and conditions. Update content in the admin panel.
Dispute Resolution Defines how conflicts are resolved Specifying arbitration as the dispute resolution method Add dispute resolution clause in terms content. Edit in Stores > Terms and Conditions.
Liability Limitation Sets boundaries for the store's responsibility Limiting liability to the purchase price of products Include liability limitation in terms of text. Update in the admin panel.
Intellectual Property Protects store's content and trademarks Prohibiting unauthorized use of store logos or images Add IP protection clause in terms and conditions. Edit in Stores > Terms and Conditions.
Shipping and Returns Clarifies policies for product delivery and returns Detailing the return process and associated costs Include shipping and return policies in terms. Update in the admin panel.
Age Restrictions Sets minimum age for purchases or account creation Requiring users to be 18+ to create an account Add age verification step during account registration. Customize the registration form.

Note: Implementing these terms helps protect your business from legal issues. It sets clear expectations for customers and prevents misunderstandings. However, terms must be fair and comply with local laws. Unfair or illegal terms may not be enforceable in court.

Customizing Terms and Conditions Checkbox Appearance and Placement

1. Modifying Checkbox Location

Changing the location of the terms and conditions checkbox can improve user experience. Follow these steps:

  • Locate your theme's checkout layout file

  • Find the terms and conditions block

  • Move the block to your desired position

  • Update the layout XML accordingly

  • Clear cache and verify changes on the frontend

Example code to move the checkbox:

<move element="checkout.agreements" destination="checkout.payment.methods" after="-"/>  

The above code moves the checkbox after payment methods. You can adjust the destination and position as needed.

2. Styling the Checkbox

Customizing the checkbox style helps it match your store's design. Here's how:

  • Create a custom CSS file for checkout

  • Target the checkbox and label elements

  • Apply your desired styles

  • Include the CSS file in your theme

  • Test on different devices for responsiveness

Example CSS for styling:

.checkout-agreement input[type="checkbox"] {  
    width: 20px;  
    height: 20px;  
    border: 2px solid #333;  
}  
.checkout-agreement label {  
    font-weight: bold;  
    color: #333;  
    font-size: 14px;  
}  

3. Customizing Text Display

Modifying the terms' text display improves readability. Follow these steps:

  • Override the default template file

  • Edit the HTML structure

  • Add custom classes or attributes

  • Update the template in your theme

  • Implement responsive design for mobile users

Example template modification:

<div class="checkout-agreement">  
    <input type="checkbox" id="agreement-<?= $block->escapeHtml($_agreementId) ?>"   
           name="agreement[<?= $block->escapeHtml($_agreementId) ?>]"   
           value="1" class="required-entry" data-validate="{required:true}"/>  
    <label for="agreement-<?= $block->escapeHtml($_agreementId) ?>">  
        <span class="agreement-content"><?= $block->escapeHtml($_agreement->getCheckboxText()) ?></span>  
    </label>  
</div>  

4. Adding Custom Functionality

Enhance the checkbox with additional features for better user interaction:

  • Create a custom JavaScript file

  • Add event listeners to the checkbox

  • Implement desired functionality (e.g., modal popup)

  • Include the JS file in your theme

  • Test thoroughly across different scenarios

Example JavaScript for a modal popup:

document.querySelector('.checkout-agreement input').addEventListener('click', function() {  
    if (this.checked) {  
        openTermsModal();  
    }  
});

function openTermsModal() {  
    // Code to open a modal with full terms  
}  

5. Implementing Multi-language Support

For international stores, multi-language support is crucial. Here's how:

  • Create translation files for each language

  • Add translations for checkbox text and terms

  • Configure language switching in Magento admin

  • Test checkout in different languages

  • Ensure proper text display for all languages

Example translation file (en_US.csv):

"I agree to the terms and conditions," "I agree to the terms and conditions"  
"Please read and accept the terms and conditions," "Please read and accept the terms and conditions."  

6. Optimizing for Mobile Devices

  • Ensure the checkbox is easily accessible on mobile devices:

  • Use responsive CSS for mobile layouts

  • Adjust font sizes and spacing for small screens

  • Test touch interactions on various devices

  • Implement a mobile-friendly terms viewer

  • Optimize loading speed for mobile networks

Example mobile-specific CSS:

@media (max-width: 768px) {  
    .checkout-agreement label {  
        font-size: 16px;  
        line-height: 1.5;  
    }  
    .checkout-agreement input[type="checkbox"] {  
        width: 24px;  
        height: 24px;  
    }  
}  

Note: These customizations will enhance the appearance and functionality of your terms and conditions checkbox in Magento 2. Remember to test all changes thoroughly before deploying to your live store.

Integrating Magento 2 Terms Acceptance with Accounts and Order History

1. Creating a Terms Acceptance Table

  • Open your Magento 2 database management tool

  • Create a new table for storing terms acceptance

  • Define columns for customer ID, terms version, and acceptance date

  • Add foreign key constraints for data integrity

  • Execute the SQL query to create the table

CREATE TABLE terms_acceptance (  
    id INTEGER PRIMARY KEY AUTO_INCREMENT,  
    customer_id INTEGER NOT NULL,  
    terms_version TEXT NOT NULL,  
    accepted_at DATETIME DEFAULT CURRENT_TIMESTAMP,  
    FOREIGN KEY (customer_id) REFERENCES customer_entity(entity_id)  
);  

This table will store each customer's terms acceptance history. It allows tracking multiple versions of terms and conditions.

2. Updating Customer Registration Process

  • Locate the customer registration controller in Magento 2

  • Add a new field for terms acceptance in the registration form

  • Modify the controller to handle the new field

  • Store the terms acceptance data in the new table

  • Update the customer account creation confirmation

public function createPost()  
{  
    // Existing registration logic  
    $customer = $this->customerExtractor->extract('customer_account_create', $this->_request);  
    $termsAccepted = $this->getRequest()->getParam('terms_accepted', false);  
      
    if ($termsAccepted) {  
        $customer->setCustomAttribute('terms_accepted', true);  
          
        // Save acceptance details using the repository pattern  
        $termsAcceptance = $this->termsAcceptanceFactory->create();  
        $termsAcceptance->setCustomerId($customer->getId())  
                       ->setTermsVersion('v1.0')  
                       ->setAcceptedAt(new DateTime());  
                         
        try {  
            $this->termsAcceptanceRepository->save($termsAcceptance);  
        } catch (Exception $e) {  
            throw new LocalizedException(__('Unable to save terms acceptance.')); // Graceful error handling  
        }  
    }  
      
    // Continue with customer creation  
}  

The above code adds terms of acceptance to the registration process. It stores the data for future reference and compliance.

3. Integrating Terms Acceptance with Order Placement

  • Modify the order placement process in Magento 2

  • Add a check for terms acceptance before order submission

  • Store the version of the accepted terms with each order

  • Update the order confirmation page to show the term's acceptance

  • Implement a terms re-acceptance process for outdated versions

public function placeOrder($orderId)  
{  
    try {  
        $order = $this->orderRepository->get($orderId);  
        $customerId = $order->getCustomerId();  
          
        $latestAcceptance = $this->termsAcceptanceRepository->getLatestForCustomer($customerId);  
          
        if (!$latestAcceptance || $latestAcceptance->getVersion() !== $this->getCurrentTermsVersion()) {  
            throw new MagentoFrameworkExceptionLocalizedException(__('Please accept the latest terms and conditions'));  
        }  
          
        $order->setData('terms_version', $latestAcceptance->getVersion());  
        $this->orderRepository->save($order);  
          
        // Continue with order placement  
    } catch (MagentoFrameworkExceptionNoSuchEntityException $e) {  
        throw new MagentoFrameworkExceptionLocalizedException(__('Order not found.'));  
    } catch (Exception $e) {  
        throw new MagentoFrameworkExceptionLocalizedException(__('Unable to place order.')); // Graceful handling for unexpected issues  
    }  
}  

This integration ensures customers agree to the latest terms. It also records the specific version accepted for each order.

4. Displaying Terms Acceptance in Customer Account

  • Create a new section in the customer account dashboard

  • Fetch the customer's terms acceptance history from the database

  • Display the acceptance history in a user-friendly format

  • Add an option to view and re-accept the latest terms

  • Implement a notification system for term updates

public function getTermsAcceptanceHistory($customerId)  
{  
    $acceptanceHistory = $this->termsAcceptanceRepository->getHistoryForCustomer($customerId);  
      
    $result = [];  
    foreach ($acceptanceHistory as $acceptance) {  
        $result[] = [  
            'version' => $acceptance->getVersion(),  
            'accepted_at' => $acceptance->getAcceptedAt()->format('Y-m-d H:i:s'),  
            'is_current' => $acceptance->getVersion() === $this->getCurrentTermsVersion()  
        ];  
    }  
      
    return $result;  
}  

This feature increases transparency and helps customers track their agreement history. It also facilitates easy updates to terms acceptance.

5. Adding Terms Acceptance to Order History

  • Modify the order history page in Magento 2

  • Add a column to display the terms version for each order

  • Create a link to view the specific terms version accepted

  • Implement a system to archive old-term versions

  • Add a filter option for orders based on terms versions

public function addTermsVersionToOrderGrid($collection)  
{  
    $collection->addFieldToSelect('terms_version');  
      
    return $collection;  
}  

This enhancement provides a clear record of terms acceptance. It helps resolve disputes and maintain legal compliance.

Automating Terms and Conditions Updates for Multiple Store Views

1. Create a Custom Module for Terms Management

<?xml version="1.0"?>  
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">  
    <module name="Vendor_TermsManager" setup_version="1.0.0">  
        <sequence>  
            <module name="Magento_CheckoutAgreements"/>  
        </sequence>  
    </module>  
</config>  

2. Set Up a Cron Job for Regular Updates

<?xml version="1.0"?>  
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">  
    <group id="default">  
        <job name="update_terms_conditions" instance="VendorTermsManagerCronUpdateTerms" method="execute">  
            <schedule>0 1 * * *</schedule>  
        </job>  
    </group>  
</config>  

3. Create an Observer to Handle Terms Updates

<?php  
namespace VendorTermsManagerObserver;

use MagentoFrameworkEventObserver;  
use MagentoFrameworkEventObserverInterface;  
use MagentoStoreModelStoreManagerInterface;  
use VendorTermsManagerModelAgreementFactory;  
use VendorTermsManagerModelAgreementRepository;

class UpdateTermsObserver implements ObserverInterface  
{  
    protected $storeManager;  
    protected $agreementFactory;  
    protected $agreementRepository;

    public function __construct(  
        StoreManagerInterface $storeManager,  
        AgreementFactory $agreementFactory,  
        AgreementRepository $agreementRepository  
    ) {  
        $this->storeManager = $storeManager;  
        $this->agreementFactory = $agreementFactory;  
        $this->agreementRepository = $agreementRepository;  
    }

    public function execute(Observer $observer)  
    {  
        $termsContent = $observer->getData('terms_content');  
        if ($termsContent) {  
            $this->updateTermsAcrossStores($termsContent);  
        }  
    }

    public function updateTermsAcrossStores($termsContent)  
    {  
        $storeIds = $this->storeManager->getStores(true);  
        foreach ($storeIds as $storeId => $store) {  
            $agreement = $this->agreementFactory->create();  
            $agreement->setStoreId($storeId)  
                ->setName('Terms and Conditions')  
                ->setContent($termsContent)  
                ->setIsActive(1)  
                ->setIsHtml(1);  
            $this->agreementRepository->save($agreement);  
        }  
    }  
}  

4. Create an Admin Interface for Managing Terms Versions

<?php  
namespace VendorTermsManagerBlockAdminhtml;

use MagentoBackendBlockWidgetGridContainer;

class TermsVersion extends Container  
{  
    protected function _construct()  
    {  
        $this->_controller = 'adminhtml_termsversion';  
        $this->_blockGroup = 'Vendor_TermsManager';  
        $this->_headerText = __('Manage Terms Versions');  
        $this->_addButtonLabel = __('Add New Version');  
        parent::_construct();  
    }  
}  

FAQs

1. How can I add terms and conditions to the Magento 2 checkout page?

To add terms and conditions, navigate to the checkout options. You can manually or automatically configure the terms checkbox. Enter the content in the text box where the terms appear. Customers are required to agree before placing an order.

2. How do I enable terms and conditions on the Magento 2 checkout page?

In Magento 2, enable terms and conditions from the checkout options. Clients must tick the checkbox before entering payment information. This step is required by law for B2C or B2B sites.

3. Can I add multiple terms and conditions checkboxes on the checkout page?

Yes, Magento 2 allows adding 2 terms and conditions checkboxes. Customers have to agree to both before placing an order. Use this feature if required by law to disclose information.

4. How do I customize the height of the terms and conditions text box?

You can adjust the pixel height of the text box. Enter the content height manually to fit your needs. This step helps optimize the display for better usability.

5. Can terms and conditions statements appear during checkout in Adobe Commerce?

Yes, terms and conditions statements appear during checkout in Adobe Commerce. It’s imperative for ecommerce stores to simplify customer agreements. B2C or B2B sites must follow the law when using TOS.

6. What steps should I follow to configure terms and conditions in Magento 2?

To configure Magento 2 terms and conditions, enable the checkbox in checkout options. Next. craft the terms in the textbox. Scroll pixels to determine height. Its required for seamless ecommerce.

7. Why is it mandatory for online stores to add terms and conditions?

Terms and conditions are mandatory to simplify legal compliance. Required by law for disclosure in ecommerce, they protect businesses. Google Analytics can track user interactions, helping improve customer experience. Customers are required to agree before registering or making a purchase. It can simplify refund processes.

CTA

Summary

Implementing terms and conditions in Magento 2 safeguards your online business. Layout guidelines for customers and meet legal requirements effectively. Here are the key highlights of the tutorial:

  1. Customize the appearance and placement of the terms checkbox. Improve user experience and increase agreement rates during checkout.
  2. Integrate terms acceptance with customer accounts and order history. Create a comprehensive record of agreements for compliance management.
  3. Support multiple languages for terms in international stores. Provide terms customers can understand regardless of their native language.
  4. Optimize terms display for mobile devices to improve accessibility. Reach more mobile shoppers with a better user experience.
  5. Automate terms updates across multiple store views efficiently. Streamline management and maintain consistency across your Magento store.

Managed Magento hosting services include terms and conditions updating/editing within the plans.

Sayan Chakraborty
Sayan Chakraborty
Technical Writer

Sayan is a seasoned technical writer with over 4 years of expertise in SDLCs and Magento. His proficiency lies in simplifying complex Magento hosting concepts in clear, concise words.


Get the fastest Magento Hosting! Get Started