Shopify: Order Print App is not picking up variables - shopify

I am trying to display a Final Sale message on order receipts for products that are 60% off. This bit of code does display the message on the individual product page, but when I insert in the template I'm using in the Order Printer app, the message does not seem to display.
I've contacted various Shopify support people, but they have not been able to identify the problem. Here's the code I'm inserting:
<!--if item is 60% off, it displays message: -->
{% if product.compare_at_price %}
{% assign sixtyPercentOff = product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price | round %}
{% if sixtyPercentOff == 60 %}
<p style="color: #B21F1F;">
This item is final sale -- no returns or exchanges are accepted.
</p>
{% endif %}
{% endif %}
Is it because Order Printer does not recognize variables such as "compare_at_price"?

product.compare_at_price doesn't exist.
For product you have: compare_at_price_max, compare_at_price_min, compare_at_price_varies
Do you mean to use something like: {% if product.compare_at_price_min > 0 %}
Or if you have variants you can use directly variant.compare_at_price
For first available variant of product: {% if product.variants[0].compare_at_price > 0 %}

Related

Liquid coding (Shopify) "and" and "elsif" not functioning together

I'm new to liquid coding while starting my own Shopify store (although I had some experience with coding). I'm currently stuck trying to get this code to function. I've added 3 text options in the liquid file for each variable. The idea is that when the criteria are met, it would display the appropriate text option. Please see the code string here for ref.
{% if section.settings.free_shipping_announcement_bar %}
{% assign promote_text = section.settings.promote_free_shipping_text | escape %}
{% assign unlocked_text = section.settings.unlocked_free_shipping_text | escape %}
{% assign unlocked_del_text = section.settings.unlocked_free_delivery_text | escape %}
{% assign threshold = section.settings.free_shipping_threshold | times: 100 %}
{% assign value_left = threshold | minus:cart.total_price %}
{% assign value_left_money = value_left | money %}
<div class="announcement-bar">
{% if value_left <= 0 %}
<p class="announcement-bar__message">{{unlocked_text}}</p>
{% elsif value_left >= 1 and value_left < 50 %}
<p class="announcement-bar__message">{{unlocked_del_text}}</p>
{% else %}
<p class="announcement-bar__message">{{promote_text | replace:'(value)' , value_left_money}}</p>
{% endif %}
basically, the idea is if the cart total is between $0-$99 I will show the "promote_text", if it's between $100-$149 it will show the "Unlocked_free_del_text"(free delivery), then at $150+ in the cart it shows "unlocked_text".
It currently shows the "promote_text" from $0-$149 then changes directly to the "unlocked_text" and skips the middle section for "unlocked_del_text"
my best assumption is that I'm using the elsif function wrong but I've trailed as many adjustments as I can think of without breaking the code, so any advice would be greatly appreciated!
Update:
After checking and testing the code over dev store I find you need to use divided_by to value_left value to compare with the value into normalized format.
so your code needs an update to this line
{% assign value_left = threshold | minus:cart.total_price | divided_by: 100%}
becase case is multile of 100 to process to cart value and need to normalized before test into if else condition.
The code looks great, I am not sure why this not works properly, you can check and try in this way also and I hope it will work. overwise you need to post the whole code along with schema and anyone replicate it dev store and find the solution.
{% if section.settings.free_shipping_announcement_bar %}
{% assign promote_text = section.settings.promote_free_shipping_text | escape %}
{% assign unlocked_text = section.settings.unlocked_free_shipping_text | escape %}
{% assign unlocked_del_text = section.settings.unlocked_free_delivery_text | escape %}
{% assign threshold = section.settings.free_shipping_threshold | times: 100 %}
{% assign value_left = threshold | minus:cart.total_price | divided_by: 100%}
{% assign value_left_money = value_left | money %}
<div class="announcement-bar">
{% if value_left <= 0 %}
<p class="announcement-bar__message">{{unlocked_text}}</p>
{% elsif value_left >= 1 and value_left < 50 %}
<p class="announcement-bar__message">{{unlocked_del_text}}</p>
{% else %}
<p class="announcement-bar__message">{{promote_text | replace:'(value)' , value_left_money}}</p>
{% endif %}
</div>
{% endif %}
Thanks for the quick response! I trialed the snippet you added but unfortunately ran into the same issue. here is the schema that I added to impact the section of code I input. If you are able to spot a simple issue in here please let me know, otherwise, I will continue to troubleshoot personally and hopefully find a solution or alternate method, to avoid troubling someone with having to replicate the entire code to recreate the issue.
{
"type":"checkbox",
"label":"enable free shipping bar",
"id":"free_shipping_announcement_bar",
"default":false
},
{
"type":"text",
"id":"promote_free_shipping_text",
"label":"message to promote free shipping"
},
{
"type":"text",
"id":"unlocked_free_shipping_text",
"label":"message for unlocked free shipping"
},
{
"type":"text",
"id":"unlocked_free_delivery_text",
"label":"message for unlocked free delivery"
},
{
"type":"range",
"id":"free_shipping_threshold",
"label":"threshold for free shipping",
"min":0,
"max":200,
"step":5,
"unit":"$",
"default":150
}

