Need a little help with this if statement...

Highlighted
New Member
5 0 0

Hi everyone.  Found this code in the forums, but I am trying to take it one step further.  We offer customers $7.99 flat rate shipping over $25 and free shipping over $100.  so far I have this code by duplicationg it:

{% assign flat_rate_shipping_alert = 15 | times: 100 %}
{% assign cart_total = cart.total_price %}
{% assign flat_rate_shipping_amount = 25 | times: 100 %}
{% assign remaining_amount = flat_rate_shipping_amount | minus: cart_total %}

{% if cart_total >= flat_rate_shipping_alert %}

{% if cart_total >= flat_rate_shipping_amount  %}
You qualify for $7.99 Flat Rate Shipping!
{% else %}
You are {{ remaining_amount | money }} away to qualify for our $7.99 Flate Rate Shipping.

{% endif %}
{% endif %}
              

{% assign free_shipping_alert = 85 | times: 100 %}
{% assign cart_total = cart.total_price %}
{% assign free_shipping_amount = 100 | times: 100 %}
{% assign remaining_amount = free_shipping_amount | minus: cart_total %}

{% if cart_total >= free_shipping_alert %}

{% if cart_total >= free_shipping_amount %}
              
You now qualify for Free Shipping!
{% else %}
You're only {{ remaining_amount | money }} away from receiving Free Shipping.

{% endif %}
{% endif %}

Now for the part I cannot figure out....  When customers finally reach stage 2 Free Shipping ("You're only xxx away from receiving Free Shiping") I want to completely hide the text "You qualify for $7.99 Flat Rate Shipping".  I know I'm missing something but can't seem to figure it out.

Any and all help would be greatly appreciated.

0 Likes
Highlighted
Shopify Partner
1783 211 370

Hey there,

Basically, you should start with checking the free shipping rules and then fallback on the flat rate. As the last step, if the customer qualifies for both flat and free shipping you choose the option that is closer. Below is the code I come up with (not tested) that you can try. I also formatted it a little so it's easier to read:

{% assign free_shipping_alert = 85 | times: 100 %}
{% assign cart_total = cart.total_price %}
{% assign free_shipping_amount = 100 | times: 100 %}
{% assign free_shipping_remaining_amount = free_shipping_amount | minus: cart_total %}

{% if cart_total >= free_shipping_alert %}
	{% if cart_total >= free_shipping_amount %}
		You now qualify for Free Shipping!
	{% else %}
		{% assign flat_rate_shipping_alert = 15 | times: 100 %}
		{% assign cart_total = cart.total_price %}
		{% assign flat_rate_shipping_amount = 25 | times: 100 %}
		{% assign flat_rate_remaining_amount = flat_rate_shipping_amount | minus: cart_total %}

		{% if cart_total >= flat_rate_shipping_alert %}
			{% if cart_total >= flat_rate_shipping_amount  %}
				You qualify for $7.99 Flat Rate Shipping!
			{% else %}
				{% if flat_rate_remaining_amount < free_shipping_remaining_amount %}
					You are {{ flat_rate_remaining_amount | money }} away to qualify for our $7.99 Flate Rate Shipping.
				{% else %}
					You're only {{ free_shipping_remaining_amount | money }} away from receiving Free Shipping.
				{% endif %}	
			{% endif %}
		{% endif %}
	{% endif %}
{% endif %}

 

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
New Member
5 0 0

Just tested it.  Doesn't show any text besides "You qualify for $7.99 Flat Rate Shipping" if I'm over the $25 mark.

Thanks for the help.  I will try and play with your version a little more.

0 Likes
Highlighted
Shopify Partner
1783 211 370

Yes, it also needs to check whether the free shipping alert was not reached before sticking with the flat rate qualification message. Slightly adjusted logic:

{% assign free_shipping_alert = 85 | times: 100 %}
{% assign cart_total = cart.total_price %}
{% assign free_shipping_amount = 100 | times: 100 %}
{% assign free_shipping_remaining_amount = free_shipping_amount | minus: cart_total %}

{% if cart_total >= free_shipping_alert %}
	{% if cart_total >= free_shipping_amount %}
		You now qualify for Free Shipping!
	{% else %}
		{% assign flat_rate_shipping_alert = 15 | times: 100 %}
		{% assign cart_total = cart.total_price %}
		{% assign flat_rate_shipping_amount = 25 | times: 100 %}
		{% assign flat_rate_remaining_amount = flat_rate_shipping_amount | minus: cart_total %}

		{% if cart_total >= flat_rate_shipping_alert %}
			{% if cart_total >= flat_rate_shipping_amount and cart_total < free_shipping_alert %}
				You qualify for $7.99 Flat Rate Shipping!
			{% else %}
				{% if cart_total >= free_shipping_alert %}
					You're only {{ free_shipping_remaining_amount | money }} away from receiving Free Shipping.
				{% else %}
					You are {{ flat_rate_remaining_amount | money }} away to qualify for our $7.99 Flate Rate Shipping.
				{% endif %}	
			{% endif %}
		{% endif %}
	{% endif %}
{% endif %}

 

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
New Member
5 0 0

Still not performing the way it should.  Thank you for your time in trying to help me solve this problem.

0 Likes
Highlighted
Shopify Expert
2684 67 818

I guess you shoud be checking from the most expensive down:

{% assign free_reached 	= 100 | times: 100 %}
{% assign free_alert 	=  85 | times: 100 %}
{% assign flat_reached 	=  25 | times: 100 %}
{% assign flat_alert 	=  15 | times: 100 %}

{% assign cart_total = cart.total_price %}

{% if    cart_total > free_reached %}
    Free Shipping!
{% elsif cart_total > free_alert %}
    {{ free_reached | minus: cart_total | money }} away from Free Shipping.
{% elsif cart_total > flat_reached %}
    Flat rate Shipping!
{% elsif cart_total > flat_alert %}
    {{ flat_reached | minus: cart_total | money }} away from Flat rate Shipping.
{% endif %}

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
I am away till Feb-15.
0 Likes
Highlighted
New Member
5 0 0

BINGO!!!! That code seems to work just like I wanted.  I tried using the Elsif statement but I was keeping the rest to complex.  Easy, simple, and to the point.

Thank you for the help.

0 Likes
Highlighted
New Member
1 0 0

Hello, I was wondering where you put this code to make it work.  I'm trying to change it slightly so that anything over $100 shows as "Shipping: Free" on the actual products page if the price is $100 or more.

Thanks!

0 Likes