Newbie Question : How to set initial value of a variable ?

Solved
Highlighted

Hi, sorry for such basic question.

 

To my logic work in product.liquid I need a variable that must keep his value while customer navigates on several product pages.

 

How can I make sure  to INITIAL value be defined only once for each user session ?

 

Best REgards 

William Alencar
GoodFy Brasil
0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

Hey @GoodFy_Brasil,

 

JavaScript + local storage might be the best way to go here. Can you elaborate on the problem you're trying to solve?

Notice; Out of office, replies will be delayed until my return. Thanks!
Highlighted

Hi @SBD_ thanks per contribution.

 

Passed this time the need I have is better described like this :

 

With a Pop Up at home page ( or any other way to get customer visitor input ) capture customer response about which region are him/her in Brasil ( 5 possibilities only ) .

 

With that value ... use in the code of Product and Cart page to calculate how much visitor should expend to get FREE SHIPPING .

 

Thats what I need. 

Best Regards 

William Alencar
GoodFy Brasil
0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

This is an accepted solution.

Thanks for the info. For that information to persist, one approach would be to store the value in local storage.

 

localStorage.setItem('region', 'some-region')

 

Then on the product/cart page you could retrieve the value using getItem:

var region = localStorage.getItem('region')
Notice; Out of office, replies will be delayed until my return. Thanks!
Highlighted

Hey @SBD_  thanks again ...

 

This is Javascript correct ?

 

just one more question . CAn i insert javascript direct into liquid code ?  ( sorry if is a stupid question but ... I do prefer learn fast than try hide my doubts :-))))

 

 

William Alencar
GoodFy Brasil
0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

Hey @GoodFy_Brasil,

 

You can insert JavaScript into your theme, it might looks something like this (product.liquid):

 

{{ product.title }}

<script>
// Some JavaScript
</script>

 

 

Notice; Out of office, replies will be delayed until my return. Thanks!
Highlighted

Thanks a lot @SBD_ 

 

Best Regards

William Alencar
GoodFy Brasil
0 Likes