skip to Main Content

i’m running a dropshipping store on shopify, dawn theme, where i get the products from 2 different suppliers who obviously ships separate.

I need to add a custom script to check the location.id for each product added into the cart, if the location id are different than i would like to show a notification to the customer saying ” This order will be delivered with 2 separate shipping" so i though to write something like this :

{%- for item in cart.items -%}
    {%- if location.id[i] != location.id[j]-%}
<div><h2>This order will be delivered with 2 separate shipping</h2></div>
{%- endif -%}
    {%- endfor -%}

I’ve looked around but i did not find any solution regarding this matter.
I think the above script should work, but i’m not sure at all (i’m skilled in php, js) but not in liquid.

Is there somebody who can help me to solve this matter?

Moreover, in which file should i add this script?

Thank you in advance

2

Answers


  1. Unfortunately there is nothing within the Shopify Liquid object model present in themes that would let you return the product variants’ inventory location. Neither does any query object exist withing the Storefront API that might enable implementing this requirement.

    Login or Signup to reply.
  2. You can use Shopify Product Metafields that can be set up for each specific product/variant (https://shopify.dev/api/liquid/objects/metafield).

    So adding location id for each product metafield will do the trick

    {% assign suppliersAmount = 0 %}
    {% assign cartSuppliersList = "" %}
    {% for item in cart.items %}
        {% assign productSupplierId = item.product.metafields.my_fields.location %}
        
        {% if cartSuppliersList contains productSupplierId %}
        {% else %}
          {% assign cartSuppliersList = cartSuppliersList | append: productSupplierId %}
          {% assign suppliersAmount = suppliersAmount | plus: 1 %}
        {% endif %}
    {% endfor %}
    
    {% if suppliersAmount > 1 %}
        <div><h2>This order will be delivered with 2 separate shipping</h2></div>
    {% endif %}
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search