PageSourceSearch

https://cutiebeecreative.com/wp-content/plugins/checkout-upsell-woocommerce/assets/js/frontend.js?ver=2.1.9

js cutiebeecreative.com collected 2026-10-09 22:40:08 UTC 28,014 bytes, 672 lines download raw bytes

1jQuery(function ($) {
2
3    let cuw_ajax_url = cuw_frontend.ajax_url;
4    let cuw_ajax_nonce = cuw_frontend.ajax_nonce;
5    let cuw_is_cart = (cuw_frontend.is_cart == '1');
6    let cuw_is_checkout = (cuw_frontend.is_checkout == '1');
7    let cuw_has_cart_block = (cuw_frontend.has_cart_block == '1');
8    let cuw_has_checkout_block = (cuw_frontend.has_checkout_block == '1');
9    let cuw_dynamic_offer_display_enabled = (cuw_frontend.dynamic_offer_display_enabled == '1');
10
11    var cuw_page_action_performing = false;
12
13    /* Actions */
14    window.cuw_actions = {
15        // add offer to cart
16        add_offer_to_cart: function (offer) {
17            let offer_id = offer.data('id');
18            if (!offer_id) {
19                return;
20            }
21
22            $.ajax({
23                type: 'post',
24                url: cuw_ajax_url,
25                async: true,
26                data: {
27                    action: 'cuw_ajax',
28                    method: 'add_offer_to_cart',
29                    offer_id: offer_id,
30                    quantity: offer.find('[name="quantity"]').val() || 1,
31                    variation_id: offer.find('[name="variation_id"]').val() || 0,
32                    variation_attributes: offer.find('[name="variation_id"]').data('chosen_attributes') || [],
33                    location: offer.closest('.cuw-offers').data('location') || '',
34                    nonce: cuw_ajax_nonce || ''
35                },
36                beforeSend: function () {
37                    cuw_spinner.show(offer);
38                    offer.find('.cuw-offer :input').prop('disabled', true);
39                },
40                success: function (response) {
41                    if (response.success && response.data) {
42                        jQuery(document.body).trigger('cuw_offer_added_to_cart', [response.data, offer]);
43
44                        if (response.data.reload_page) {
45                            location.reload(true); // to reload page if requires.
46                        }
47
48                        cuw_actions.update_fragments();
49
50                        if (response.data.cart_item_key) {
51                            offer.data('cart_item_key', response.data.cart_item_key);
52                            offer.addClass('cuw-offer-added');
53                            offer.find('.cuw-offer-cta-section .cuw-offer-cta-text').hide();
54                            offer.find('.cuw-offer-cta-section .cuw-offer-added-text').show();
55                            offer.find('.cuw-product-quantity, .cuw-product-variants').css('pointer-events', 'none');
56                            offer.find('.cuw-product-quantity, .cuw-product-variants').css('opacity', '0.8');
57                        } else {
58                            offer.find('.cuw-checkbox').prop('checked', false);
59                        }
60
61                        if (response.data.remove_offer) {
62                            if (response.data.notice) {
63                                $(response.data.notice).insertBefore(offer);
64                            }
65                            offer.fadeOut(1000, function () {
66                                $(this).remove();
67                            });
68                        } else {
69                            cuw_spinner.hide(offer);
70                        }
71
72                        if (response.data.remove_all_offers) {
73                            $('.cuw-offer').fadeOut(1000, function () {
74                                $(this).remove();
75                            });
76                        }
77                    }
78                    offer.find('.cuw-offer :input').prop('disabled', false);
79                }
80            });
81        },
82
83        remove_offer_from_cart: function (offer) {
84            let key = offer.data('cart_item_key');
85            if (!key) {
86                return;
87            }
88
89            $.ajax({
90                type: 'post',
91                url: cuw_ajax_url,
92                async: true,
93                data: {
94                    action: 'cuw_ajax',
95                    method: 'remove_item_from_cart',
96                    item_key: key,
97                    nonce: cuw_ajax_nonce || ''
98                },
99                beforeSend: function () {
100                    cuw_spinner.show(offer);
101                },
102                success: function (response) {
103                    cuw_actions.update_fragments();
104                    if (response.data.item_removed) {
105                        offer.removeClass('cuw-offer-added');
106                        offer.find('.cuw-offer-cta-section .cuw-offer-added-text').hide();
107                        offer.find('.cuw-offer-cta-section .cuw-offer-cta-text').show();
108                        offer.find('.cuw-product-quantity, .cuw-product-variants').css('pointer-events', 'all');
109                        offer.find('.cuw-product-quantity, .cuw-product-variants').css('opacity', '1.0');
110                    }
111                    cuw_spinner.hide(offer);
112                },
113            });
114        },
115
116        // perform action
117        perform_action: function (action) {
118            let params = action.data();
119            params.checked = action.find('input[type=checkbox]').is(':checked');
120
121            $.ajax({
122                type: 'post',
123                url: cuw_ajax_url,
124                async: true,
125                data: {
126                    action: 'cuw_ajax',
127                    method: 'perform_action',
128                    params: params,
129                    nonce: cuw_ajax_nonce || ''
130                },
131                beforeSend: function () {
132                    cuw_spinner.show(action);
133                    $('.cuw-action :input').prop('disabled', true);
134                },
135                success: function (response) {
136                    if (response.success && response.data) {
137                        jQuery(document.body).trigger('cuw_action_performed', [response.data, action]);
138
139                        if (response.data.reload_page) {
140                            location.reload(true); // to reload page if requires.
141                        }
142
143                        if (response.data.trigger) {
144                            jQuery(document.body).trigger(response.data.trigger, {});
145                        }
146
147                        cuw_spinner.hide(action);
148
149                        if (!response.data.remove) {
150                            action.find('input[type=checkbox]').prop('checked', response.data.checked ? true : false);
151                            action.data('lock', response.data.lock ? true : false);
152                        } else {
153                            action.remove();
154                        }
155                    }
156                    $('.cuw-action :input').prop('disabled', false);
157                }
158            });
159        },
160
161        // to perform post-purchase upsells action
162        perform_ppu_action: function (action) {
163            cuw_spinner.show($('#cuw-ppu-offer'));
164            $('#cuw-ppu-offer [name="cuw_ppu_action"]').val(action);
165            $('#cuw-ppu-offer').submit();
166        },
167
168        // add chosen products to cart
169        add_products_to_cart: function (section, choose_variants = false) {
170            if (choose_variants) {
171                let chosen_product_ids = [];
172                let chosen_variable_product_ids = [];
173                cuw_products.get_chosen_products(section).forEac
173h(function (product) {
174                    chosen_product_ids.push(product.data('id'));
175                    if (product.hasClass('is_variable')) {
176                        chosen_variable_product_ids.push(product.data('id'));
177                    }
178                });
179                if (chosen_variable_product_ids.length > 0) {
180                    let modal = section.find('.cuw-modal').first();
181                    modal.find('.cuw-product-row').each(function (index, row) {
182                        if (chosen_product_ids.includes($(row).data('product_id'))) {
183                            cuw_products.update_product_row(section, $(row));
184                            $(row).show();
185                        } else {
186                            $(row).hide();
187                        }
188                    });
189                    cuw_products.update_prices(section);
190                    cuw_modal.show(modal);
191                } else {
192                    this.add_products_to_cart(section, false);
193                }
194            } else {
195                cuw_spinner.show(section.find(".cuw-buy-section, .cuw-modal-content"));
196                section.find('form').submit();
197            }
198        },
199
200        // add product to cart
201        add_product_to_cart: function (section, product) {
202            let page = this.get_page(section);
203
204            $.ajax({
205                type: 'post',
206                url: cuw_ajax_url,
207                async: true,
208                data: {
209                    action: 'cuw_ajax',
210                    method: 'add_product_to_cart',
211                    campaign_id: section.data('campaign_id') || 0,
212                    product_id: product.data('id') || 0,
213                    quantity: product.find('[name="quantity"]').val() || 1,
214                    variation_id: product.find('[name="variation_id"]').val() || 0,
215                    variation_attributes: product.find('[name="variation_id"]').data('chosen_attributes') || [],
216                    page: page,
217                    nonce: cuw_ajax_nonce || ''
218                },
219                beforeSend: function () {
220                    cuw_spinner.show(product);
221                    product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', true).css('opacity', 0.8);
222                },
223                success: function (response) {
224                    if (response.success && response.data) {
225                        if (response.data.item_key && response.data.cart_subtotal) {
226                            product.data('key', response.data.item_key);
227                            cuw_products.update_inputs(product, false);
228                            cuw_products.update_prices(section, response.data);
229                            cuw_actions.update_fragments(page);
230                        }
231                    }
232                    cuw_spinner.hide(product);
233                    product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', false).css('opacity', 1);
234                },
235            });
236        },
237
238        // remove item from cart
239        remove_item_from_cart: function (section, product) {
240            let key = product.data('key');
241            if (!key) {
242                return;
243            }
244
245            let page = this.get_page(section);
246
247            $.ajax({
248                type: 'post',
249                url: cuw_ajax_url,
250                async: true,
251                data: {
252                    action: 'cuw_ajax',
253                    method: 'remove_item_from_cart',
254                    item_key: key,
255                    page: page,
256                    nonce: cuw_ajax_nonce || ''
257                },
258                beforeSend: function () {
259                    cuw_spinner.show(product);
260                    product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', true).css('opacity', 0.8);
261                },
262                success: function (response) {
263                    if (response.success && response.data) {
264                        if (response.data.item_removed && response.data.cart_subtotal) {
265                            product.data('key', '');
266                            cuw_products.update_inputs(product, true);
267                            cuw_products.update_prices(section, response.data);
268                            cuw_actions.update_fragments(page);
269                        }
270                    }
271                    cuw_spinner.hide(product);
272                    product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', false).css('opacity', 1);
273                },
274            });
275        },
276
277        // add addon product to cart
278        add_addon_to_cart: function (section, product) {
279            let wrapper = product;
280            if (product.closest('.cart_item').length) {
281                wrapper = product.closest('.cart_item');
282            }
283
284            $.ajax({
285                type: 'post',
286                url: cuw_ajax_url,
287                async: true,
288                data: {
289                    action: 'cuw_ajax',
290                    method: 'add_addon_to_cart',
291                    campaign_id: section.data('campaign_id') || 0,
292                    product_id: product.data('id') || 0,
293                    quantity: section.data('quantity') || 0,
294                    variation_id: product.data('variant_id') || product.val() || 0,
295                    main_item_key: section.data('main_item_key') || '',
296                    nonce: cuw_ajax_nonce || ""
297                },
298                beforeSend: function () {
299                    cuw_spinner.show(wrapper);
300                },
301                success: function (response) {
302                    if (response.success && response.data && response.data.item_key) {
303                        cuw_actions.update_fragments('cart');
304                    }
305                    cuw_spinner.hide(wrapper);
306                },
307            });
308        },
309
310        // remove addon item from cart
311        remove_addon_from_cart: function (section, product) {
312            let key = product.data('item_key');
313            if (!key) {
314                return;
315            }
316
317            let wrapper = product;
318            if (product.closest('.cart_item').length) {
319                wrapper = product.closest('.cart_item');
320            }
321
322            $.ajax({
323                type: 'post',
324                url: cuw_ajax_url,
325                async: true,
326                data: {
327                    action: 'cuw_ajax',
328                    method: 'remove_addon_from_cart',
329                    item_key: key,
330                    nonce: cuw_ajax_nonce || ""
331                },
332                beforeSend: function () {
333                    cuw_spinner.show(wrapper);
334                },
335                success: function (response) {
336                    if (response.success && response.data) {
337                        cuw_actions.update_fragments('cart');
338                    }
339                    cuw_spinner.hide(wrapper);
340                    product.data('lock', false);
341                },
342            });
343        },
344
345        // change cart item variant
346        change_cart_item_variant: function (section, variant) {
347            let key = section.data('item_key');
348            if (!key) {
349                return;
350            }
351
352            let wrapper = variant;
353            if (variant.closest('.cart_item').length > 0) {
354                wrapper = variant.closest('.cart_item');
355            }
356
357            $.ajax({
358                type: 'post',
359                url: cuw_ajax_url,
360                async: true,
361                data: {
362                    action: 'cuw_ajax',
363                    method: 'change_cart_item_variant',
364                    item_key: key,
365                    variation_id: variant.val() || 0,
366                    nonce: cuw_ajax_nonce || ""
367                },
368                beforeSend: function () {
369                    cuw_spinner.show(wrapper);
370                },
371                success: function (response) {
372                    if (response.success && response.data) {
373                        cuw_actions.update_fragments('cart');
374                    }
375                    cuw_spinner.hide(wrapper);
376                },
377            });
378        },
379
380        // to get page
381        get_page: function (section = null) {
382            let page = '';
383            if (section !== null) {
384                page = section.data('page') ? section.data('page') : section.closest('.cuw-modal').data('page');
385            }
386            return page;
387        },
388
389        // to update page fragments
390        update_fragments: function (page = '') {
391            if (page === 'cart' || cuw_is_cart) {
392                jQuery(document.body).trigger('wc_update_cart');
393                jQuery(document.body).trigger('cuw_cart_page_updated');
394            } else if (page === 'checkout' || cuw_is_checkout) {
395                jQuery(document.body).trigger('update_checkout');
396                jQuery(document.body).trigger('cuw_checkout_page_updated');
397            } else {
398                jQuery(document.body).trigger('wc_fragment_refresh');
399                jQuery(document.body).trigger('cuw_fragment_refreshed');
400            }
401
402            if (cuw_has_cart_block || cuw_has_checkout_block) {
403                setTimeout(function () {
404                    jQuery(document.body).trigger('added_to_cart', {});
405                }, 0);
406            }
407        },
408
409        // to get the product details in popup
410        show_product_details_popup: function (section, product_id) {
411            cuw_spinner.show(section);
412
413            $.ajax({
414                type: 'post',
415                url: cuw_ajax_url,
416                async: false,
417                data: {
418                    action: 'cuw_ajax',
419                    method: 'get_product_details_popup',
420                    product_id: product_id,
421                    nonce: cuw_ajax_nonce || ''
422                },
423                success: function (response) {
424                    if (response.data.html) {
425                        $('body').append(response.data.html);
426                        cuw_modal.show($('#cuw-modal-product-details-' + product_id), true);
427                        $('#cuw-modal-product-details-' + product_id + ' .variant-select').trigger('change');
428                    }
429                    cuw_spinner.hide(section);
430                },
431            });
432        },
433
434        // to update the product image
435        update_product_image: function (section, product_id) {
436            cuw_spinner.show(section.find(".cuw-product-image"));
437
438            $.ajax({
439                type: 'post',
440                url: cuw_ajax_url,
441                async: true,
442                data: {
443                    action: 'cuw_ajax',
444                    method: 'get_offer_image',
445                    product_id: product_id,
446                    nonce: cuw_ajax_nonce || ''
447                },
448                success: function (response) {
449                    cuw_spinner.hide(section.find('.cuw-product-image'));
450                    if (response.data.html) {
451                        if (section.find('.cuw-product-image a').length > 0) {
452                            section.find('.cuw-product-image a').html(response.data.html);
453                        } else {
454                            section.find('.cuw-product-image').html(response.data.html);
455                        }
456                    }
457                },
458            });
459        },
460    }
461
462    $(document).on("change", ".cuw-product-addons .cuw-product .cuw-product-checkbox", function () {
463        let addons_count = $('.cuw-product-addons .cuw-product-checkbox:checked').length;
464        $('.cuw-product-addons-pricing-section').css('display', (addons_count > 0 ? 'flex' : 'none'));
465        $(this).closest('.cuw-product').find('.cuw-product-quantity').toggle($(this).prop('checked'));
466        $(this).closest('.cuw-product').find('.cuw-product-variants').toggle($(this).prop('checked'));
467    });
468
469    $(document).on("click", ".cuw-modal-product-detail", function () {
470        cuw_actions.show_product_details_popup($(this).closest('.cuw-container'), $(this).data('id'));
471    });
472
473    $(document).on("click", ".cuw-products .cuw-product .cuw-add-product-to-cart", function () {
474        cuw_actions.add_product_to_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product'));
475    });
476
477    $(document).on("change", ".cuw-cart-item-variants .variant-select", function () {
478        cuw_actions.change_cart_item_variant($(this).closest('.cuw-cart-item-variants'), $(this).find("option:selected"));
479    });
480
481    $(document).on("click", ".cuw-products .cuw-product .cuw-remove-item-from-cart", function () {
482        cuw_actions.remove_item_from_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product'));
483    });
484
485    $(document).on("click", ".cuw-cart-addon-products .cuw-products .cuw-product input[type=checkbox]", function () {
486        if ($(this).is(":checked")) {
487            cuw_actions.add_addon_to_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product'));
488        } else {
489            cuw_actions.remove_addon_from_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product'));
490        }
491    });
492
493    $(document).on("click", ".cuw-offer input[type=checkbox], .cuw-offer button", function () {
494        let offer = $(this).closest('.cuw-offer');
495        if (!offer.hasClass('cuw-offer-added')) {
496            cuw_actions.add_offer_to_cart(offer);
497        } else {
498            cuw_actions.remove_offer_from_cart(offer);
499        }
500    });
501
502    $(document).on("click", ".cuw-action input[type=checkbox], .cuw-action button", function () {
503        cuw_actions.perform_action($(this).closest('.cuw-action'));
504    });
505
506    $(document).on("click", ".cuw-products .cuw-add-to-cart", function () {
507        cuw_actions.add_products_to_cart($(this).closest(".cuw-products"), $(this).data('choose_variants') == '1');
508    });
509
510    $(".cuw-page .cuw-qty").change(function () {
511        $(".cuw-page .cuw-qty").val($(this).val());
512        $('.cuw-hidden-product-quantity').val($(this).val());
513    }).trigger('change');
514
515    $(".cuw-page .variant-select").change(function () {
516        $(".cuw-page .variant-select").val($(this).val());
517        $('.cuw-hidden-product-variant').val($(this).val());
518    }).trigger('change');
519
520    $(".cuw-page-offer-form, .cuw-page-offer-accept").submit(function () {
521        cuw_spinner.show($(this));
522        cuw_page_action_performing = true;
523    });
524
525    $(".cuw-offer-decline-link").click(function () {
526        cuw_page_action_performing = true;
527        $(".cuw-offer-decline-link").css({'pointer-events': 'none', 'opacity': '0.8'});
528    });
529
530    $("#cuw-ppu-offer .cuw-ppu-ignore-offers").click(function () {
531        cuw_actions.perform_ppu_action('ignore_offers');
532    });
533
534    $("#cuw-ppu-offer .cuw-ppu-accept-button").click(function () {
535        cuw_actions.perform_ppu_action('accept_offer');
536    });
537
538    $("#cuw-ppu-offer .cuw-ppu-decline-button, #cuw-ppu-offer .cuw-ppu-decline-link").click(function () {
539        cuw_actions.perform_ppu_action('decline_offer');
540    });
541
542    jQuery(document.body).on('click', '.cuw-custom-trigger', function () {
543        cuw_spinner.show($(this).closest('.cuw-modal').find('.cuw-modal-body'));
544        $($(this).data('target')).trigger($(this).data('event'));
545    });
546
547    jQuery(document.body).on('cuw_update_offers', function (event, campaign_type = '') {
548        if ($('.cuw-offers').length === 0 || campaign_type === '') {
549            return;
550        }
551
552        $.ajax({
553            type: 'post',
554            url: cuw_ajax_url,
555            async: false,
556            data: {
557                action: 'cuw_ajax',
558                method: 'get_all_offers_html',
559                campaign_type: campaign_type,
560                nonce: cuw_ajax_nonce || ''
561            },
562            success: function (response) {
563                if (response.data && response.data.html) {
564                    $.each(response.data.html, function (location, html) {
565                        $('.cuw-offers[data-location="' + location + '"]').html(html);
566                    });
567                }
568            },
569        });
570    });
571
572    if (cuw_dynamic_offer_display_enabled) {
573        if (cuw_is_cart || cuw_has_cart_block) {
574            jQuery(document.body).on('applied_coupon rem
574oved_coupon', function () {
575                jQuery(document.body).trigger('cuw_update_offers', ['cart_upsells']);
576            });
577        } else if (cuw_is_checkout || cuw_has_checkout_block) {
578            jQuery(document.body).on('applied_coupon_in_checkout removed_coupon_in_checkout', function () {
579                jQuery(document.body).trigger('cuw_update_offers', ['checkout_upsells']);
580            });
581        }
582    }
583
584    jQuery(document.body).on('cuw_show_upsell_popup', function (event, data, element) {
585        if (data.dynamic_content) {
586            $.ajax({
587                type: 'post',
588                url: cuw_ajax_url,
589                data: {
590                    action: 'cuw_ajax',
591                    method: 'get_upsell_popup',
592                    campaign_id: data.campaign_id,
593                    product_id: data.product_id,
594                    trigger: data.trigger,
595                    page: data.page,
596                    nonce: cuw_ajax_nonce || ''
597                },
598                success: function (response) {
599                    if (response.success && response.data && response.data.campaign_id && response.data.html) {
600                        let campaign_id = response.data.campaign_id;
601                        if ($('#cuw-modal-' + campaign_id).length > 0) {
602                            $('#cuw-modal-' + campaign_id).find('.cuw-cart-subtotal').html(response.data.cart_subtotal);
603                        } else {
604                            $('body').append(response.data.html);
605                        }
606
607                        cuw_modal.show($('#cuw-modal-' + campaign_id), true);
608
609                        // to add scroll action event listener
610                        if (cuw_products && cuw_products.carousel_update_actions) {
611                            $('#cuw-modal-' + campaign_id + ' .cuw-carousel .cuw-carousel-slider').on('scroll', function () {
612                                cuw_products.carousel_update_actions($(this).closest(".cuw-carousel"));
613                            });
614                        }
615                    }
616                },
617            });
618        } else if (data.campaign_id) {
619            let modal = $('#cuw-modal-' + data.campaign_id);
620            if (modal.length > 0) {
621                modal.data('shown', true);
622                cuw_modal.show(modal);
623            }
624        }
625    });
626
627    jQuery(document.body).on('checkout_error', function () {
628        cuw_modal.hide('.cuw-modal');
629    });
630
631    let messages = $(".cuw-page-timer");
632    if (messages.length > 0) {
633        let element = messages.first();
634        let message = element.data('message');
635        let params = new URLSearchParams(window.location.search);
636        let unique_id = params.get('cuw_order_id');
637        if (params.get('cuw_ppu_offer')) {
638            unique_id = params.get('cuw_ppu_offer') + '_' + (params.get('cuw_order') || '');
639        }
640        if (!unique_id) {
641            return;
642        }
643        let duration = (element.data('minutes') * 60) + element.data('seconds'), minutes, seconds;
644        if (Cookies && unique_id) {
645            let duration_from_cookie = Cookies.get("cuw_timer_" + unique_id);
646            if (duration_from_cookie !== undefined) {
647                duration = duration_from_cookie;
648            }
649        }
650        setInterval(function () {
651            if (duration >= 0) {
652                minutes = parseInt(duration / 60, 10);
653                seconds = parseInt(duration % 60, 10);
654                minutes = minutes < 10 ? "0" + minutes : minutes;
655                seconds = seconds < 10 ? "0" + seconds : seconds;
656                messages.html(message.replace('{minutes}', minutes).replace('{seconds}', seconds));
657                if (duration === 0) {
658                    if (params.get('cuw_ppu_offer')) {
659                        cuw_actions.perform_ppu_action('decline_offer');
660                    } else if (!cuw_page_action_performing) {
661                        window.location = element.data('redirect');
662                    }
663                }
664                if (Cookies && unique_id) {
665                    Cookies.set("cuw_timer_" + unique_id, duration);
666                }
667                duration--;
668            }
669        }, 1000);
670    }
671
672});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.