Magento: Moving Terms & Conditions to the First Checkout Step
One of the most common requests we get from our clients is how to move the “terms and conditions” field from the last checkout step in Magento to the first one. By default, Magento places this field at the end of the checkout process for security reasonsâbut there are valid cases where you might want to move it earlier.
The Challenge: Moving Terms & Conditions Without XML
Many developers try to achieve this by editing the checkout.xml file directly. While this approach works in theory, it often leads to issues with Magento’s built-in validation and progression of checkout steps. If not done correctly, users won’t be able to proceed past the first step even after accepting the terms.
The Solution: Using an Observer for Better Control
The most robust way to move the “terms and conditions” field is by using an event observer in Magento 2. This allows you to intercept and modify the checkout process flow without breaking any of Magento’s core functionality.
Here are the steps:
Step 1: Create a Custom Plugin
First, create a new plugin file that will extend the Magento\Checkout\Controller\Cart\Index class. In your plugin file (let’s say app/code/Vendor/Module/etc/frontend/di.xml), define the following configuration:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager etc/config.xsd">
<type name="Magento\Checkout\Controller\Cart\Index">
<plugin name="vendor_module_checkout_index_observer" type="Vendor\Module\Observer\CheckoutIndexObserver" sortOrder="10"/>
</type>
</config>
Step 2: Implement the Observer
Next, create the observer class app/code/Vendor/Module/Observer/CheckoutIndexObserver.php. In this class, you’ll override the execute method to add your custom logic:
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var \Magento\Checkout\Model\Session $checkoutSession */
$checkoutSession = $this->get checkoutSession();
if ($checkoutSession->isAllowToDisplayTermsAndConditions()) {
return;
}
// Add your terms and conditions field here (e.g., a new form element)
$checkoutSession->setIsAllowToDisplayTermsAndConditions(true);
}
Step 3: Add the Terms & Conditions Field
In the execute method, add your custom form fields using Magento’s form context. You can reference our guide on Adding Custom Fields to Checkout in Magento for detailed instructions.
Best Practices: Testing and Deployment
Always test your changes thoroughly before deploying them to a production environment. Use Magento’s built-in testing tools, and consider using a staging environment first to catch any potential issues.
Remember that modifying the checkout process can have security implications, so make sure you understand how it affects your store’s compliance with payment gateway rules and PCI standards.
Conclusion
Moving the “terms and conditions” field in Magento requires careful handling of the checkout process. By using an observer plugin, you can intercept and modify the flow without breaking Magento’s core functionality or causing validation errors.
If you’re looking to build custom checkouts for your e-commerce store, consider reaching out to our team at Laravel Company. We specialize in Magento development services that help businesses like yours create seamless shopping experiences.