I want to show banner on product page using date metafield and I am looking for the liquid code
My metafields are below:
{{ product.metafields.timer_test.image.value }}
{{ product.metafields.timer_test.fr-date.value }}
{{ product.metafields.timer_test.to-date.value }}
How can I make the liquid code on this base?
You can turn all the dates into timestamps (number of seconds), then compare them and see if the "now" timestamp is between the start and end. Just make sure the values in the metafields are properly formatted, for example "Aug 2, 2022".
You can test it here.
{% assign dateStart = product.metafields.timer_test.fr-date.value | date: '%s' %}
{% assign dateEnd = product.metafields.timer_test.to-date.value | date: '%s' %}
{% assign nowTimestamp = 'now' | date: '%s' %}
{% if dateStart < nowTimestamp and dateEnd > nowTimestamp %}
<img src="{{ product.metafields.timer_test.image.value }}" class="banner">
{% endif %}
Related
{% assign price = product.price | money %}
{% capture dot_separator %} <span class='Button__SeparatorDot'></span> {% endcapture %}
{% capture addToCartText %} ADD TO CART {{ dot_separator }} {{ product_price_formatted }} {% endcapture %}
{{ addToCartText }}
My goal is to show the "addToCartText" text this way
Goal: ADD TO CART . 287$
Where the dot is created using css
Right now it's showing like this
Current output: ADD TO CART < span class='Button__SeparatorDot'></ span> 287$
How would I tell liquid to read the html as it is?
Try to use strip_html filter https://shopify.github.io/liquid/filters/strip_html/
like so:
{% capture dot_separator %} < span class='Button__SeparatorDot'></ span> {% endcapture %}
{% capture addToCartText %} ADD TO CART {{ dot_separator | strip_html }} {{ product_price_formatted }} {% endcapture %}
{{ addToCartText }}
I'm really puzzled and can't understand why my {{ time }} returns an empty value.
I'm trying to calculate the difference between the time currently and a booking time in Shopify. For the booking I have the date (first line_item.property) and the time (second one) coming separately. I want to add one to another and then compare it to the current time, but before I can do the math I have tried to display the different variables I have created.
{{ now }} & {{ date }} work fine but for {{ time }} it returns an empty value. On the other hand if instead of assigning it a value name I just display the line.item.property it works just fine.
Can you help me understand what I am doing wrong here?
{% assign today = 'now' | date: '%s' %}
{% for order in customer.orders %}
{%- for line_item in order.line_items -%}
{% for property in line_item.properties limit:1 %}
{% assign date = property.last | date: '%s' %}
{% endfor %}
{% for property in line_item.properties offset:1 %}
{% assign time = property.last | date: '%s' %}
{% endfor %}
{%- endfor -%}
{{ now }} - {{ date }} - {{ time }}
{% endfor %}
By using plus: 0 you can convert the string to integer, this will enable math operation for your comparison.
{% assign today = 'now' | date: '%s' | plus: 0 %}
check with {% unless line_item.properties == empty %} to see if properties exist.
{% assign date = property.last | date: '%s' %} , the variable property.last must follow a well-formatted dates for date to work. liquid-date-format
{% for property in line_item.properties offset:1 %}
{% assign time = property.last | date: '%s' %}
{% endfor %}
problem with offset:1, if the array only has 1 line_item.properties this will not run at all. Hence time is empty; or it exist but property.last does not have a date format.
{% assign today = 'now' | date: '%s' | plus: 0 %}
{% for order in customer.orders %}
{%- for line_item in order.line_items -%}
{% unless line_item.properties == empty %}
{% for property in line_item.properties %}
{% if forloop.index == 1 %}
{% assign date = property.last | date: '%s' | plus: 0 %}
{% if date == 0 %}
{% comment %}Opp! Not A Date, Terminate loop{% endcomment %}
{% break %}
{% endif %}
{% else %}
{% assign time = property.last | date: '%s' | plus: 0 %}
{% unless time == 0 %}
{% assign date = date - time %}
{% endunless %}
{% endif %}
{% endfor %}
{% endunless %}
{% endfor %}
{{today - date}}
Thanks Charles that really unblocked me.
Posting here the final version I went with as I needed to compare exact time and not simply the date of the order.
{% assign now_date = 'now' | date: '%s' | plus: 0 %}
{% assign now_time = 'now' | date: '%s' | plus: 0 %}
{% for order in customer.orders %}
{%- for line_item in order.line_items -%}
{% for property in line_item.properties limit:1 %}
{% assign booking_date = property.last | date: '%s' | plus: 0 %}
{% endfor %}
{% for property in line_item.properties offset:1 limit:1 %}
{% assign booking_time = property.last | date: '%s' | plus: 0 %}
{% endfor %}
{% assign date_to_compare = booking_date | plus: '86400' %}
{% unless now_date > date_to_compare %}
{% if now_time <= booking_time or now_date <= booking_date %}SEANCE A VENIR{% endif %}
{% endunless %}
{%- endfor -%}
{% endfor %}
I am working a shopify shop but not trying to sell products but rather appointments.
I am using a shopify extension called Sesami to do so.
In the customer/account.liquid page I want to show the next coming appointment (or appointments) and a different information to people who don't have any future appointment coming.
I have been trying to do this with the following code :
{% if customer.orders != blank %}
{% for order in customer.orders %}
{%- for line_item in order.line_items -%}
{% for property in line_item.properties limit:1 %}
{% assign today_date = 'now' | date: '%s' %}
{% assign pre_date = property.last | date: '%s' %}
{% if pre_date >= today_date %}
{{ line_item.product.title | link_to: line_item.product.url }}
{% for property in line_item.properties limit:1 %}
{% if property != blank %}
{{ property.last | date: format: 'abbreviated_date' }}
{{ 'customer.orders.at' | t }}
{% endif %}
{%- endfor -%}
{% for property in line_item.properties offset:1 %}
{{ property.last }}
{%- endfor -%}
{{ line_item.image | img_url: 'small' | img_tag }}
{{ order.fulfillment_status_label }}
{% endif %}
{% endfor %}
{%- endfor -%}
{% endfor %}
{% else %}
Content for people with no booking at all
{% endif %}
But the problem is that the forloop stays open and therefore shows the content I am hoping to display to people with no upcoming appointment multiple times based on the total number of past appointments.
I imagine there is a much simpler way to do this and am hoping you can help me find it !
Thanks a lot,
Julien
Consider using {% break %} when you'd like the loop to stop it's current iteration.
https://shopify.github.io/liquid/tags/iteration/#break
I have a store with 10 products.
One of them is a subscription for a magazine, with 3 variants: 6 months, 1 year and 2 year
I made the product page with a custom template and i inserted the prices with simple html as so:
Price: 25 $ and so on for the other variants...
Now i'm doing some promos so i would like to have the price updating without having to change it in the theme, i was trying something like that to make it work but without success:
{% assign semestraleid = '18773651783776' %}{% variant.id == semestraleid %} {{ current_variant.price | money }} {% if current_variant.compare_at_price > current_variant.price %} <s style="color: #B8DAEE; font-size: 0.85em;">{{ current_variant.compare_at_price | money }}</s> {% endif %} {% endif %}
So here is the question: HOW CAN I DISPLAY THE REAL PRICE OF EACH VARIANT IN THIS ONE-PAGE PRODUCT PAGE, EXACTLY WHERE I WANT WITH A CODE SNIPPET?
Thank you
PS: I've also tried doing some other experiments using the assign and split, i have succeded into printing the price of every variant all together, but after that i didn't know how to show the price correctly as i would like.
Loop through each of the Product's Variants and output the price:
{% for variant in product.variants %}
{{ variant.price | money }}
{% endfor %}
... or output each one separately using its index:
{{ product.variants[0].price | money }}
{{ product.variants[1].price | money }}
{{ product.variants[2].price | money }}
[index is zero-based]
We have a group of products that we want to have FREE Shipping. In order to do so, I have made their weight =0 and created a weight based shipping for 0lbs.
That way the shipping passes through the cart. But...I would like to display the actual weight on the product page.
I have created a metafield for the shipping weight, and I am trying to call that value to the product page, but not having any luck......
Here is what I am trying for code....
//------SHIPPING WEIGHT-------------------------//
{% if product.vendor == 'American Chains' %}
$('.wt').text((variant.ShippingWeight)+'lb');
// {{ variant.metafields.ShippingWeight.shipping_weight }}
{% else %}
$('.wt').text(parseInt(variant.weight * 0.0022046, 10) + 'lb');
{% endif %}
//------SHIPPING WEIGHT-------------------------//
Thanks for any help or direction on this one.
In Product.liquid you only have access to the Product. If you want to access a specific Product Variant you have to loop through the Product Variants. Within the loop you have access to the metafields for a variant.
{% for variant in product.variants %}
// to display the variant metafields use {{resource.metafields.namespace.key}}
{{ variant.metafields.ShippingWeight.shipping_weight }}
{% endfor %}
http://docs.shopify.com/themes/liquid-documentation/objects/metafield
go threw with this link
simple...
{% for field in product.metafields.instructions %}
{{ field | first }}: {{ field | last }}
{% endfor %}
Meta fields are created by using ( metafields or shopify FD ) shopify app for products edit page
Then enter the following values in form fields (Namespace,Key,Value)
After entering values,you can retrive values like following code..,
Namespace = metafield_values,
Key= color,
Value= red,
{% assign value = product.metafields.metafield_values%}
<p>{{ value.color }}</p>
output: red
------------------------------
{{metafields.namespace.key}}
------------------------------
Namespace = prod_video,
{{ product.metafields.prod_video.prod_video }}
{{ collection.metafields.prod_video.prod_video }}
---------metafield loop with same namespace & different key------------
<div class="prod_add_img">
{% for collection in product.collections %}
{% for field in collection.metafields.additional_images %}
<img src="{{ field | last | asset_url }}">
{% endfor %}
{% endfor %}
</div>
In metafield section, shopify show's shortcode. For below screenshot the code is
{{product.metafields.custom.theme_color}}