I'm trying to change the order of the tabs on the product page in Magento 2. Default is Details|More Information|Reviews
.
I tried:
Vendor/theme/Magento_Catalog/layout/catalog_product_view.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="product.info.description" destination="product.info.details" after="-" />
</body>
</page>
But that doesn't work, and thats the recommended way for moving elements. I was able to move the tabs out of the tab area and into other areas, as well as add new tabs, but I cannot control the order of the tabs.
My guess is that it has something to do with group="detailed_info"
; It looks like Magento grabs the layout elements with this attribute in the XML and loops through through it to create the tabs.
Is there a way to change the order of tabs without rewriting the module?
Best Answer
My approach is a little different but probably more future proof, in case of adding new tabs later on and changing the priority/order of these tabs.
I passed an argument for each tab via XML File in my themes XML file
So my themes XML file looks something like this:
Further more we have to adjust the
details.phtml
, so copy it fromto
Please keep in mind that magento's own
details.phtml
could be changed in future Magento versions or patches. These changes should be also applied to your theme'sdetails.phtml
We now need to get the priority which we passed on via the XML file.
So you see: You just have to add a few lines and can always change the priority/order of the tabs via the xml file, you don't have to change the
details.phtml
in future anymore.