Skip to content

Instantly share code, notes, and snippets.

@scheibome
Last active October 8, 2018 17:40
Show Gist options
  • Save scheibome/f427ef4673285e8a36c3b4c8391d09ad to your computer and use it in GitHub Desktop.
Save scheibome/f427ef4673285e8a36c3b4c8391d09ad to your computer and use it in GitHub Desktop.
multi shipping in tinystoragecart checkout
<select id="shippingselect">
<option disabled selected value>Select</option>
<option value="2" data-shippingselect="15">Europe Shipping +15€</option>
<option value="3" data-shippingselect="35">International Shiping +35€</option>
</select>
var $cartcheckoutshippingselection = document.getElementById('shippingselect');
if ($cartcheckoutshippingselection) {
$cartcheckoutshippingselection.addEventListener('change', function(e) {
$singleShipping.dataset.shippingcost = e.target.selectedOptions[0].dataset.shippingselect;
requirejs(['cart/cart'], function(cart) {
document.dispatchEvent(
new CustomEvent('calculateCartSum', {
detail: {
cart: cart.getStorageCart(),
cartTotal: cart.calculateTotal(),
cartObject: cart
}
})
);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment