2

How do I remove a link from customer menu when customer group is general?

I know about the ifconfig tag, but it does not give me the possibility to hide a custom link when a customer in the general group.

I use Magento 2.2.4.

Customer menu

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Andry
  • 53
  • 1
  • 7

2 Answers2

1
class Current extends \Magento\Framework\View\Element\Html\Link\Current //block
{
    /**
     * @return string
     */
    public function toHtml()
    {
        if (SOME CONDITION HERE) {
            return parent::toHtml(); //show link
        }

    return ''; //hide link
}

//Layout

<referenceBlock name="customer_account_navigation">
        <block class="...\Current" name="customer-account-navigation-product">
            <arguments>
                <argument name="path" xsi:type="string">.../index</argument>
                <argument name="label" xsi:type="string">Product</argument>
            </arguments>
        </block>
    </referenceBlock>
Andry
  • 53
  • 1
  • 7
0

Step 1: First of all, you need a create customer_account.xml in your theme in:

app/design/frontend/_YOUR_VENDOR_/_YOUR_THEME_/Magento_Customer/layout/customer_account.xml

Step 2: Add Remove the link to the file:

To shorten and simplify the story, in the example below I will immediately show you how to delete all links from the navigation one by one.

<!-- Store credit -->
<referenceBlock name="customer-account-navigation-customer-balance-link" remove="true"/>

<!-- Downloadable product link -->
<referenceBlock name="customer-account-navigation-downloadable-products-link" remove="true"/>

<!-- Subscription link -->
<referenceBlock name="customer-account-navigation-newsletter-subscriptions-link" remove="true"/>

<!-- Billing agreement link -->
<referenceBlock name="customer-account-navigation-billing-agreements-link" remove="true"/>

<!-- Product review link -->
<referenceBlock name="customer-account-navigation-product-reviews-link" remove="true"/>

<!-- My credit card link -->
<referenceBlock name="customer-account-navigation-my-credit-cards-link" remove="true"/>

<!-- Account link -->
<referenceBlock name="customer-account-navigation-account-link" remove="true"/>

<!-- Account edit link -->
<referenceBlock name="customer-account-navigation-account-edit-link" remove="true"/>

<!-- Address link -->
<referenceBlock name="customer-account-navigation-address-link" remove="true"/>

<!-- Orders link -->
<referenceBlock name="customer-account-navigation-orders-link" remove="true"/>

<!-- Wish list link -->
<referenceBlock name="customer-account-navigation-wish-list-link" remove="true"/>

<!-- Gift card link -->
<referenceBlock name="customer-account-navigation-gift-card-link" remove="true"/>

<!-- Gift registry -->
<referenceBlock name="customer-account-navigation-giftregistry-link" remove="true"/>

<!-- Reward points -->
<referenceBlock name="customer-account-navigation-reward-link" remove="true"/>

<!-- Order by SKU -->
<referenceBlock name="customer-account-navigation-checkout-sku-link" remove="true"/>

Please view more detail in https://inchoo.net/magento-2/managing-my-account-navigation-links-magento-2/

Mage Wet
  • 186
  • 1
  • 6
  • this code remove link for all customer groups, and i need to remove link for only one customer group. – Andry Jul 20 '18 at 11:05
  • I think you have to overwrite "namespace Magento\Customer\Block\Account;" On this namespace, have a function called "getLinks". you can check if/else on the foreach loop to print or remove the link. – Mage Wet Jul 20 '18 at 14:15