CLICK HERE TO TRY AUTOMATIC DISCOUNT FOR SHOPIFY

Custom JS function

Custom JS function

Prix normal
$0.00
Prix réduit
$0.00
Prix normal
Épuisé
Prix unitaire
par 

 Use Case Example #1 - Rule based on the $ cart amount


// javascript function that checks if the cart total is bigger than $76
// to see what is inside the cart variable
// 1) add something to cart
// 2) open in a browser https://automatic-discount.myshopify.com/cart.json
// 3) you can find more info for the cart variable here https://go.tabarn.app/r/cart-docs

window['_tbn_custom_rule'] = function ({ cart, smart_cart, rule, customer, meta_value }){
if ( Number(cart.total_price) > 7600 ){
return true;
}
return false;
}


Use Case Example #2 - Rule based on if customer has signed up

Do not copy-paste this code. It's just an example. 

If the store has a landing page where customers land after signing up, we can add a URL parameter like ?customer_posted=true at the end of the URL and sets a sessionStorage variable like userSignedUp = true

And then we make another promotion with just a custom JS rule that checks if this userSignedUp is true or not

Example of code snippet to add to the theme.liquid file:
<script type='text/javascript'>
const url = new URL(window.location.href);
if (url.search.indexOf('customer_posted=true')>=0){
sessionStorage.userSignedUp = 'true';
}
window._TBN_CUSTOM_CHECK_SIGNUP = function(input){
return sessionStorage.userSignedUp === 'true';
}
</script>