4

I have a problem moving this reviews tab to the last. Sorry I'm new to magento 2. I did all my best searching the web for solutions. but I was hoping someone can help me here.

enter image description here

2

5 Answers 5

6

You can just change inside details.phtml template file and set as per your requirement tabbing order,

set details.phtml file inside your theme folder,

app/design/frontend/Packagename/themename/Magento_Catalog/templates/product/view/details.phtml

first print order of tabbing by,

   <?php if ($detailedInfoGroup = $block->getGroupChildNames('detailed_info', 'getChildHtml')):
                echo "<pre>";print_r($detailedInfoGroup);
    ?>

            **Now you have display your order tabbing in array.
            you can just change your order by creating new array,**

 <?php $newOrderTabbing = array('product.info.description','product.attributes','reviews.tab'); //custom add ?>

Inside foreach in this file, rename array name like instead of Code for details.phtml file,

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php if ($detailedInfoGroup = $block->getGroupChildNames('detailed_info', 'getChildHtml')):?>
    <?php $newOrderTabbing = array('product.info.description','reviews.tab','product.attributes'); //custom add ?>
    <div class="product info detailed">
        <?php $layout = $block->getLayout(); ?>
        <div class="product data items" data-mage-init='{"tabs":{"openedState":"active"}}'>
            <?php foreach ($newOrderTabbing as $name):?>
                <?php
                    $html = $layout->renderElement($name);
                    if (!trim($html)) {
                        continue;
                    }
                    $alias = $layout->getElementAlias($name);
                    $label = $block->getChildData($alias, 'title');
                ?>
                <div class="data item title"
                     aria-labeledby="tab-label-<?php /* @escapeNotVerified */ echo $alias;?>-title"
                     data-role="collapsible" id="tab-label-<?php /* @escapeNotVerified */ echo $alias;?>">
                    <a class="data switch"
                       tabindex="-1"
                       data-toggle="switch"
                       href="#<?php /* @escapeNotVerified */ echo $alias; ?>"
                       id="tab-label-<?php /* @escapeNotVerified */ echo $alias;?>-title">
                        <?php /* @escapeNotVerified */ echo $label; ?>
                    </a>
                </div>
                <div class="data item content" id="<?php /* @escapeNotVerified */ echo $alias; ?>" data-role="content">
                    <?php /* @escapeNotVerified */ echo $html; ?>
                </div>
            <?php endforeach;?>
        </div>
    </div>
<?php endif; ?>

After adding above code now review tab display at the end of tab. Finally Tab orders are display like Details, More Information,Review.

Thanks.

0
1

Just extract reviews.tab from detailedInfoGroup array and push after

if (($key = array_search('reviews.tab', $detailedInfoGroup)) !== false) {
    unset($detailedInfoGroup[$key]);
    array_push($detailedInfoGroup, "reviews.tab");
}
1
  • Nice idea, working fine Feb 1, 2022 at 13:42
1

This is working. We can use sort order to move the tab where we want.

<?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">70</argument>
                    </arguments>
                </referenceBlock>
            </referenceBlock>
        </body>
    </page>
0

For Magento 2.1 CE

Inside:

app/design/frontend/Packagename/themename/Magento_Catalog/templates/product/view/details.phtml

or:

vendor/magento/module-catalog/view/frontend/templates/product/view/details.phtml

Add:

<?php 
  $customTabsLayout = array_diff($detailedInfoGroup, ['reviews.tab','product.attributes']);
  $toAddAafter = array('product.attributes','reviews.tab');
  $newOrderTabbing = array_merge($customTabsLayout,$toAddAafter);
?>

and change

<?php foreach ($detailedInfoGroup as $name):?>

to

<?php foreach ($newOrderTabbing as $name):?>

Like

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php if ($detailedInfoGroup = $block->getGroupChildNames('detailed_info', 'getChildHtml')):?>

<?php 
  $customTabsLayout = array_diff($detailedInfoGroup, ['reviews.tab','product.attributes']);
  $toAddAafter = array('product.attributes','reviews.tab');
  $newOrderTabbing = array_merge($customTabsLayout,$toAddAafter);
?>

    <div class="product info detailed">
        <?php $layout = $block->getLayout(); ?>
        <div class="product data items" data-mage-init='{"tabs":{"openedState":"active"}}'>
            <?php foreach ($newOrderTabbing as $name):?>
                <?php
                    $html = $layout->renderElement($name);
                    if (!trim($html)) {
                        continue;
                    }
                    $alias = $layout->getElementAlias($name);
                    $label = $block->getChildData($alias, 'title');
                ?>
                <div class="data item title"
                     aria-labeledby="tab-label-<?php /* @escapeNotVerified */ echo $alias;?>-title"
                     data-role="collapsible" id="tab-label-<?php /* @escapeNotVerified */ echo $alias;?>">
                    <a class="data switch"
                       tabindex="-1"
                       data-toggle="switch"
                       href="#<?php /* @escapeNotVerified */ echo $alias; ?>"
                       id="tab-label-<?php /* @escapeNotVerified */ echo $alias;?>-title">
                        <?php /* @escapeNotVerified */ echo $label; ?>
                    </a>
                </div>
                <div class="data item content" id="<?php /* @escapeNotVerified */ echo $alias; ?>" data-role="content">
                    <?php /* @escapeNotVerified */ echo $html; ?>
                </div>
            <?php endforeach;?>
        </div>
    </div>
<?php endif; ?>
1
  • Try not to repeat the same answer... Apr 18, 2019 at 21:35
0

Modify the order of the xml blocks in catalog_product_view.xml. They should all be listed in the name="product.info.details" xml node

1
  • how? can you show how to do it? Jan 8, 2020 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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