cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 order information: How to add links dynamically?

Magento 2 order information: How to add links dynamically?

When a customer selects an order in his order history he is redirected to the order information page.

If the items have not yet been shipped there is only one tab available: Items ordered. If its shipped and invoiced two other tabs are available: Shipment and Invoice.

Where can I find the code responsible for showing and not showing the aforementioned tabs? I am asking because I want to create a custom tab and dynamically decide whether it should be shown or not.

4 REPLIES 4

Re: Magento 2 order information: How to add links dynamically?

@Jens_Noma Enable template path hints and check the respected files. Go on path to enable path hint - Stores > Configuration > Developer  options  from the Advanced tab at the end. 

set Enabled Template Path Hints for Storefront to yes

-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Magento 2 order information: How to add links dynamically?

Unfortunatelly, I already did that but I was not able to find the piece of code responsible for that.

Re: Magento 2 order information: How to add links dynamically?

By default In Order history page of Customer dashboard,

 

All the dynamics links are handled by below layout XML from Sales Module,

sales_order_info_links.xml

All the links are managed by _toHtml() function from Link.php,

 

You can add/modify your new tab using above xml overriding in your custom theme or module level.

 

 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Magento 2 order information: How to add links dynamically?

Hello,

 

 

Please check below XML for same

module-sales\view\frontend\layout\sales_order_guest_info_links.xml

 

 <block class="Magento\Sales\Block\Order\Link" name="sales.order.info.links.invoice">
                    <arguments>
                        <argument name="key" xsi:type="string">Invoices</argument>
                        <argument name="path" xsi:type="string">sales/guest/invoice</argument>
                        <argument name="label" xsi:type="string" translate="true">Invoices</argument>
                    </arguments>
                </block>

In that code

protected function _toHtml()
    {
        if ($this->hasKey()
            && method_exists($this->getOrder(), 'has' . $this->getKey())
            && !$this->getOrder()->{'has' . $this->getKey()}()
        ) {
            return '';
        }
        return parent::_toHtml();
    }

you need to do customize above method for that.

 

If it will help you then mark as a solution or give kudos.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer