Showing custom form in cart depending on cart content

Highlighted
New Member
2 0 0

Showing custom form in cart depending on cart content

We have a store, with two different lines of products, Home Decor and flower shop. When a customer put any of the flowers products in the card, we need to collect additional info (to whom they are sending the flowers, the delivery date, the message they want to put in the cart, etc.). When they order products from Home Decor we do not collect that info.

We manage to show the form using the "cart.item" and is working: It shows the form only when we add one of the "Flower" products but not when we add other products. However, if we deleted the flower product from the cart, the form does not disappear, the condition is not updated.

Any help would be greatly appreciated.

Here is the code we included in the cart_main.liquid:

{% assign products_flower_shop = 0 %}
{% for item in cart.items %}
  {% for collection in item.product.collections %}      
    {% if collection.title == 'Sympathy' or collection.title == 'Flowers Arrangements' or collection.title == 'Plants & Zen Gardens'%}
      {% assign products_flower_shop = products_flower_shop | plus: item.quantity %}
    {% endif %}
  {% endfor %}
{% endfor %}      
    
{% if  products_flower_shop > 0  %}
  {% include 'form_flower_shop' %}
{% endif %}


And this is the Snippet we are using to call the form.

form_flower_shop.liquid

          <div class="cart__cost-summary container is-flex-column">
              <h3>Enter Delivery Information</h3>
          </div>
        <p><label><h4>*Delivery Date:</h4></label></p>
        {% render 'delivery-date' %}<br>
        <p class="cart-attribute__field">
		  <input type="hidden" name="attributes[Send an email to remind me of this occasion annually]" value="No">
		  <input type="checkbox" name="attributes[Send an email to remind me of this occasion annually]" value="Yes"{% if cart.attributes["Send an email to remind me of this occasion annually"] == "Yes" %} checked{% endif %}>
          <label>Send an email to remind me of this occasion annually</label>
	    </p><br>
        <p class="dotted">MONDAY-FRIDAY Orders must be placed before 12:00 pm in the recipient's time zone for same-day delivery. SATURDAY & SUNDAY Orders must be placed before 12:00 pm in the recipient's time zone for same-day delivery</p>
        <div class="cart__cost-summary container is-flex-column">
            <h3>Write a Note</h3>
        </div>
	  <p class="cart-attribute__field">
		<label><h4>*What is the Occasion: </h4></label>
		  <select required class="required" id="massage-from-eg-love-jhon" name="attributes[Massage From: (e.g. love, jhon)]">
			<option value="" disabled selected >Please Select...</option>
			<option value="4th of july"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "4th of july" %} selected{% endif %}>4th of july</option>
			<option value="Anniversary"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Anniversary" %} selected{% endif %}>Anniversary</option>
			<option value="Birthday"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Birthday" %} selected{% endif %}>Birthday</option>
			<option value="Business Gift"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Business Gift" %} selected{% endif %}>Business Gift</option>
			<option value="Congratulations"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Congratulations" %} selected{% endif %}>Congratulations</option>
			<option value="Get Well"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Get Well" %} selected{% endif %}>Get Well</option>
			<option value="Graduation"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Graduation" %} selected{% endif %}>Graduation</option>
			<option value="Good Luck"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Good Luck" %} selected{% endif %}>Good Luck</option>
			<option value="Housewarming"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Housewarming" %} selected{% endif %}>Housewarming</option>
			<option value="I'm Sorry"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "I'm Sorry" %} selected{% endif %}>I'm Sorry</option>
			<option value="Just Because"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Just Because" %} selected{% endif %}>Just Because</option>
			<option value="Love and Romance"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Love and Romance" %} selected{% endif %}>Love and Romance</option>
			<option value="New Baby"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "New Baby" %} selected{% endif %}>New Baby</option>
			<option value="New Home"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "New Home" %} selected{% endif %}>New Home</option>
			<option value="New job"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "New job" %} selected{% endif %}>New job</option>
			<option value="Other"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Other" %} selected{% endif %}>Other</option>
			<option value="Retirement"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Retirement" %} selected{% endif %}>Retirement</option>
			<option value="Sympathy"{% if cart.attributes["Massage From: (e.g. love, jhon)"] == "Sympathy" %} selected{% endif %}>Sympathy</option>
		  </select>
	  </p><br>
        <p class="cart-attribute__field">
          <label for="your-massage"><h4>*Your Massage: </h4></label>
		  <textarea required class="required" id="your-massage" name="attributes[Your Massage: ]" maxlength="59" cols="70" rows="4">{{ cart.attributes["Your Massage: "] }}</textarea>
	    </p><br>
	    <p class="cart-attribute__field">
          <label for="massage-from-eg-love-jhon"><h4>*Massage From: (e.g. love, jhon)</h4></label>
		  <input required class="required" id="massage-from-eg-love-jhon" type="text" maxlength="60" name="attributes[Massage From: (e.g. love, jhon)]" value="{{ cart.attributes["Massage From: (e.g. love, jhon)"] }}">
	    </p>

 

0 Likes