How can I block direct URL access to specific products?

How can I block direct URL access to specific products?

YogaBear
Excursionist
34 2 5

Hello all,

I have created a private collection where the products in this collection are only meant for wholesalers and only when they are logged in they can see the collection and all the products in them via code.

But at the same time, I am able to enter the exact product page via direct product URL without having to go through the collections page or the protected collection and it will be visible to anyone

For example : store-name.com/products/product-name

Is there anyway to restrict a direct URL access to these products via code? 



Replies 2 (2)

ProtoMan44
Shopify Partner
610 54 92

@YogaBear

{% if customer %}
  {% if collection.title == 'Your Collection Name' %}
    <p>This content will be displayed for logged-in customers in the 'Your Collection Name' collection.</p>
  {% else %}
    <p>This content will be displayed for logged-in customers not in the 'Your Collection Name' collection.</p>
  {% endif %}
{% else %}
  <p>This content will be displayed for visitors (not logged in).</p>
{% endif %}
- A thirsty developer passionate about supporting the community. If you'd like to, you can  

Buy me a Coffee.


- Your Shopify Solution Specialist Get a Quote at

ProtoMan44

 - 

Chat On Whatsapp


Crafting exceptional e-commerce experiences to elevate your online presence. Let's build your success story together!
YogaBear
Excursionist
34 2 5

Hi ProtoMan44,

Where do I paste this code? Sorry I am not very good with the coding but I am able to learn fast.

Just to also check does this code only block them from viewing the whole collection or they will not be able to use direct URL anymore as well? 

Because I already made it so that they are not able to access the collection if they are not logged in. 
But for e.g if someone who has access to that collection , can access the direct product url of that page and give it to someone without access to the collection, they can still check out that product in their cart.