I’m creating an internal-use “Dealer Club” using WooCommerce. It will be accessible by our external dealers as well as internal salespeople and admin types.
How do I show select products based on the different types of users (dealers, salespeople, other internal, etc.) and different geographic areas that the individual users service (East, West, all areas)?
The idea that I have so far….
- Create the types of users and geographic areas using Cimy Extra User
Fields plugin. - Tag each product appropriately (type and area).
- Create a page for each product category that somehow queries only
products with the correct tags to the users that match the “extra
user fields”. So only Eastern Salespeople would see items with
tags “east” and “salespeople”, for example. - The problems I see are how to queries the products based on tags,
how to use the Cimy Extra User Fields to determine the
classification of the user, and how to deal with hierarchy issues
(users marked as Salespeople should be able to see all Dealer
products as well).
However, if there is a “canned” solution that handles displaying certain products to certain groups, I’m all ears.
Thanks for suggestions!
Notes about users & roles
WordPress doesn’t have a hierarchical role management system. I don’t even know if there is or ever was a system that had this kind of setup. In general, “role” is just a name for a container that sums up specific capabilities. And those capabilities restrict access to something or grant it.
So above quote simply is a misunderstanding of the concept of roles.
Who has a role, where does it reside, etc.?
A roles is assigned to a user. This is saved as user meta data in the DB and can be changed anytime. Either via code, or via the graphical UI in the admin back end. More can be read in the Codex, which I highly recommend.
Taxons/Terms (of a taxonomy) and Roles
Taxonomies are either flat (like post tags) or hierarchical (like categories) organized Meta Data that can be attached to object types like posts, pages, nav menu items or a custom post type. They can be attached to more than a single type of object to allow you to output archives of multiple object(post) types that share a taxonomy/have a connection.
As we already discussed roles: They aren’t terms/taxons/a taxonomy. Now you’ll have to ask yourself how you’d connect them. Possible ideas:
You can see that there’s no real reliable or easy way to connect them unless you start building a nice UI to handle the task of taxon ID mapping.
Solution/Concept
What you could do is adding an additional user meta field that allows you to enter a specific
template_route
that will then be added as user meta data. Below you’ll find a very simple plugin that adds an additional user meta entry field that allows you to enter atemplate_route
name (should be lowercase and use_
as separators).You can then check for this meta entry in a template like this:
Of course there’re dozens of other ways to do this, but this is the fastest way to approach your problem – just be aware of typos until you don’t modify the output of the field and switch to
select
form field that allows you to select directly from a restricted array. This array should then as well should be accessible in your theme through a public custom API function, so you can avoid the chance of typos there.