Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, I have a product page that can only be shown to some customers... which we have setup without any issue. But now, we also need to allow logged in store employees and the store owner to access that product page.
Is there a way to tell in liquid when either one of those (employees or owner) are logged in the admin side of Shopify?
Or is there a specific cookie I should look for?
Thanks so much!
Similar post as https://community.shopify.com/c/technical-q-a/detect-admin-shop-owner-logged-into-store/m-p/569714. I put a reply there, which isn't a solution but has some additional details.
Thank you so much for your reply! I did read your post before submitting mine.
I got frustrated not finding a Shopify native way to do this. So I ended up creating a new customer, which I'm treating as a master customer. On the front end, when I detect that the logged in user has the 'master customer' ID, I'm able to perform certain business logic operations. I think this approach it's a little faster to implement than trying to read cookies from the admin side --which involves more setup and testing.
Thanks so much!!
I answered the question that the other user linked but for completeness sake here is an example that suits your use case.
You can use the content_for_header liquid object details to detect admin inside liquid code blocks.
The following example snippet will only include the example div for admin users.
{% if content_for_header contains 'adminBar' %}
<div>Admin Detected</div>
{% endif %}
The code does not get included for regular visitors, just for admins.
Update: By October 2024 the snippet must check for previewBar instead of adminBar:
{% if content_for_header contains 'previewBar' %}
<div>Admin Detected</div>
{% endif %}
As of October 2024, this still works, but will only detect the admin in "Preview Mode" when previewing new themes or theme changes from the editor. If the admin is browsing the site normally, the preview bar is not output, and the `adminBar` we used to test for is gone.
We hope Shopify has a replacement for this functionality soon, it's an often requested feature from our clients (show something to admins only etc)
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024