I've read many add tabs post here, but can't seem to get any to work the way I need to work.
-
Attribute is 'sizechart' and is text field added to the default attribute set (but could be dropdown or multiselect)
-
In admin product add text to "sizechart" attribute eg "levi-size" ("levi-size' is name of CMS/Block already created in the backend).
-
The product page would then display the new tab with the CMS/Block
Since the size charts for different manufacturers aren't the same, I can't make a static tab, but need one which will use the custom test field or even better, a dropdown where the storefront labels contain the CMS/Block widget code such as below
{{widget type="Magento\Cms\Block\Widget\Block" template="widget/static_block/default.phtml" block_id="3"}}
I had this working very well in 1.9, but since 2.2, I can't seem to find a way to make this work.
The code I've seen here for Magento 2 and 2.1 doesn't seem to work for 2.2 and I'm not sure what the solution is. I expect this to go to bounty in a few days …
Ideally, creating a drop down where the admin label is "oneill" and the storefront field is
{{widget type="Magento\Cms\Block\Widget\Block" template="widget/static_block/default.phtml" block_id="3"}}
witch would correspond to the oneill warranty information would be much better.
And the same for size charts as well.
EDIT: For 2.3.2, the tabs were before the product details. To change that, I added SORT to the catalog_product_view.xml
This is what I added
<referenceBlock name="product.info.details">
<referenceBlock name="product.info.description">
<arguments>
<argument name="sort_order" xsi:type="string">10</argument>
</arguments>
</referenceBlock>
<referenceBlock name="product.attributes">
<arguments>
<argument name="sort_order" xsi:type="string">20</argument>
</arguments>
</referenceBlock>
</referenceBlock>
Then, below my added tab I added
<argument name="sort_order" xsi:type="string">50</argument>
So the whole file looks like
<?xml version="1.0"?>
<page 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.details">
<referenceBlock name="product.info.description">
<arguments>
<argument name="sort_order" xsi:type="string">10</argument>
</arguments>
</referenceBlock>
<referenceBlock name="product.attributes">
<arguments>
<argument name="sort_order" xsi:type="string">20</argument>
</arguments>
</referenceBlock>
</referenceBlock>
<referenceBlock name="product.info.details">
<block class="Magento\Catalog\Block\Product\View" name="custom.tab" template="HBC_size::product/view/details/custom_tab.phtml" group="detailed_info">
<arguments>
<argument translate="true" name="title" xsi:type="string">Size Chart</argument>
<argument name="sort_order" xsi:type="string">50</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Best Answer
You can try code, same as below:
Note:
For dropdown or multiselect attribute, you need to change code accordingly or add multiple conditions for the same.