PageSourceSearch

https://ountravela.com/wp-content/plugins/woo-bought-together-premium/assets/js/frontend.js

js ountravela.com collected 2026-09-25 01:31:03 UTC 45,094 bytes, 1,122 lines download raw bytes

1'use strict';
2
3(function ($) {
4    $(function () {
5        if (!$('.woobt-wrap').length) {
6            return;
7        }
8
9        $('.woobt-wrap').each(function () {
10            woobt_check_position($(this));
11            woobt_init($(this));
12        });
13    });
14
15    $(document).on('woosq_loaded', function () {
16        woobt_init($('#woosq-popup').find('.woobt-wrap'));
17    });
18
19    $(document).on('woovr_selected', function (e, selected, variations) {
20        var $wrap = variations.closest('.woobt-wrap');
21        var $products = variations.closest('.woobt-products');
22        var $product = variations.closest('.woobt-product');
23        var atc_button = $wrap.attr('data-atc-button');
24        var id = selected.attr('data-id');
25        var sku = selected.attr('data-sku');
26        var weight = selected.attr('data-weight');
27        var dimensions = selected.attr('data-dimensions');
28        var order = $product.attr('data-order');
29        var pricing = $products.attr('data-pricing');
30        var price_html = selected.attr('data-pricehtml');
31        var display_price = selected.attr('data-price');
32        var price = selected.attr('data-price');
33        var regular_price = selected.attr('data-regular-price');
34        var purchasable = selected.attr('data-purchasable');
35        var attrs = selected.attr('data-attrs');
36        var woobt_image = selected.attr('data-woobt_image');
37
38        if (pricing == 'regular_price') {
39            price = regular_price;
40        }
41
42        if ($product.length) {
43            if (purchasable === 'yes') {
44                // change data
45                $product.attr('data-id', id);
46                $product.attr('data-price', price);
47                $product.attr('data-regular-price', regular_price);
48
49                // change image
50                var $img = $wrap.find('.woobt-img-order-' + order);
51
52                if ($img.length) {
53                    if (woobt_image !== undefined && woobt_image !== '') {
54                        $img.html(woobt_image);
55                    } else {
56                        $img.html($img.attr('data-img'));
57                    }
58                }
59
60                // change price
61                var new_price = $product.attr('data-new-price') ?? '100%';
62
63                $product.find('.woobt-price-ori').hide();
64
65                if (new_price != '100%') {
66                    if (isNaN(new_price)) {
67                        new_price = price * parseFloat(new_price) / 100;
68                    }
69
70                    $product.find('.woobt-price-new').html(woobt_price_html(display_price, new_price)).show();
71                } else {
72                    $product.find('.woobt-price-new').html(price_html).show();
73                }
74
75                // change attributes
76                $product.attr('data-attrs', attrs.replace(/\/$/, ''));
77
78                // change separate add to cart
79                if ($product.hasClass('woobt-product-this')) {
80                    $wrap.attr('data-product-id', id);
81                    $wrap.find('.variation_id').attr('value', id);
82                }
83            } else {
84                // reset data
85                $product.attr('data-id', 0);
86                $product.attr('data-attrs', '');
87                $product.attr('data-price', 0);
88                $product.attr('data-regular-price', 0);
89
90                // reset price
91                $product.find('.woobt-price-ori').show();
92                $product.find('.woobt-price-new').html('').hide();
93
94                // reset separate add to cart
95                if ($product.hasClass('woobt-product-this')) {
96                    $wrap.attr('data-product-id', 0);
97                    $wrap.find('.variation_id').attr('value', 0);
98                }
99
100                // reset image
101                var $img = $wrap.find('.woobt-img-order-' + order);
102
103                if ($img.length) {
104                    $img.html($img.attr('data-img'));
105                }
106            }
107
108            // prevent changing SKU / weight / dimensions
109            $('.product_meta .sku').html($wrap.attr('data-product-sku'));
110            $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value').html($wrap.attr('data-product-weight'));
111            $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value').html($wrap.attr('data-product-dimensions'));
112        } else {
113            var pid = variations.closest('.variations_form').attr('data-product_id');
114
115            $wrap = $('.woobt-wrap-' + pid);
116            atc_button = $wrap.attr('data-atc-button');
117
118            if (atc_button === 'main' || atc_button === 'both') {
119                $products = $('.woobt-products-' + pid);
120
121                if (id > 0) {
122                    $wrap.attr('data-product-id', id);
123
124                    $products.find('.woobt-product-this').attr('data-price', price);
125                    $products.find('.woobt-product-this').attr('data-regular-price', regular_price);
126
127                    if (price_html !== '') {
128                        // change this price
129                        $products.find('.woobt-product-this .woobt-price-ori').hide();
130                        $products.find('.woobt-product-this .woobt-price-new').html(price_html).show();
131                    }
132
133                    if (woobt_image !== undefined && woobt_image !== '') {
134                        // change this image
135                        $wrap.find('.woobt-img-order-' + order).html(woobt_image);
136                    }
137
138                    $wrap.attr('data-product-sku', sku);
139                    $wrap.attr('data-product-weight', weight);
140                    $wrap.attr('data-product-dimensions', dimensions);
141                } else {
142                    // reset
143                    $products.find('.woobt-product-this').attr('data-price', 0);
144                    $products.find('.woobt-product-this').attr('data-regular-price', 0);
145
146                    $products.find('.woobt-product-this .woobt-price-new').hide();
147                    $products.find('.woobt-product-this .woobt-price-ori').show();
148
149                    var $img = $wrap.find('.woobt-img-order-' + order);
150
151                    if ($img.length) {
152                        $img.html($img.attr('data-img'));
153                    }
154
155                    $wrap.attr('data-product-id', 0);
156                    $wrap.attr('data-product-sku', $wrap.attr('data-product-o_sku'));
157                    $wrap.attr('data-product-weight', $wrap.attr('data-product-o_weight'));
158                    $wrap.attr('data-product-dimensions', $wrap.attr('data-product-o_dimensions'));
159                }
160            }
161        }
162
163        woobt_init($wrap);
164    });
165
166    $(document).on('found_variation', function (e, t) {
167        var $wrap = $(e['target']).closest('.woobt-wrap');
168        var $products = $(e['target']).closest('.woobt-products');
169        var $product = $(e['target']).closest('.woobt-product');
170        var atc_button = $wrap.attr('data-atc-button');
171        var pricing = $products.attr('data-pricing');
172        var price_html = t['price_html'];
173        var display_price = t['display_price'];
174        var display_regular_price = t['display_regular_price'];
175        var order = $product.attr('data-order');
176        var pid = $(e['target']).closest('.variations_form').attr('data-product_id');
177
178        if (pricing === 'regular_price') {
179            display_price = display_regular_price;
180        }
181
182        if ($product.length) {
183            if ($product.hasClass('woobt-product-together')) {
184                var new_price = $product.attr('data-new-price') ?? '100%';
185
186                if (new_price !== '100%') {
187                    if (isNaN(new_price)) {
188                        new_price = display_price * parseFloat(new_price) / 100;
189                    }
190
191                    $product.find('.woobt-price-ori').hide();
192                    $product.find('.woobt-price-new').html(woobt_price_html(display_price, new_price)).show();
193                } else if (price_html !== '') {
194                    $product.find('.woobt-price-ori').hide();
195                    $product.find('.woobt-price-new').html(price_html).show();
196                }
197            } else {
198                $wrap.attr('data-product-id', t['variation_id']);
199
200                if (price_html !== '') {
201                    $product.find('.woobt-price-ori').hide();
202                    $product.find('.woobt-price-new').html(price_html).show();
203                }
204            }
205
206            $product.attr('data-price', display_price);
207            $product.attr('data-regular-price', display_regular_price);
208
209            if (t['is_purchasable'] && t['is_in_stock']) {
210                $product.attr('data-id', t['variation_id']);
211
212                if ($product.hasClass('woobt-product-this')) {
213                    $wrap.find('.variation_id').attr('value', t['variation_id']);
214                }
215
216                // change attributes
217                var attrs = {};
218
219                $product.find('select[name^="attribute_"]').each(function () {
220                    var attr_name = $(this).attr('name');
221
222                    attrs[attr_name] = $(this).val();
223                });
224
225                $product.attr('data-attrs', JSON.stringify(attrs));
226            } else {
227                $product.attr('data-id', 0);
228                $product.attr('data-attrs', '');
229
230                if ($product.hasClass('woobt-product-this')) {
231                    $wrap.find('.variation_id').attr('value', 0);
232                }
233            }
234
235            // change availability
236            if (t['availability_html'] && t['availability_html'] !== '') {
237                $product.find('.woobt-availability').html(t['availability_html']).show();
238            } else {
239                $product.find('.woobt-availability').html('').hide();
240            }
241
242            // prevent changing SKU / weight / dimensions
243            $('.product_meta .sku').html($wrap.attr('data-product-sku'));
244            $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value').html($wrap.attr('data-product-weight'));
245            $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value').html($wrap.attr('data-product-dimensions'));
246
247            if (woobt_vars.change_image === 'no') {
248                // prevent changing the main image
249                $wrap.find('.variations_form').trigger('reset_image');
250                $('form.variations_form').wc_variations_image_update($wrap.data('variation'));
251            }
252
253            // change image
254            var $img = $wrap.find('.woobt-img-order-' + order);
255
256            if ($img.length) {
257                if (t['woobt_image'] !== undefined && t['woobt_image'] !== '') {
258                    $img.html(t['woobt_image']);
259                } else {
260                    $img.html($img.attr('data-img'));
261                }
262            }
263
264            woobt_init($wrap);
265        } else {
266            if ($(e['target']).closest('.woosb-product').length || $(e['target']).closest('.woosg-product').length || $(e['target']).closest('.woofs-product').length) {
267                return;
268            }
269
270            $wrap = $('.woobt-wrap-' + pid);
271            atc_button = $wrap.attr('data-atc-button');
272            $wrap.data('variation', t);
273
274            if ($wrap.length) {
275                if (t['woobt_items'] !== undefined) {
276                    if (t['woobt_items'] === 'yes') {
277                        var $ids = $('.woobt-ids-' + pid);
278                        var $main_btn = $ids.closest('form.cart').find('.single_add_to_cart_button:not(.wpcbn-btn)');
279                        var $separate_btn = $ids.closest('.woobt-form').find('.single_add_to_cart_button:not(.wpcbn-btn)');
280
281                        // reset ids
282                        $ids.val('');
283                        $main_btn.find('.woobt-count').remove();
284                        $separate_btn.find('.woobt-count').remove();
285                        $wrap.addClass('woobt-loading');
286
287                        var data = {
288                            action: 'woobt_get_variation_items',
289                            variation_id: t['variation_id'],
290                            nonce: woobt_vars.nonce,
291                        };
292
293                        $.post(woobt_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woobt_get_variation_items'), data, function (response) {
294                            if (response !== '') {
295                                $wrap.addClass('woobt-wrap-variation').html(response);
296                            } else {
297                                $wrap.removeClass('woobt-wrap-variation').html($wrap.data('variable'));
298                            }
299
300                            $wrap.find('.woobt_variations_form').each(function () {
301                                $(this).wc_variation_form();
302                            });
303
304                            $wrap.removeClass('woobt-loading');
305                            $(document).trigger('woobt_loaded_variation_items', [$wrap, t]);
306                        });
307                    } else {
308                        if ($wrap.hasClass('woobt-wrap-variation')) {
309                            $wrap.removeClass('woobt-wrap-variation').html($wrap.data('variable'));
310                            $wrap.find('.woobt_variations_form').each(function () {
311                                $(this).wc_variation_form();
312                            });
313                        }
314                    }
315                }
316
317                $wrap.attr('data-product-sku', t['sku']);
318                $wrap.attr('data-product-weight', t['weight_html']);
319                $wrap.attr('data-product-dimensions', t['dimensions_html']);
320                $wrap.attr('data-product-id', t['variation_id']);
321
322                if (atc_button === 'main' || atc_button === 'both') {
323                    $products = $('.woobt-products-' + pid);
324
325                    if (t['price_html'] !== '') {
326                        $wrap.attr('data-product-price-html', t['price_html']);
327                    }
328
329                    if ($products.find('.woobt-product-this').length) {
330                        $products.find('.woobt-product-this').attr('data-id', t['variation_id']);
331                        $products.find('.woobt-product-this').attr('data-price', display_price);
332                        $products.find('.woobt-product-this').attr('data-regular-price', display_regular_price);
333
334                        if (price_html !== '') {
335                            // change this price
336                            $products.find('.woobt-product-this .woobt-price-ori').hide();
337                            $products.find('.woobt-product-this .woobt-price-new').html(price_html).show();
338                        }
339
340                        // change this image
341                        var $img_0 = $wrap.find('.woobt-img-order-0');
342
343                        if ($img_0.length) {
344                            if (t['woobt_image'] !== undefined && t['woobt_image'] !== '') {
345                                $img_0.html(t['woobt_image']);
346                            } else {
347                                $img_0.html($img_0.attr('data-img'));
348                            }
349                        }
350                    }
351                }
352
353                woobt_init($wrap);
354            }
355        }
356    });
357
358    $(document).on('reset_data', function (e) {
359        var $wrap = $(e['target']).closest('.woobt-wrap');
360        var atc_button = $wrap.attr('data-atc-button');
361        var $products = $(e['target']).closest('.woobt-products');
362        var $product = $(e['target']).closest('.woobt-product');
363        var order = $product.attr('data-order');
364        var pid = $(e['target']).closest('.variations_form').attr('data-product_id');
365
366        if ($product.length) {
367            $product.attr('data-id', 0);
368            $product.attr('data-attrs', '');
369
370            // prevent changing the main image
371            $('form.variations_form').wc_variations_image_update($wrap.data('variation'));
372
373            // reset stock
374            $(e['target']).closest('.variations_form').find('p.stock').remove();
375
376            // reset SKU / weight / dimensions
377            $('.product_meta .sku').html($wrap.attr('data-product-sku'));
378            $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value').html($wrap.attr('data-product-weight'));
379            $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value').html($wrap.attr('data-product-dimensions'));
380
381            // reset availability
382            $product.find('.woobt-availability').html('').hide();
383
384            // reset price
385            $product.find('.woobt-price-new').hide();
386            $product.find('.woobt-price-ori').show();
387
388            if ($product.hasClass('woobt-product-this')) {
389                $wrap.attr('data-product-id', 0);
390            }
391
392            // reset image
393            var $img = $wrap.find('.woobt-img-order-' + order);
394
395            if ($img.length) {
396                $img.html($img.attr('data-img'));
397            }
398        } else {
399            if ($(e['target']).closest('.woosb-product').length || $(e['target']).closest('.woosg-product').length || $(e['target']).closest('.woofs-product').length) {
400                return;
401            }
402
403            $wrap = $('.woobt-wrap-' + pid);
404            atc_button = $wrap.attr('data-atc-button');
405
406            if ($wrap.length && ($wrap.data('variable') !== undefined)) {
407                $wrap.removeClass('woobt-wrap-variation').html($wrap.data('variable'));
408            }
409
410            $wrap.find('.woobt_variations_form').each(function () {
411                $(this).wc_variation_form();
412            });
413
414            $wrap.removeData('variation');
415
416            $wrap.attr('data-product-id', 0);
417            $wrap.attr('data-product-sku', $wrap.attr('data-product-o_sku'));
418            $wrap.attr('data-product-weight', $wrap.attr('data-product-o_weight'));
419            $wrap.attr('data-product-dimensions', $wrap.attr('data-product-o_dimensions'));
420            $wrap.attr('data-product-price-html', $wrap.attr('data-product-o_price-html'));
421
422            if (atc_button === 'main' || atc_button === 'both') {
423                $products = $('.woobt-products-' + pid);
424
425                // change this price
426                $products.find('.woobt-product-this').attr('data-id', 0);
427
428                // reset this image
429                var $img_0 = $wrap.find('.woobt-img-order-0');
430
431                if ($img_0.length) {
432                    $img_0.html($img_0.attr('data-img'));
433                }
434            }
435        }
436
437        if ($wrap.length) {
438            woobt_init($wrap);
439        }
440    });
441
442    $(document).on('click touch', '.woobt-quantity-input-plus, .woobt-quantity-input-minus', function () {
443        // get values
444        var $qty = $(this).closest('.woobt-quantity').find('.woobt-qty');
445
446        if (!$qty.length) {
447            $qty = $(this).closest('.woobt-quantity').find('.qty');
448        }
449
450        var val = parseFloat($qty.val()), max = parseFloat($qty.attr('max')), min = parseFloat($qty.attr('min')),
451            step = $qty.attr('step');
452
453        // format values
454        if (!val || val === '' || val === 'NaN') {
455            val = 0;
456        }
457
458        if (max === '' || max === 'NaN') {
459            max = '';
460        }
461
462        if (min === '' || min === 'NaN') {
463            min = 0;
464        }
465
466        if (step === 'any' || step === '' || step === undefined || parseFloat(step) === 'NaN') {
467            step = 1;
468        } else {
469            step = parseFloat(step);
470        }
471
472        // change the value
473        if ($(this).is('.woobt-quantity-input-plus')) {
474            if (max && (max == val || val > max)) {
475                $qty.val(max);
476            } else {
477                $qty.val((val + step).toFixed(woobt_decimal_places(step)));
478            }
479        } else {
480            if (min && (min == val || val < min)) {
481                $qty.val(min);
482            } else if (val > 0) {
483                $qty.val((val - step).toFixed(woobt_decimal_places(step)));
484            }
485        }
486
487        // trigger change event
488        $qty.trigger('change');
489    });
490
491    $(document).on('click touch', '.single_add_to_cart_button:not(.wpcbn-btn)', function (e) {
492        if ($(this).hasClass('woobt-disabled')) {
493            e.preventDefault();
494        }
495    });
496
497    $(document).on('change', '.woobt-checkbox', function () {
498        var $this = $(this);
499        var $wrap = $this.closest('.woobt-wrap');
500        var selection = $wrap.attr('data-selection');
501
502        if (selection === 'single') {
503            $wrap.find('.woobt-checkbox').not('.woobt-checkbox-this').not(this).prop('checked', false);
504        }
505
506        $(document).trigger('woobt_checkbox', [$this]);
507
508        woobt_init($wrap);
509    });
510
511    $(document).on('change keyup mouseup', '.woobt-this-qty', function () {
512        var val = $(this).val();
513        var pid = $(this).closest('.woobt-wrap').attr('data-id');
514        var $ids = $('.woobt-ids-' + pid);
515        var $form = $ids.closest('form.cart').length ? $ids.closest('form.cart') : $ids.closest('.woobt-form');
516
517        $(this).closest('.woobt-product-this').attr('data-qty', val);
518
519        $form.find('input[name="quantity"]').val(val).trigger('change');
520    });
521
522    $(document).on('change keyup mouseup', '.woobt-qty, .woobt-quantity .qty', function () {
523        var $this = $(this);
524        var $wrap = $this.closest('.woobt-wrap');
525        var $product = $this.closest('.woobt-product');
526        var $checkbox = $product.find('.woobt-checkbox');
527        var val = parseFloat($this.val());
528
529        if ($checkbox.prop('checked')) {
530            var min = parseFloat($this.attr('min'));
531            var max = parseFloat($this.attr('max'));
532
533            if (val < min) {
534                $this.val(min);
535            }
536
537            if (val > max) {
538                $this.val(max);
539            }
540
541            $product.attr('data-qty', $this.val());
542
543            woobt_init($wrap);
544        }
545    });
546
547    $(document).on('change input', 'form.cart .qty', function () {
548        var $this = $(this);
549        var qty = parseFloat($this.val());
550
551        if ($this.hasClass('woobt-qty') || $this.closest('.woobt-quantity').length) {
552            return;
553        }
554
555        if (!$this.closest('form.cart').find('.woobt-ids').length) {
556            return;
557        }
558
559        var wrap_id = $this.closest('form.cart').find('.woobt-ids').attr('data-id');
560        var $wrap = $('.woobt-wrap-' + wrap_id);
561        var $products = $wrap.find('.woobt-products');
562        var optional = $products.attr('data-optional');
563        var sync_qty = $products.attr('data-sync-qty');
564
565        $products.find('.woobt-product-this').attr('data-qty', qty);
566
567        $products.find('.woobt-product-together').each(function () {
568            var $item = $(this);
569            var item_qty_mode = $item.attr('data-qty-mode');
570            var item_sync_qty = $item.attr('data-sync-qty');
571            var should_sync = false;
572
573            if (item_qty_mode === 'sync' || item_sync_qty === 'on') {
574                should_sync = true;
575            } else if (item_qty_mode === 'custom' || item_qty_mode === 'default') {
576                should_sync = false;
577            } else if ((optional !== 'on') && (sync_qty === 'on')) {
578                should_sync = true;
579            }
580
581            if (should_sync) {
582                var _qty = parseFloat($item.attr('data-o_qty')) * qty;
583
584                $item.attr('data-qty', _qty);
585                $item.find('.woobt-qty-num .woobt-qty').html(_qty);
586            }
587        });
588
589        woobt_init($wrap);
590    });
591
592    $(document).on('click touch', '.woobt-form .single_add_to_cart_button', function (e) {
593        e.preventDefault();
594        var $btn = $(this);
595        var $form = $btn.closest('.woobt-form');
596        var $wrap = $btn.closest('.woobt-wrap');
597        // variable product
598        var data = {};
599        var attrs = {};
600
601        $btn.removeClass('added').addClass('loading');
602
603        $wrap.find('.woobt-product-this select[name^=attribute]').each(function () {
604            var attribute = $(this).attr('name');
605
606            attrs[attribute] = $(this).val();
607        });
608
609        data.action = 'woobt_add_all_to_cart';
610        data.quantity = $form.find('input[name="quantity"]').val();
611        data.product_id = $form.find('input[name="product_id"]').val();
612        data.variation_id = $form.find('input[name="variation_id"]').val();
613        data.woobt_ids = $form.find('input[name="woobt_ids"]').val();
614        data.variation = attrs;
615        data.nonce = woobt_vars.nonce;
616
617        $.post(woobt_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woobt_add_all_to_cart'), data, function (response) {
618            if (!response) {
619                return;
620            }
621
622            if (response.error && response.product_url) {
623                window.location = response.product_url;
624                return;
625            }
626
627            if ((typeof wc_add_to_cart_params !== 'undefined') && (wc_add_to_cart_params.cart_redirect_after_add === 'yes')) {
628                window.location = wc_add_to_cart_params.cart_url;
629                return;
630            }
631
632            $btn.removeClass('loading');
633            $(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $btn]);
634            $(document.body).trigger('woobt_added_to_cart', [response.fragments, response.cart_hash, $btn]);
635        });
636    });
637})(jQuery);
638
639function woobt_init($wrap) {
640    // has placeholder for variable product
641    if ($wrap.data('variable') === undefined) {
642        $wrap.data('variable', $wrap.html());
643    }
644
645    if ($wrap.find('.woobt-products').length) {
646        var pid = $wrap.attr('data-id');
647        var $ids = jQuery('.woobt-ids-' + pid).length ? jQuery('.woobt-ids-' + pid) : $wrap.find('.woobt-ids');
648        var $form = $ids.closest('.woobt-form').length ? $ids.closest('.woobt-form') : $ids.closest('form.cart');
649
650        var $main_qty_input = $form.find('.qty').not('.woobt-qty').not('.woobt-quantity .qty').first();
651
652        if ($form.length && $main_qty_input.length) {
653            var main_qty = parseFloat($main_qty_input.val());
654
655            if (main_qty > 0) {
656                var $products = $wrap.find('.woobt-products');
657                var optional = $products.attr('data-optional');
658                var sync_qty = $products.attr('data-sync-qty');
659
660                $products.find('.woobt-product-this').attr('data-qty', main_qty);
661
662                $products.find('.woobt-product-together').each(function () {
663                    var $item = jQuery(this);
664                    var item_qty_mode = $item.attr('data-qty-mode');
665                    var item_sync_qty = $item.attr('data-sync-qty');
666                    var should_sync = false;
667
668                    if (item_qty_mode === 'sync' || item_sync_qty === 'on') {
669                        should_sync = true;
670                    } else if (item_qty_mode === 'custom' || item_qty_mode === 'default') {
671                        should_sync = false;
672                    } else if ((optional !== 'on') && (sync_qty === 'on')) {
673                        should_sync = true;
674                    }
675
676                    if (should_sync) {
677                        var _qty = parseFloat($item.attr('data-o_qty')) * main_qty;
678
679                        $item.attr('data-qty', _qty);
680                        $item.find('.woobt-qty-num .woobt-qty').html(_qty);
681                    }
682                });
683            }
684        }
685
686        woobt_carousel($wrap);
687        woobt_check_ready($wrap);
688        woobt_calc_price($wrap);
689        woobt_save_ids($wrap);
690
691        if (woobt_vars.counter !== 'hide') {
692            woobt_update_count($wrap);
693        }
694    }
695
696    jQuery(document).trigger('woobt_init', [$wrap]);
697}
698
699function woobt_carousel($wrap) {
700    if ($wrap.find('[class*="woobt-products-layout-carousel"]').length) {
701        let slides = 2;
702        let carousel = JSON.parse(woobt_vars.carousel_params);
703        let $products = $wrap.find('[class*="woobt-products-layout-carousel"]');
704
705        if ($products.hasClass('woobt-products-layout-carousel-2') || $products.hasClass('woobt-products-layout-carousel-3') || $products.hasClass('woobt-products-layout-carousel-4')) {
706            if ($products.hasClass('woobt-products-layout-carousel-3')) {
707                slides = 3;
708            } else if ($products.hasClass('woobt-products-layout-carousel-4')) {
709                slides = 4;
710            }
711
712            carousel.slidesToShow = slides;
713            carousel.slidesToScroll = slides;
714
715            if ($products.find('.woobt-product:not(.woobt-hide-this)').length > slides) {
716                if (!$products.hasClass('woobt-carousel')) {
717                    $products.addClass('woobt-carousel').slick(carousel);
718
719                    if ($products.find('.woobt-hide-this').length) {
720                        $products.slick('slickFilter', '.woobt-product:not(.woobt-hide-this)');
721                    }
722                }
723            } else {
724                if ($products.hasClass('woobt-carousel')) {
725                    $products.removeClass('woobt-carousel').slick('unslick');
726                }
727
728                $products.addClass('woobt-no-carousel');
729            }
730        }
731    }
732}
733
734function woobt_check_position($wrap) {
735    var pid = $wrap.attr('data-id');
736    var position = $wrap.attr('data-position');
737    var atc_button = $wrap.attr('data-atc-button');
738    var $products = $wrap.find('.woobt-products');
739    var $ids = $wrap.parent().find('.woobt-ids-' + pid);
740
741    if ((position === 'before') && (atc_button === 'main' || atc_button === 'both') && (($products.attr('data-product-type') === 'variable') || ($products.attr('data-product-type') === 'variable-subscription')) && ($products.attr('data-variables') === 'no' || woobt_vars.variation_selector === 'woovr')) {
742        $wrap.insertAfter($ids);
743    }
744
745    jQuery(document).trigger('woobt_check_position', [$wrap]);
746}
747
748function woobt_check_ready($wrap) {
749    var pid = $wrap.attr('data-id');
750    var $products = $wrap.find('.woobt-products');
751    var $alert = $wrap.find('.woobt-alert');
752    var $ids = jQuery('.woobt-ids-' + pid);
753    var $form = $ids.closest('.woobt-form').length ? $ids.closest('.woobt-form') : $ids.closest('form.cart');
754    var $btn = $form.find('.single_add_to_cart_button:not(.wpcbn-btn)');
755    var is_selection = false;
756    var is_empty = true;
757    var selection_name = '';
758
759    $products.find('.woobt-product').each(function () {
760        var $this = jQuery(this);
761
762        if ($this.hasClass('woobt-hide-this')) {
763            // skip
764            return true;
765        }
766
767        var _id = parseInt($this.attr('data-id'));
768        var _qty = parseInt($this.attr('data-qty'));
769        var _order = parseInt($this.attr('data-order'));
770        var _checked = $this.find('.woobt-checkbox').prop('checked');
771
772        if (!_checked) {
773            $this.addClass('woobt-hide');
774            $wrap.find('.woobt-image-order-' + _order).addClass('woobt-image-hide');
775        } else {
776            $this.removeClass('woobt-hide');
777            $wrap.find('.woobt-image-order-' + _order).removeClass('woobt-image-hide');
778        }
779
780        if (_checked && (_id === 0) && (_qty > 0)) {
781            is_selection = true;
782
783            if (selection_name === '') {
784                selection_name = $this.attr('data-name');
785            }
786        }
787
788        if (!$this.hasClass('woobt-product-this') && _checked && (_id > 0) && (_qty > 0)) {
789            is_empty = false;
790        }
791    });
792
793    if (is_selection) {
794        $btn.addClass('woobt-disabled woobt-selection');
795        $alert.html(woobt_vars.alert_selection.replace('[name]', '<strong>' + selection_name + '</strong>')).slideDown();
796    } else {
797        $btn.removeClass('woobt-disabled woobt-selection');
798        $alert.html('').slideUp();
799    }
800
801    // trigger
802    jQuery(document).trigger('woobt_check_ready', [is_empty, is_selection, $wrap]);
803}
804
805function woobt_calc_price($wrap) {
806    var pid = $wrap.attr('data-id');
807    var atc_button = $wrap.attr('data-atc-button');
808    var $additional = $wrap.find('.woobt-additional');
809    var $total = $wrap.find('.woobt-total');
810    var $products = $wrap.find('.woobt-products');
811    var $product_this = $products.find('.woobt-product-this');
812    var count = 0, total = 0, total_regular = 0;
813    var ori_price_suffix = $products.attr('data-product-price-suffix');
814    var ori_price = parseFloat($product_this.length ? $product_this.attr('data-price') : 0);
815    var ori_price_regular = parseFloat($product_this.length ? $product_this.attr('data-regular-price') : 0);
816    var ori_qty = parseFloat($product_this.length ? $product_this.attr('data-qty') : 0);
817    var total_ori = ori_price * ori_qty;
818    var total_ori_regular = ori_price_regular * ori_qty;
819    var $price = jQuery('.woobt-price-' + pid);
820    var show_price = $products.attr('data-show-price');
821    var fix = Math.pow(10, Number(woobt_vars.price_decimals) + 1);
822
823    if ((woobt_vars.change_price === 'yes_custom') && (woobt_vars.price_selector != null) && (woobt_vars.price_selector !== '')) {
824        $price = jQuery(woobt_vars.price_selector);
825    }
826
827    $products.find('.woobt-product-together').each(function () {
828        var $this = jQuery(this);
829        var _checked = $this.find('.woobt-checkbox').prop('checked');
830        var _id = parseInt($this.attr('data-id'));
831        var _qty = parseFloat($this.attr('data-qty'));
832        var _price = $this.attr('data-new-price') ?? '100%';
833        var _price_suffix = $this.attr('data-price-suffix');
834        var _sale_price = parseFloat($this.attr('data-price'));
835        var _regular_price = parseFloat($this.attr('data-regular-price'));
836        var _total_ori = 0, _total_ori_regular = 0, _total = 0;
837
838        _total_ori = _qty * _sale_price;
839        _total_ori_regular = _qty * _sale_price;
840
841        if (isNaN(_price)) {
842            // is percent
843            if (_price === '100%') {
844                _total_ori = _qty * _regular_price;
845                _total_ori_regular = _qty * _regular_price;
846                _total = _qty * _sale_price;
847            } else {
848                _total = _total_ori * parseFloat(_price) / 100;
849            }
850        } else {
851            _total = _qty * parseFloat(_price);
852        }
853
854        if (show_price === 'total') {
855            $this.find('.woobt-price-ori').hide();
856            $this.find('.woobt-price-new').html(woobt_price_html(_total_ori, _total) + _price_suffix).show();
857        }
858
859        // calc total
860        if (_checked && (_qty > 0) && (_id > 0)) {
861            count++;
862            total += _total;
863            total_regular += _total_ori_regular;
864            total_ori_regular += _total_ori_regular;
865        }
866    });
867
868    total = Math.round(total * fix) / fix;
869    total_regular = Math.round(total_regular * fix) / fix;
870
871    if ($product_this.length) {
872        var _this_id = parseInt($product_this.attr('data-id'));
873        var _this_qty = parseFloat($product_this.attr('data-qty'));
874
875        if (_this_qty > 0 && _this_id > 0) {
876            var _this_price_suffix = $product_this.attr('data-price-suffix');
877            var _this_sale_price = parseFloat($product_this.attr('data-price'));
878            var _this_new_price = _this_sale_price;
879            var _this_regular_price = parseFloat($product_this.attr('data-regular-price'));
880
881            if (total > 0 && parseFloat($product_this.attr('data-id')) > 0) {
882                var _this_price = $product_this.attr('data-new-price') ?? '100%';
883
884                if (isNaN(_this_price)) {
885                    // is percent
886                    if (_this_price !== '100%') {
887                        _this_new_price = woobt_round(_this_sale_price * parseFloat(_this_price) / 100);
888                    }
889                } else {
890                    _this_new_price = parseFloat(_this_price);
891                }
892
893                total_ori = _this_new_price * _this_qty;
894            }
895
896            $product_this.find('.woobt-price-ori').hide();
897
898            if (show_price === 'total') {
899                $product_this.find('.woobt-price-new').html(woobt_price_html(_this_qty * _this_regular_price, _this_qty * _this_new_price) + _this_price_suffix).show();
900            } else {
901                $product_this.find('.woobt-price-new').html(woobt_price_html(_this_regular_price, _this_new_price) + _this_price_suffix).show();
902            }
903        } else {
904            $product_this.find('.woobt-price-new').hide();
905            $product_this.find('.woobt-price-ori').show();
906        }
907    }
908
909    if (count > 0) {
910        total_ori += total;
911
912        $additional.html(woobt_vars.additional_price_text + ' ' + woobt_price_html(total_regular, total) + ori_price_suffix).slideDown();
913        $total.html(woobt_vars.total_price_text + ' ' + woobt_price_html(total_ori_regular, total_ori) + ori_price_suffix).slideDown();
914    } else {
915        $additional.html('').slideUp();
916        $total.html('').slideUp();
917    }
918
919    // change the main price
920    if ((woobt_vars.change_price !== 'no') && (atc_button !== 'separate')) {
921        if (parseInt($wrap.attr('data-product-id')) > 0 && count > 0) {
922            $price.html(woobt_price_html(total_ori_regular, total_ori) + ori_price_suffix);
923        } else {
924            $price.html($wrap.attr('data-product-price-html'));
925        }
926    }
927
928    if ($wrap.find('.woobt-wrap').length) {
929        $wrap.find('.woobt-wrap').attr('data-total', total);
930    } else {
931        $wrap.attr('data-total', total);
932    }
933
934    jQuery(document).trigger('woobt_calc_price', [total, total_ori, total_ori_regular, $wrap]);
935}
936
937function woobt_save_ids($wrap) {
938    var pid = $wrap.attr('data-id');
939    var $products = $wrap.find('.woobt-products');
940    var sync_qty = $products.attr('data-sync-qty');
941    var $ids = jQuery('.woobt-ids-' + pid).length ? jQuery('.woobt-ids-' + pid) : $wrap.find('.woobt-ids');
942    var items = [];
943
944    $products.find('.woobt-product-together').each(function () {
945        var $this = jQuery(this);
946        var checked = $this.find('.woobt-checkbox').prop('checked');
947        var id = parseInt($this.attr('data-id'));
948        var key = $this.data('key');
949        var qty = parseFloat($this.attr('data-qty'));
950        var qty_ori = parseFloat($this.attr('data-o_qty'));
951        var attrs = $this.attr('data-attrs');
952
953        if (checked && (qty > 0) && (id > 0)) {
954            if (attrs !== undefined) {
955                attrs = encodeURIComponent(attrs);
956            } else {
957                attrs = '';
958            }
959
960            var item_qty_mode = $this.attr('data-qty-mode');
961            var item_sync_qty = $this.attr('data-sync-qty');
962            var is_sync = false;
963
964            if (item_qty_mode === 'sync' || item_sync_qty === 'on') {
965                is_sync = true;
966            } else if (item_qty_mode === 'custom' || item_qty_mode === 'default') {
967                is_sync = false;
968            } else if (sync_qty === 'on') {
969                is_sync = true;
970            }
971
972            if (is_sync) {
973                items.push(id + '/' + key + '/' + qty_ori + '/' + attrs);
974            } else {
975                items.push(id + '/' + key + '/' + qty + '/' + attrs);
976            }
977        }
978    });
979
980    if (items.length > 0) {
981        $ids.val(items.join(','));
982    } else {
983        $ids.val('');
984    }
985
986    jQuery(document.body).trigger('woobt_save_ids', [items, $wrap]);
987}
988
989function woobt_update_count($wrap) {
990    var pid = $wrap.attr('data-id');
991    var ignore_this = $wrap.attr('data-ignore-this');
992    var $products = $wrap.find('.woobt-products');
993    var $main_btn = jQuery('.woobt-ids-' + pid).closest('form.cart').find('.single_add_to_cart_button:not(.wpcbn-btn)');
994    var $separate_btn = jQuery('.woobt-ids-' + pid).closest('.woobt-form').find('.single_add_to_cart_button:not(.wpcbn-btn)');
995    var qty = 0;
996    var num = 0;
997
998    $products.find('.woobt-product').each(function () {
999        var $this = jQuery(this);
1000        var _checked = $this.find('.woobt-checkbox').prop('checked');
1001        var _id = parseInt($this.attr('data-id'));
1002        var _qty = parseFloat($this.attr('data-qty'));
1003
1004        if (_checked && (_qty > 0) && (_id > 0)) {
1005            qty += _qty;
1006            num++;
1007        }
1008    });
1009
1010    if ((num > 1) || (ignore_this === 'yes' && num > 0)) {
1011        if (woobt_vars.counter === 'individual') {
1012            if ($main_btn.find('.woobt-count').length) {
1013                $main_btn.find('.woobt-count').text(num);
1014            } else {
1015                $main_btn.append('<span class="woobt-count">' + num + '</span>');
1016            }
1017
1018            if ($separate_btn.find('.woobt-count').length) {
1019                $separate_btn.find('.woobt-count').text(num);
1020            } else {
1021                $separate_btn.append('<span class="woobt-count">' + num + '</span>');
1022            }
1023        } else {
1024            if ($main_btn.find('.woobt-count').length) {
1025                $main_btn.find('.woobt-count').text(qty);
1026            } else {
1027                $main_btn.append('<span class="woobt-count">' + qty + '</span>');
1028            }
1029
1030            if ($separate_btn.find('.woobt-count').length) {
1031                $separate_btn.find('.woobt-count').text(qty);
1032            } else {
1033                $separate_btn.append('<span class="woobt-count">' + qty + '</span>');
1034            }
1035        }
1036    } else {
1037        $main_btn.find('.woobt-count').remove();
1038        $separate_btn.find('.woobt-count').remove();
1039    }
1040
1041    jQuery(document.body).trigger('woobt_update_count', [num, qty, $wrap]);
1042}
1043
1044function woobt_format_money(number, places, symbol, thousand, decimal) {
1045    number = number || 0;
1046    places = !isNaN(places = Math.abs(places)) ? places : 2;
1047    symbol = symbol !== undefined ? symbol : '$';
1048    thousand = thousand !== undefined ? thousand : ',';
1049    decimal = decimal !== undefined ? decimal : '.';
1050
1051    var negative = number < 0 ? '-' : '', i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '', j = 0;
1052
1053    if (i.length > 3) {
1054        j = i.length % 3;
1055    }
1056
1057    if (woobt_vars.trim_zeros === '1') {
1058        return symbol + negative + (j ? i.substr(0, j) + thousand : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (places && (parseFloat(number) > parseFloat(i)) ? decimal + Math.abs(number - i).toFixed(places).slice(2).replace(/(\d*?[1-9])0+$/g, '$1') : '');
1059    } else {
1060        return symbol + negative + (j ? i.substr(0, j) + thousand : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : '');
1061    }
1062}
1063
1064function woobt_format_price(total) {
1065    var total_html = '<span class="woocommerce-Price-amount amount">';
1066    var total_formatted = woobt_format_money(total, woobt_vars.price_decimals, '', woobt_vars.price_thousand_separator, woobt_vars.price_decimal_separator);
1067
1068    switch (woobt_vars.price_format) {
1069        case '%1$s%2$s':
1070            // left
1071            total_html += '<span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span>' + total_formatted;
1072            break;
1073        case '%1$s %2$s':
1074            // left with space
1075            total_html += '<span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span> ' + total_formatted;
1076            break;
1077        case '%2$s%1$s':
1078            // right
1079            total_html += total_formatted + '<span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span>';
1080            break;
1081        case '%2$s %1$s':
1082            // right with space
1083            total_html += total_formatted + ' <span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span>';
1084            break;
1085        default:
1086            // default
1087            total_html += '<span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span> ' + total_formatted;
1088    }
1089
1090    total_html += '</span>';
1091
1092    return total_html;
1093}
1094
1095function woobt_price_html(regular_price, sale_price) {
1096    var price_html = '';
1097
1098    if (parseFloat(woobt_round(sale_price)) < parseFloat(woobt_round(regular_price))) {
1099        price_html = '<del>' + woobt_format_price(regular_price) + '</del> <ins>' + woobt_format_price(sale_price) + '</ins>';
1100    } else {
1101        price_html = woobt_format_price(regular_price);
1102    }
1103
1104    return price_html;
1105}
1106
1107function woobt_decimal_places(num) {
1108    var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
1109
1110    if (!match) {
1111        return 0;
1112    }
1113
1114    return Math.max(0, // Number of digits right of decimal point.
1115        (match[1] ? match[1].length : 0)
1116        // Adjust for scientific notation.
1117        - (match[2] ? +match[2] : 0));
1118}
1119
1120function woobt_round(value) {
1121    return Number(Math.round(value + 'e' + woobt_vars.price_decimals) + 'e-' + woobt_vars.price_decimals);
1122}

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.