0

i am facing problems while adding a custom tab on the PDP page along with the description.

what i have tried

catalog_product_view.xml

<?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">
<block class="Magento\Catalog\Block\Product\View" name="tabbb.tab" template="Learning_Module::shipping.phtml" group="detailed_info" >
<arguments>
<argument translate="true" name="title" xsi:type="string">Shipping Policy</argument>
</arguments>
</block>
</referenceBlock>


<referenceBlock name="product.info.details">
<block class="Magento\Catalog\Block\Product\View" name="ssssss" template="Learning_Module::delivery.phtml" group="detailed_info" >
<arguments>
<argument translate="true" name="title" xsi:type="string">Delivery</argument>
</arguments>
</block>
</referenceBlock>

</body>
</page>

shipping.phtml

<?php

$product = $block->getProduct();

?>
dxsdccdcsdc
<!--<h1 style="color: #ff6e17"><?php echo $product->getData('tabbb'); ?></h1>-->

delivery.phtml

<?php

$product = $block->getProduct();

?>
sdcfcd
<!--<h1 style="color: #ff6e17"><?php echo $product->getData('sssss'); ?></h1>-->

afterall, this all am getting is only a single whereas the second tab is missing. prefer the image fro more details enter image description here

0

Try to replace your XML file content with this

<?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">
            <block class="Magento\Catalog\Block\Product\View" name="custom-tab-1" template="Learning_Module::shipping.phtml" group="detailed_info" >
                <arguments>
                    <argument translate="true" name="title" xsi:type="string">Shipping Policy</argument>
                    <argument name="sort_order" xsi:type="string">50</argument>
                </arguments>
            </block>
            <block class="Magento\Catalog\Block\Product\View" name="custom-tab-2" template="Learning_Module::delivery.phtml" group="detailed_info" >
                <arguments>
                    <argument translate="true" name="title" xsi:type="string">Delivery</argument>
                    <argument name="sort_order" xsi:type="string">60</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

You need to add sort_order for new tabs. After changing above file please run below commands.

php bin/magento c:c full_page layout

Hope this will help you!

  • 1
    ok give me a min let me try – Pramod Dec 5 '19 at 9:22
  • it works could you please expalin what is the use of sort order here – Pramod Dec 5 '19 at 9:24
  • Sure, If you'll not add sort number to tabs then it will take 0 as a sort number by default and you have created 2 tabs in both tabs that will take 0 so you can see only last tab. If you'll remove last then you can second tab. that logic is available here in this default Magento file vendor/magento/module-catalog/Block/Product/View/Details.php – Kishan Savaliya Dec 5 '19 at 9:26
  • ok that means it is overriding my first tab based on sort order – Pramod Dec 5 '19 at 9:27
  • 1
    thank you and i have already accepted your ans – Pramod Dec 5 '19 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.