Shopify order email template sometimes prints transaction twice

Sometimes (often, but randomly), the order confirmation prints out the payment gateway twice:
Payment
Credit card – 36.90
Credit card – 36.90
I've confirmed that real money is not being transferred twice. But could the transaction count be higher anyways? I'm not so sure about how the transaction_count works, and I don't really know how to debug this.
This part is the problem (I don't see where else it could be):
{% assign transaction_count = transactions | size %}
{% if transaction_count > 0 %}
<h4>Payment</h4>
{% for transaction in transactions %}
{% if transaction.status == "success" or transaction.status == "pending" %}
{% if transaction.kind == "authorization" or transaction.kind == "sale" %}
<p>
{{ transaction.gateway | replace: "_", " " | capitalize }}
—
<strong>{{ transaction.amount | money }}</strong>
</p>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
I've custom built the whole shop, but I can't seem to understand why this is happening.
I'm stumped, I've reached out to Shopify support but they don't want to help because I have added some custom html in the Order Notification email.
A huge thanks for anybody that could help me with this!
There is no other explanation than to assume that in
transactions there are more than one transactions. You can double check the transaction variable and see where the double identical transactions are coming from.

donation counter on starting page

I need a donation counter (total sum), which shows on the starting page and on a specific page. My problem here is, that I included a snippet to get the total donation and these donations come from one specific product. I managed to get to get the total sum of donations and I can display it on the product page. But I want to display it on the startpage and on a specific page. I wrote a product-sold-count.liquid as following:
{% assign productStartCount = product.metafields.stock.initial | times:1 %}
{% if productStartCount > 0 %}
{% assign productInventory = product.variants.first.inventory_quantity %}
{% assign totalSum = productStartCount | minus:productInventory | times: product.price | times: product.metafields.donation.percent | divided_by: 10000 %}
<p>{{ totalSum }} € were donated until now!</p>
{% endif %}
Now I want to get this totalSum to another page or more likely to the start page and to other pages? I tried: {% include 'product-sold-count' %} on the specific liquids like page.liquid or theme.liquid but that won't work. How can I achieve this?
The problem is on product page, you have the variable product. But on other pages, this variable is longer valid.
In order to have total count for all product, you can repeat the above code for each product and get the sum of all products. Note that Shopify provide all_products variable, but limit to 20 products per page. You can use collection.products if it's on a collection (or, assign all donation products to donation collection then get all products of this collection)
{% assign allProductCount = 0 %}
{% for product in all_products %}
{% assign productStartCount = product.metafields.stock.initial | times:1 %}
{% if productStartCount > 0 %}
{% assign productInventory = product.variants.first.inventory_quantity %}
{% assign totalSum = productStartCount | minus:productInventory | times:
product.price | times: product.metafields.donation.percent | divided_by: 10000 %}
{% assign allProductCount = allProductCount | plus: totalSum %}
{% endif %}
{% endfor %}
<p>{{ allProductCount }} € were donated until now!</p>

Shopify Inventory Display Output on Product Page

I've spent much of the day setting up a new shopify site - my first experience with shopify. Most of it has been pretty straightfoward, but I've found myself somewhat stumped when it comes to showing inventory on the product pages. I'm using the debut theme, and using the editor to update 'product-template.liquid'
After browsing the docs, I've added the following;
{% comment %} Inventory tracking on product page {% endcomment %}
<div id="variant-inventory" class="{% unless current_variant.available %} hide {% endunless %}">
{% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
{% else %}
Out of Stock
{% endif %}
</div>
However, this is currently returning 'out of stock' for items that are in fact, in stock. In addition, what I am hoping to achieve but haven't been able to find documentation for is;
'Items in stock' = We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
'No inventory, but customer allowed to order' = Order now for delivery within 7 days
'No inventory, customer not allowed to order' = Out of Stock
Any pointers much appreciated!
You have:
{% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
{% else %}
Out of Stock
{% endif %}
This will show the 'Out-of-Stock' message for either of the following conditions:
inventory_management is blank (which is the default value)
inventory_policy is continue
What you probably wanted was something like this:
{% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
{% comment %}
We care about inventory on this product - is there any in stock?
{% endcomment %}
(% if current_variant.inventory_quantity > 0 %}
We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
{% else %}
Out of Stock
{% endif %}
{% else %}
{% comment %}
Any code/messages we might want for products where we don't care about inventory
{% endcomment %}
{% endif %}
I'm a little puzzled by this line of code:
{% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
What you are checking is if you are using shopify to track inventory and if the variant options command to allow people to order even if it is out of stock is checked in the admin panel. I would assume that the latter is checked so it is always returning the else.
If it wasn't in stock nothing would show due to this line:
div id="variant-inventory" class="{% unless current_variant.available %} hide {% endunless %}">
As I am unsure how you plan to differentiate between the out of stock and the out of stock can order in 7 days. As there is nothing in the inventory tracker that allows you to enter incoming product (As far as I know). If you were so inclined to enter this manually you could go to product.template.liquid find Ctrl + F
{% unless current_variant.available %}
The Second one down is where to sold-out code takes place
and edit it through adding and removing tags (Using noOrder and noStockCanOrder as example tags)
{% if product.tags contains 'noOrder' %}
<div>No inventory, customer not allowed to order' = Out of Stock</div>
-Insert Current out of stock code here-
{% elsif product.tags contains 'noStockCanOrder' %}
<div>No inventory, but customer allowed to order' = Order now for delivery within 7 days</div>
-Insert Current in stock code here-
{% else %}
<div>Items in stock' = We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.</div>
-Insert Current in stock code here-
{% endif %}
You may have to play around with this a little bit as I have never done exactly what you are asking but the theory should be sound and it should get you close to what you want and you can edit it from there.

Shopify Sold Out Message

I'm trying to display a sold out message when we set a product's quantity to 0. This bit of liquid code of kinda worked:
`{% assign variantQuantity = product.variants | map: 'inventory_quantity' | sort %}
{% if variantQuantity[0] < 1 %}
<strong><p style="color: #B21F1F;">This item is currently sold out.</p></strong>
{% else %}
{% endif %}`
The problem is it displays the sold out message when even one size is out of stock and other sizes are not. Is there a way to check and make sure all sizes are sold out?
You can just check the product.available attribute:
product.available
Returns true if a product is available for purchase. Returns false if
all of the products variants' inventory_quantity values are zero or
less, and their inventory_policy is not set to "Allow users to
purchase this item, even if it is no longer in stock."
So you can use for example:
{% if product.available == false %}
This item is currently sold out.
{% endif %}
have you tried the multiple checks in the manual?
{% if variant.inventory_quantity <= 0 and variant.available and variant.inventory_management != '' %}
so example being:
{% assign variantQuantity = product.variants | map: 'inventory_quantity' | sort %}
{% if variant.inventory_quantity <= 0 and variant.available and variant.inventory_management != '' %}
<strong><p style="color: #B21F1F;">This item is currently sold out.</p></strong>
{% else %}
{% endif %}