Skip to content

Instantly share code, notes, and snippets.

/*
$(function() {
fetch("/geocoder/ip", {
method: "get"
}).then(function (response) {
if (response.ok) {
return response.json().then(function(json) {
var country_code = json["country_code"];
switch(country_code) {
<script>
$(document).ready(function() {
// Get the variant_id from the parameter
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
if (urlParams.has('variant_id')) {
const variant_id = urlParams.get('variant_id')
console.log('-------> '+variant_id)
var update_function = function(data) {
const coupon = "ABCDEFG"
var coupons = function(){
i("#payments_options input:checked").val() == 362229 ? Jumpseller.addCouponToCart(coupon , {callback: alert("Cupon Agregado")}) : Jumpseller.removeCouponFromCart(coupon, {callback: alert("No hay cupon")}) ;
}
$("#checkout").submit(coupons);
function cleanEstimates() {
// remove all prices and errors
$('#shipping_options li').each(function() {
$(this).children().last().detach();
});
// add empty messages - placeholders
$('#shipping_options li').each(function() {
$(this).append('<span></span>')
});
}
let products = [7966034,7966035]; // Add products IDs here
// This may take a while, so it's better to create a loader
var setLoading = function(par){if(par){console.log("Inicio")}else{console.log("Inicio")}}
setLoading(true);
const addListToCart = (index, quantity) => {
if(index < products.length){
product = products[index];
Jumpseller.addProductToCart(product, quantity, {}, {callback: addListToCart(++index,quantity)})
}
<script>
// Define all codes from many promotions
const coupons = ["cupon1", "cupon2", "cupon3"]
//Callback that returns all coupons in cart
var callback_added = function(data) {
console.log(data.coupons)
}
// Callback that searches intersections between the codes in cart and the promotional codes.
<script>
const shipping_method_id = 1234556 // id of free shipping option
const normal_shipping = 654321 // id of normal shipping option
const municipalities_free_shipping = ["merchant needs to complete this field"] // Ideally a theme option separated by comma
const products_free_shipping = ["merchant needs to complete this field"] // Ideally a theme option separated by comma
var conditions = function() {
// certain product is in the cart and certain municipalities are selected. The work is to construct this function
}
var callbackFunction = function() {
console.log("Coupon " + discount + " added")
}
var add_url_coupon = function() {
queryString = window.location.search;
urlParams = new URLSearchParams(queryString);
if (urlParams.has('discount')) {
discount = urlParams.get('discount')
Jumpseller.addCouponToCart(discount, {
@aatronco
aatronco / open_variant_from_url_parameter.js
Created March 17, 2021 20:05
Chooses al of the options from a product URL containing the variant_id parameter in Jumpseller
$(document).ready(function() {
// Get the variant_id from the parameter
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
if (urlParams.has('variant_id')) {
const variant_id = urlParams.get('variant_id')
var update_function = function(data) {
// Find the variant
active_variant = data.variants.find(item => item.id == variant_id)
<script>
// Variables
var productId = 7576049 // Create virtual product and get the product id
var variant1 = 11996397 // Create a variant of the product, this is the variant that will go to the cart.
// Conditions Function: This function returns true or false depending if the conditions are present or not on the checkout. This part can change depending on the conditions.
var conditions = function(){
return $("#ID_DE_CAJA_DE_VERIFICACION").is(":checked"); // Certain payment option is selected on this example
}
// Finds product_cart_id by searching the productId on the cart. The Product Cart Id is the ID of the instance of the product that is on the cart. This section shouldn't change.
function find_order_product_id(cart_json) {