10 examples of 'woocommerce update cart ajax hook' in JavaScript

Every line of 'woocommerce update cart ajax hook' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
20function addProductToCart (productId, variationId, amount) {
21 var request2 = jQuery.ajax({
22 url : window.location.protocol + '//'
23 + window.location.host
24 + '/blocks/'+jQuery('html').attr('lang')+'/shopping-cart/add-item-to-cart',
25 type : "POST",
26 data : {
27 'current-page' : jQuery('body').attr('data-current-page'),
28 'productId' : productId,
29 'variationId': variationId,
30 'amount':amount
31 },
32 dataType : "json"
33 });
34
35 request2.done(updateShoppingCarts);
36
37 request2.fail(function(jqXHR, textStatus) {
38 console.log("error in adding item to cart");
39 });
40}
7function addToCart(product_id, quantity) {
8 quantity = typeof(quantity) != 'undefined' ? quantity : 1;
9
10 $.ajax({
11 url: urls['cartUrl'] + '/add',
12 type: 'post',
13 data: 'product_id=' + product_id + '&quantity=' + quantity,
14 dataType: 'json',
15 success: function(json) {
16 $('.alert-success').remove();
17
18 if (json['redirect']) {
19 location = json['redirect'];
20 }
21
22 if (json['success']) {
23 $('#notification').html('<div>' + json['success'] + '×</div>');
24
25 //$('.alert-success').fadeIn('slow');
26
27 $('#cart-total').html(json['total']);
28
29 $('html, body').animate({
30 scrollTop: 0
31 }, 'slow');
32 }
33 }
34 });
35}
31function WishlistCart(id, action, id_product, id_product_attribute, quantity)
32{
33 $.ajax({
34 type: 'GET',
35 url: baseDir + 'modules/blockwishlist/cart.php',
36 async: true,
37 cache: false,
38 data: 'action=' + action + '&amp;id_product=' + id_product + '&amp;quantity=' + quantity + '&amp;token=' + static_token + '&amp;id_product_attribute=' + id_product_attribute,
39 success: function(data)
40 {
41 if (action == 'add')
42 {
43 var $element = $('#bigpic');
44 if (!$element.length)
45 var $element = $('#wishlist_button');
46 var $picture = $element.clone();
47 var pictureOffsetOriginal = $element.offset();
48 $picture.css({'position': 'absolute', 'top': pictureOffsetOriginal.top, 'left': pictureOffsetOriginal.left});
49 var pictureOffset = $picture.offset();
50 var wishlistBlockOffset = $('#wishlist_block').offset();
51
52 $picture.appendTo('body');
53 $picture.css({ 'position': 'absolute', 'top': $picture.css('top'), 'left': $picture.css('left') })
54 .animate({ 'width': $element.attr('width')*0.66, 'height': $element.attr('height')*0.66, 'opacity': 0.2, 'top': wishlistBlockOffset.top + 30, 'left': wishlistBlockOffset.left + 15 }, 1000)
55 .fadeOut(800);
56 }
57
58 if($('#' + id).length != 0)
59 {
60 $('#' + id).slideUp('normal');
61 $('#' + id).html(data);
62 $('#' + id).slideDown('normal');
63 }
64 }
65 });
66}
53export function changeLocalCart(id: number, quantity: number) {
54 return {
55 type: actionTypes.CHANGE_LOCAL_CART,
56 id,
57 quantity
58 };
59}
41function sm_update_cart_totals(){
42 var items = jQuery( "#sell-media-checkout-cart tr.itemRow" );
43 var currency_symbol = sell_media.currencies[sell_media.currency_symbol].symbol;
44 var subtotal = 0;
45 var grand_total = 0;
46
47 // Get price of all items
48 var total_qty = 0;
49 items.each( function(){
50 var price = jQuery(this).find('.item-price').attr('data-price');
51 var current_qty = jQuery(this).find( '.item-quantity' ).text();
52
53 total_qty += parseInt(current_qty);
54 subtotal+= parseFloat( price ) * parseFloat( current_qty );
55 });
56
57 // Show sub total
58 jQuery( '.sell-media-totals .sell-media-cart-total' ).html( currency_symbol + subtotal );
59
60 // Add tax
61 jQuery( '.sell-media-totals .sell-media-cart-tax' ).html( currency_symbol + '0' );
62
63 // Add tax if tax is set.
64 if( sell_media.tax &gt; 0 ){
65 var tax = parseFloat( subtotal ) * parseFloat( sell_media.tax );
66 var grand_total = ( subtotal + tax ).toFixed(2);
67
68 tax = tax.toFixed(2);
69 jQuery( '.sell-media-totals .sell-media-cart-tax' ).html( currency_symbol + tax );
70 }
71
72
73
74 var total_shipping = 0;
75
76 // Add shipping
77 if( '2' === sell_media.shipping ){
78 var total_shipping = sm_calculate_shipping();
79
80 var grand_total = ( parseFloat( grand_total ) + parseFloat(total_shipping) );
81 }
82
83 // Show shipping.
84 jQuery( '.sell-media-totals .sell-media-cart-shipping' ).html( currency_symbol + total_shipping.toFixed( 2 ) );
85
86 // Grand total.
87 jQuery( '.sell-media-totals .sell-media-cart-grand-total' ).html( currency_symbol + grand_total );
88
89}
48function sm_update_cart_totals(){
49 // Define vars.
50 var items = jQuery( "#sell-media-checkout-cart .item" ),
51 currency_symbol = sell_media.currencies[sell_media.currency_symbol].symbol,
52 subtotal = 0,
53 tax = 0,
54 total_shipping = 0,
55 total_qty = 0;
56
57 // Get price of all items.
58 items.each( function(){
59 var price = jQuery(this).attr('data-price');
60 var current_qty = jQuery(this).find( '.item-quantity' ).text();
61
62 total_qty += parseInt(current_qty);
63 subtotal+= parseFloat( price ) * parseFloat( current_qty );
64 });
65
66 // Set grand total.
67 var grand_total = subtotal;
68
69 // Add tax if tax is set.
70 if( sell_media.tax &gt; 0 ){
71 tax = parseFloat( subtotal ) * parseFloat( sell_media.tax );
72 grand_total = subtotal + tax ;
73 }
74
75 // Add shipping cost.
76 if( '2' === sell_media.shipping ){
77 var total_shipping = sm_calculate_shipping();
78 var grand_total = parseFloat( grand_total ) + parseFloat( total_shipping );
79 }
80
81 // Show sub total.
82 jQuery( '.sell-media-totals .sell-media-cart-total' ).html( currency_symbol + subtotal.toFixed( 2 ) );
83
84 // Show tax.
85 jQuery( '.sell-media-totals .sell-media-cart-tax' ).html( currency_symbol + tax.toFixed( 2 ) );
86
87 // Show shipping.
88 jQuery( '.sell-media-totals .sell-media-cart-shipping' ).html( currency_symbol + total_shipping.toFixed( 2 ) );
89
90 // Show Grand total.
91 jQuery( '.sell-media-totals .sell-media-cart-grand-total' ).html( currency_symbol + grand_total.toFixed( 2 ) );
92
93}
11export function addToCart(product, quantity) {
12 return (dispatch) =&gt; {
13 const cartItem = {
14 "id": product.id,
15 "image": product.images[0].src,
16 "name": product.name,
17 "quantity": quantity
18 }
19 dispatch({
20 type: types.ADD_TO_CART_SUCCESS,
21 item: cartItem
22 });
23 }
24}
36function addToWishList(product_id) {
37 $.ajax({
38 url: urls['wishlistUrl'] + '/add',
39 type: 'post',
40 data: 'product_id=' + product_id,
41 dataType: 'json',
42 success: function(json) {
43 $('.success, .warning, .attention, .information').remove();
44
45 if (json['success']) {
46 $('#notification').html('<div>' + json['success'] + '</div>');
47
48 $('.success').fadeIn('slow');
49
50 $('#wishlist-total').html(json['total']);
51
52 $('html, body').animate({
53 scrollTop: 0
54 }, 'slow');
55 }
56 }
57 });
58}
164function WishlistAddProductCart(token, id_product, id_product_attribute, id_quantity)
165{
166 if ($('#' + id_quantity).val() &lt;= 0)
167 return (false);
168
169 $.ajax({
170 type: 'GET',
171 url: baseDir + 'modules/blockwishlist/buywishlistproduct.php?rand=' + new Date().getTime(),
172 headers: { "cache-control": "no-cache" },
173 data: 'token=' + token + '&amp;static_token=' + static_token + '&amp;id_product=' + id_product + '&amp;id_product_attribute=' + id_product_attribute,
174 async: true,
175 cache: false,
176 success: function(data)
177 {
178 if (data)
179 {
180 if (!!$.prototype.fancybox)
181 $.fancybox.open([
182 {
183 type: 'inline',
184 autoScale: true,
185 minHeight: 30,
186 content: '<p>' + data + '</p>'
187 }
188 ], {
189 padding: 0
190 });
191 else
192 alert(data);
193 }
194 else
195 $('#' + id_quantity).val($('#' + id_quantity).val() - 1);
196 }
197 });
198
199 return (true);
200}
201function clearCartItems() {
202 $('#cart').find("tbody tr").remove();
203}

Related snippets