Skip to content
Advertisement

Nested shortcode to dynamically display WooCommerce products category

I am attempting to display a WooCommerce product category page based on the current user role.

I have created a custom function get_user_role() to get the user role and added the shortcode [user_role] to fetch this.

If I use the shortcode on a page it successfully returns “administrator” so I can confirm this custom shortcode is working.

I am now having trouble using this shortcode as the category slug.

So what I am trying to achieve is essentially the following:

JavaScript

Advertisement

Answer

May be you are doing it in the wrong way, or may be you need to create an additional shortcode.

So the code should be something like:

JavaScript

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

SIMPLE USAGE (Example):

JavaScript

You can also use all arguments like in the real shortcode.

This code is tested and works. You will get something like this:

enter image description here


Similar answer: WordCommerce shortcode products list

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