0

How can I make a custom link in customer account navigation visible to certain customers only?

Example: I have a link labeled "Ticket management". If a user clicks on that he is redirected to a page where he can view and edit tickets. I want only display this link to customers that have a certain custom variable set.

Can I specify this in customer_account.xml or somewhere else?

This is my customer_account.xml:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-tickets-link">
                <arguments>
                    <argument name="path" xsi:type="string">ticket_module/index/display</argument>
                    <argument name="label" xsi:type="string">Tickets</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

1 Answer 1

1

Check the class

/vendor/magento/module-customer/Block/Account/Navigation.php

ans the function getLinks() where all the customer account links are collected. Then using a reference or a plugin you can extend the functionality of the getLinks() function, and check if the customer has a certain custom variable set, and if not then skip this link.

0

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.