Shopify themes, liquid, logos, and UX
Hi community,
i need to command the show/hide suggested product in cart from metafields (if it is already in cart), but it seems like i can't access metafields from cart.
the store is https://www.7amenfant.com with Prestige Theme
this is the simple code:
{%- assign in_cart = 0 -%}
...
{%- for item in cart.items -%}
{%- if item.products.metafields.global.cross_sell == 'example' -%}
{% increment in_cart %}
{%- endif -%}
{%- endfor -%}
...
{%- if in_cart == 0 -%}
{%- include 'CUSTOM_CODE' -%}
{%- endif -%}
But the variable in_cart is always 0
thanks
Solved! Go to the solution
This is an accepted solution.
Hi jason, thanks
I solved in this way:
{%- assign in_cart = true -%}
....
{%- for line_item in cart.items -%}
{%- if line_item.variant.metafields.global.cross_sell == 'true' -%}
{%- assign in_cart = false -%}
{%- endif -%}
{%- endfor-%}
....
{%- if in_cart == true -%}
{%- include 'upsell' -%}
{%- endif -%}
It would not be:
item.products
But rather:
item.product
Try that minor adjustment and see if you get better results.
This is an accepted solution.
Hi jason, thanks
I solved in this way:
{%- assign in_cart = true -%}
....
{%- for line_item in cart.items -%}
{%- if line_item.variant.metafields.global.cross_sell == 'true' -%}
{%- assign in_cart = false -%}
{%- endif -%}
{%- endfor-%}
....
{%- if in_cart == true -%}
{%- include 'upsell' -%}
{%- endif -%}
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024