<p>Depends on whether the user field is on the product or a variant.</p>

<p>If the custom field is on the product:</p>

<pre><code>{% set products = craft.commerce.products.relatedTo({
    sourceElement: currentUser,
    field: 'userFieldName'
}) %}
</code></pre>

<p>If the custom field is on the variant:</p>

<pre><code>{% set variantCriteria = craft.commerce.variants.relatedTo({
    sourceElement: currentUser,
    field: 'userFieldName'
}) %}

{% set products = craft.commerce.products.hasVariant(variantCriteria) %}
</code></pre>

CC BY-SA 3.0
2017-02-20T15:18:16.060Z
The custom field is on the product. I should have added, that I previously attempted your first suggestion, but it didn't return any results.
JackO
CC BY-SA 3.0
2017-02-20T15:09:03.453Z
2017-02-20T15:09:03.453Z
Luke Holder
<p>I have a custom field enabled on a product - it is a user field that associates a product with a user.</p>

<p>What would the correct setup be to only display products that pertain to the currentUser - as this would match the custom user field?</p>

<plugin-craftcommerce><custom-field>
Show products based on custom field
# Show products based on custom field

(Asked by: username_0 on 2017-02-20)

I have a custom field enabled on a product - it is a user field that associates a product with a user.

What would the correct setup be to only display products that pertain to the currentUser - as this would match the custom user field?

**Tags:** plugin-craftcommerce, custom-field

---

## 1 answers

### Answer by username_1 on 2017-02-20. Score: 1

Depends on whether the user field is on the product or a variant.
If the custom field is on the product:
{% set products = craft.commerce.products.relatedTo({
    sourceElement: currentUser,
    field: 'userFieldName'
}) %}

If the custom field is on the variant:
{% set variantCriteria = craft.commerce.variants.relatedTo({
    sourceElement: currentUser,
    field: 'userFieldName'
}) %}

{% set products = craft.commerce.products.hasVariant(variantCriteria) %}

> **Comments:**
> **username_0**: The custom field is on the product. I should have added, that I previously attempted your first suggestion, but it didn't return any results.  

---

