Skip Navigation

[Resolved] one to many USER Relationships?

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1270001

I am using Woocommerce to set up a Sales rep Portal. I was wondering if it is possible to set up a Parent Child relationship. I want to set up a user Role "Sales Reps" who can be the Parent to many woocommerce "Customers" and can view orders and bio information of customers they own but not other customers.

#1270063

Hi, there's nothing exactly like this built in to Types, but as a simple workaround you could use a custom field on each Customer's profile to store a number. In each Sales Rep's profile, you would have the same custom field. Then when the Sales Rep logs in, they would see a filtered list (a View) of Users who have the same custom field value as the Sales Rep's own custom field value. In the View you can display each Customer's information from custom fields or wherever it is managed. Let me know if you have questions about that.

This is just on the front-end of the site, though. It's not really possible to set up this kind of User restriction in wp-admin using Toolset plugins, some custom code would be required.

#1271037

I think I am doing something similar. I created a Post Type called "Clients" and a one-to-many relationship of clients to Orders. So a Sales Rep can add clients, place orders and then manually assign orders to their clients. I am going to try to set up views so that they can only view their clients, and their clients orders.

Do you know if it possible to assign an "order" to a Parent with a custom field at checkout or can it only be assigned after the Order is saved?

#1271061

If you're talking about a Toolset post relationship between Clients and Orders, then I'm not sure how that would work. Toolset doesn't hook into the checkout screen, and you would have to create a dynamic field to select a parent Client. Then you would have to use some PHP to process that selection and use the post relationships API to connect the posts. I can help with the post relationships API, but the rest is outside of Toolset's realm.

#1275751

Ok, I am testing both options. For your original suggestion to add a number, [types usermeta='rep-id-number' ][/types], to all customers that matches the sales rep, I built a view of customers that contain that number and it works but how do I display the customer information like billing and shipping fields in a view? I have activated some of the hidden fields...
_billing_address_1
_billing_city
_billing_company
_billing_country
_billing_email
_billing_first_name
_billing_last_name

but i can't get them to show in a view. I tried each of the following....

<td>[wpv-user field="_billing_company"]</td>
<td>[wpv-user-field name="_billing_company"]</td>

Also, Will I be able to have the Reps view the orders associated with those customers? Basically build a view where the rep can view all orders where a customer rep-id-number is theres?

#1275861

There's no underscore before the billing company slug, so this will work:

<td>[wpv-user field="billing_company"]</td>

Will I be able to have the Reps view the orders associated with those customers? Basically build a view where the rep can view all orders where a customer rep-id-number is theres?
Not directly, but you can use two nested Views to accomplish the same thing. First you must make the WC hidden field "_customer_user" visible to Views. Then create a View of Customers related to the Sales Rep, like you have already created. Next you would create a View of Orders, filtered by the _customer_user custom field, set by a shortcode attribute like "customer". Add another filter by post status, and choose one or more of the valid WC Order statuses you can find in the "Creating a View to display WooCommerce Orders" section here:
https://toolset.com/documentation-category/woocommerce-views/
In the Loop Output, you can insert the post title shortcode to display the Order date and time, or the post ID shortcode to display the Order ID, or post status, etc.

Nest this View of Orders inside the View of Customers, and set the shortcode attribute "customer" using the current Customer's ID. This technique is called passing arguments to Views, and it's explained in more detail here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/
If you need help with that I'm glad to assist.

#1276027

I kind of get the nesting but how would it work with "Current customer". I see how to do something like this to show customer #5 orders manually...

[wpv-view name="woocommerce-orders" customer="5"]

Is there a way for me to basically build a Content Template for each User and on the content Template show orders associated to each User?

#1276035

You would use another shortcode that provides the current User's ID. If you use this shortcode in a View of Users, it will be relative to the current User in the Loop. If you use it outside a View of Users, it will be relative to the current logged-in User:

[wpv-view name="woocommerce-orders" customer="[wpv-user field='ID']"]