Skip to content
Advertisement

WooCommerce: Display My Account link only for specific user role

I want to display the subscription link in the WooCommerce My Account navigation only to a specific user role. But I couldn’t figure out how to change the navigation in that way.

I found a solution to change the order of the menu items. And I found a solution to add custom links to the navigation. But unfortunately I couldn’t combine these two to a working snippet.

Here’s the code to change the order:

JavaScript

Because the links are in an array, I couldn’t use if/else to check the user role.

Here’s an example to add custom links to the navigation: (from here: https://rudrastyh.com/woocommerce/my-account-menu.html#add_with_url)

JavaScript

But the subscription endpoint already exists. So I don’t know how to add it in this way.

Any ideas?

Advertisement

Answer

Sorry, I found a solution.

The following code does the trick:

JavaScript

I just need to add the existing endpoint.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement