Moving Product Custom Options Below Add to Cart Button in Luma Theme
When it comes to customizing your Magento store, especially with themes like Luma, there are often specific layout adjustments you may need to make. One common requirement is moving the product custom options section below the “Add to Cart” button rather than above it.
In this guide, I’ll walk you through a simple yet effective way to achieve this using core Magento functionality and some theme override techniques.
Understanding the Default Layout
First, let’s understand how Luma theme handles the default layout for product pages. In the app/design/frontend/Magento/luma/Magento_Catalog/layout/catalog_product_view.xml file, you’ll find that the custom options section is defined before the “Add to Cart” button:
<block class="Magento\Catalog\Block\Product\View" name="product.info.options" as="product_info_options" template="Magento_Catalog::product/view/options.phtml">
<arguments>
<argument name="product" xsi:type="object">product</argument>
</arguments>
</block>
<block class="Magento\Framework\View\Element\Template" name="catalog.product.view.addto.button" as="addto">
...
</block>
Overriding the Layout
To move this section, we’ll create a custom layout XML file that overrides the default one. Here are the steps:
-
Create a new XML file in
app/design/frontend/Vendor/Theme/Magento_Catalog/layout/catalog_product_view.xml. -
Add the following content to the file, making sure to change “Vendor” with your actual vendor name and “Theme” with your theme’s name:
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.options" remove="true"/>
<move element="product.info.options" destination="catalog.product.view.addto.button" after="-"/>
</body>
</page>
In this XML, we’re first removing the original “product.info.options” block and then moving it to the “catalog.product.view.addto.button” block but placing it after the existing elements.
Clearing Cache
After making these changes, don’t forget to clear your Magento cache. You can do this from the admin panel under System > Tools > Cache Management, or by running the following command in your terminal:
php bin/magento cache:clean
Conclusion
Moving product custom options below the “Add to Cart” button isn’t a complex task once you understand the theme’s default layout and how to override it. Remember, when working with overrides, always create your own XML files instead of directly editing Magento core files.
This approach ensures that your changes won’t be overwritten during updates, providing a clean and maintainable solution for your customizations.
For more advanced customization techniques and best practices in Magento development, I recommend exploring our Magento Development Guide on the Laravel Company blog. It provides detailed walkthroughs of various layout override methods and other essential Magento customization topics.