PageSourceSearch

https://actisense.com/wp-content/plugins/woo-bought-together/assets/js/frontend.js?ver=8.0.0

js actisense.com collected 2026-10-02 07:38:21 UTC 42,301 bytes, 1,057 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', '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        if ((optional !== 'on') && (sync_qty === 'on')) {
568            $products.find('.woobt-product-together').each(function () {
569                var _qty = parseFloat($(this).attr('data-o_qty')) * qty;
570
571                $(this).attr('data-qty', _qty);
572                $(this).find('.woobt-qty-num .woobt-qty').html(_qty);
573            });
574        }
575
576        woobt_init($wrap);
577    });
578
579    $(document).on('click touch', '.woobt-form .single_add_to_cart_button', function (e) {
580        e.preventDefault();
581        var $btn = $(this);
582        var $form = $btn.closest('.woobt-form');
583        var $wrap = $btn.closest('.woobt-wrap');
584        // variable product
585        var data = {};
586        var attrs = {};
587
588        $btn.removeClass('added').addClass('loading');
589
590        $wrap.find('.woobt-product-this select[name^=attribute]').each(function () {
591            var attribute = $(this).attr('name');
592
593            attrs[attribute] = $(this).val();
594        });
595
596        data.action = 'woobt_add_all_to_cart';
597        data.quantity = $form.find('input[name="quantity"]').val();
598        data.product_id = $form.find('input[name="product_id"]').val();
599        data.variation_id = $form.find('input[name="variation_id"]').val();
600        data.woobt_ids = $form.find('input[name="woobt_ids"]').val();
601        data.variation = attrs;
602        data.nonce = woobt_vars.nonce;
603
604        $.post(woobt_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woobt_add_all_to_cart'), data, function (response) {
605            if (!response) {
606                return;
607            }
608
609            if (response.error && response.product_url) {
610                window.location = response.product_url;
611                return;
612            }
613
614            if ((typeof wc_add_to_cart_params !== 'undefined') && (wc_add_to_cart_params.cart_redirect_after_add === 'yes')) {
615                window.location = wc_add_to_cart_params.cart_url;
616                return;
617            }
618
619            $btn.removeClass('loading');
620            $(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $btn]);
621            $(document.body).trigger('woobt_added_to_cart', [response.fragments, response.cart_hash, $btn]);
622        });
623    });
624})(jQuery);
625
626function woobt_init($wrap) {
627    // has placeholder for variable product
628    if ($wrap.data('variable') === undefined) {
629        $wrap.data('variable', $wrap.html());
630    }
631
632    if ($wrap.find('.woobt-products').length) {
633        woobt_carousel($wrap);
634        woobt_check_ready($wrap);
635        woobt_calc_price($wrap);
636        woobt_save_ids($wrap);
637
638        if (woobt_vars.counter !== 'hide') {
639            woobt_update_count($wrap);
640        }
641    }
642
643    jQuery(document).trigger('woobt_init', [$wrap]);
644}
645
646function woobt_carousel($wrap) {
647    if ($wrap.find('[class*="woobt-products-layout-carousel"]').length) {
648        let slides = 2;
649        let carousel = JSON.parse(woobt_vars.carousel_params);
650        let $products = $wrap.find('[class*="woobt-products-layout-carousel"]');
651
652        if ($products.hasClass('woobt-products-layout-carousel-2') || $products.hasClass('woobt-products-layout-carousel-3') || $products.hasClass('woobt-products-layout-carousel-4')) {
653            if ($products.hasClass('woobt-products-layout-carousel-3')) {
654                slides = 3;
655            } else if ($products.hasClass('woobt-products-layout-carousel-4')) {
656                slides = 4;
657            }
658
659            carousel.slidesToShow = slides;
660            carousel.slidesToScroll = slides;
661
662            if ($products.find('.woobt-product:not(.woobt-hide-this)').length > slides) {
663                if (!$products.hasClass('woobt-carousel')) {
664                    $products.addClass('woobt-carousel').slick(carousel);
665
666                    if ($products.find('.woobt-hide-this').length) {
667                        $products.slick('slickFilter', '.woobt-product:not(.woobt-hide-this)');
668                    }
669                }
670            } else {
671                if ($products.hasClass('woobt-carousel')) {
672                    $products.removeClass('woobt-carousel').slick('unslick');
673                }
674
675                $products.addClass('woobt-no-carousel');
676            }
677        }
678    }
679}
680
681function woobt_check_position($wrap) {
682    var pid = $wrap.attr('data-id');
683    var position = $wrap.attr('data-position');
684    var atc_button = $wrap.attr('data-atc-button');
685    var $products = $wrap.find('.woobt-products');
686    var $ids = $wrap.parent().find('.woobt-ids-' + pid);
687
688    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')) {
689        $wrap.insertAfter($ids);
690    }
691
692    jQuery(document).trigger('woobt_check_position', [$wrap]);
693}
694
695function woobt_check_ready($wrap) {
696    var pid = $wrap.attr('data-id');
697    var $products = $wrap.find('.woobt-products');
698    var $alert = $wrap.find('.woobt-alert');
699    var $ids = jQuery('.woobt-ids-' + pid);
700    var $form = $ids.closest('.woobt-form').length ? $ids.closest('.woobt-form') : $ids.closest('form.cart');
701    var $btn = $form.find('.single_add_to_cart_button:not(.wpcbn-btn)');
702    var is_selection = false;
703    var is_empty = true;
704    var selection_name = '';
705
706    $products.find('.woobt-product').each(function () {
707        var $this = jQuery(this);
708
709        if ($this.hasClass('woobt-hide-this')) {
710            // skip
711            return true;
712        }
713
714        var _id = parseInt($this.attr('data-id'));
715        var _qty = parseInt($this.attr('data-qty'));
716        var _order = parseInt($this.attr('data-order'));
717        var _checked = $this.find('.woobt-checkbox').prop('checked');
718
719        if (!_checked) {
720            $this.addClass('woobt-hide');
721            $wrap.find('.woobt-image-order-' + _order).addClass('woobt-image-hide');
722        } else {
723            $this.removeClass('woobt-hide');
724            $wrap.find('.woobt-image-order-' + _order).removeClass('woobt-image-hide');
725        }
726
727        if (_checked && (_id === 0) && (_qty > 0)) {
728            is_selection = true;
729
730            if (selection_name === '') {
731                selection_name = $this.attr('data-name');
732            }
733        }
734
735        if (!$this.hasClass('woobt-product-this') && _checked && (_id > 0) && (_qty > 0)) {
736            is_empty = false;
737        }
738    });
739
740    if (is_selection) {
741        $btn.addClass('woobt-disabled woobt-selection');
742        $alert.html(woobt_vars.alert_selection.replace('[name]', '<strong>' + selection_name + '</strong>')).slideDown();
743    } else {
744        $btn.removeClass('woobt-disabled woobt-selection');
745        $alert.html('').slideUp();
746    }
747
748    // trigger
749    jQuery(document).trigger('woobt_check_ready', [is_empty, is_selection, $wrap]);
750}
751
752function woobt_calc_price($wrap) {
753    var pid = $wrap.attr('data-id');
754    var atc_button = $wrap.attr('data-atc-button');
755    var $additional = $wrap.find('.woobt-additional');
756    var $total = $wrap.find('.woobt-total');
757    var $products = $wrap.find('.woobt-products');
758    var $product_this = $products.find('.woobt-product-this');
759    var count = 0, total = 0, total_regular = 0;
760    var ori_price_suffix = $products.attr('data-product-price-suffix');
761    var ori_price = parseFloat($product_this.length ? $product_this.attr('data-price') : 0);
762    var ori_price_regular = parseFloat($product_this.length ? $product_this.attr('data-regular-price') : 0);
763    var ori_qty = parseFloat($product_this.length ? $product_this.attr('data-qty') : 0);
764    var total_ori = ori_price * ori_qty;
765    var total_ori_regular = ori_price_regular * ori_qty;
766    var $price = jQuery('.woobt-price-' + pid);
767    var show_price = $products.attr('data-show-price');
768    var fix = Math.pow(10, Number(woobt_vars.price_decimals) + 1);
769
770    if ((woobt_vars.change_price === 'yes_custom') && (woobt_vars.price_selector != null) && (woobt_vars.price_selector !== '')) {
771        $price = jQuery(woobt_vars.price_selector);
772    }
773
774    $products.find('.woobt-product-together').each(function () {
775        var $this = jQuery(this);
776        var _checked = $this.find('.woobt-checkbox').prop('checked');
777        var _id = parseInt($this.attr('data-id'));
778        var _qty = parseFloat($this.attr('data-qty'));
779        var _price = $this.attr('data-new-price') ?? '100%';
780        var _price_suffix = $this.attr('data-price-suffix');
781        var _sale_price = parseFloat($this.attr('data-price'));
782        var _regular_price = parseFloat($this.attr('data-regular-price'));
783        var _total_ori = 0, _total_ori_regular = 0, _total = 0;
784
785        _total_ori = _qty * _sale_price;
786        _total_ori_regular = _qty * _sale_price;
787
788        if (isNaN(_price)) {
789            // is percent
790            if (_price === '100%') {
791                _total_ori = _qty * _regular_price;
792                _total_ori_regular = _qty * _regular_price;
793                _total = _qty * _sale_price;
794            } else {
795                _total = _total_ori * parseFloat(_price) / 100;
796            }
797        } else {
798            _total = _qty * parseFloat(_price);
799        }
800
801        if (show_price === 'total') {
802            $this.find('.woobt-price-ori').hide();
803            $this.find('.woobt-price-new').html(woobt_price_html(_total_ori, _total) + _price_suffix).show();
804        }
805
806        // calc total
807        if (_checked && (_qty > 0) && (_id > 0)) {
808            count++;
809            total += _total;
810            total_regular += _total_ori_regular;
811            total_ori_regular += _total_ori_regular;
812        }
813    });
814
815    total = Math.round(total * fix) / fix;
816    total_regular = Math.round(total_regular * fix) / fix;
817
818    if ($product_this.length) {
819        var _this_id = parseInt($product_this.attr('data-id'));
820        var _this_qty = parseFloat($product_this.attr('data-qty'));
821
822        if (_this_qty > 0 && _this_id > 0) {
823            var _this_price_suffix = $product_this.attr('data-price-suffix');
824            var _this_sale_price = parseFloat($product_this.attr('data-price'));
825            var _this_new_price = _this_sale_price;
826            var _this_regular_price = parseFloat($product_this.attr('data-regular-price'));
827
828            if (total > 0 && parseFloat($product_this.attr('data-id')) > 0) {
829                var _this_price = $product_this.attr('data-new-price') ?? '100%';
830
831                if (isNaN(_this_price)) {
832                    // is percent
833                    if (_this_price !== '100%') {
834                        _this_new_price = woobt_round(_this_sale_price * parseFloat(_this_price) / 100);
835                    }
836                } else {
837                    _this_new_price = parseFloat(_this_price);
838                }
839
840                total_ori = _this_new_price * _this_qty;
841            }
842
843            $product_this.find('.woobt-price-ori').hide();
844
845            if (show_price === 'total') {
846                $product_this.find('.woobt-price-new').html(woobt_price_html(_this_qty * _this_regular_price, _this_qty * _this_new_price) + _this_price_suffix).show();
847            } else {
848                $product_this.find('.woobt-price-new').html(woobt_price_html(_this_regular_price, _this_new_price) + _this_price_suffix).show();
849            }
850        } else {
851            $product_this.find('.woobt-price-new').hide();
852            $product_this.find('.woobt-price-ori').show();
853        }
854    }
855
856    if (count > 0) {
857        total_ori += total;
858
859        $additional.html(woobt_vars.additional_price_text + ' ' + woobt_price_html(total_regular, total) + ori_price_suffix).slideDown();
860        $total.html(woobt_vars.total_price_text + ' ' + woobt_price_html(total_ori_regular, total_ori) + ori_price_suffix).slideDown();
861    } else {
862        $additional.html('').slideUp();
863        $total.html('').slideUp();
864    }
865
866    // change the main price
867    if ((woobt_vars.change_price !== 'no') && (atc_button !== 'separate')) {
868        if (parseInt($wrap.attr('data-product-id')) > 0 && count > 0) {
869            $price.html(woobt_price_html(total_ori_regular, total_ori) + ori_price_suffix);
870        } else {
871            $price.html($wrap.attr('data-product-price-html'));
872        }
873    }
874
875    if ($wrap.find('.woobt-wrap').length) {
876        $wrap.find('.woobt-wrap').attr('data-total', total);
877    } else {
878        $wrap.attr('data-total', total);
879    }
880
881    jQuery(document).trigger('woobt_calc_price', [total, total_ori, total_ori_regular, $wrap]);
882}
883
884function woobt_save_ids($wrap) {
885    var pid = $wrap.attr('data-id');
886    var $products = $wrap.find('.woobt-products');
887    var sync_qty = $products.attr('data-sync-qty');
888    var $ids = jQuery('.woobt-ids-' + pid).length ? jQuery('.woobt-ids-' + pid) : $wrap.find('.woobt-ids');
889    var items = [];
890
891    $products.find('.woobt-product-together').each(function () {
892        var $this = jQuery(this);
893        var checked = $this.find('.woobt-checkbox').prop('checked');
894        var id = parseInt($this.attr('data-id'));
895        var key = $this.data('key');
896        var qty = parseFloat($this.attr('data-qty'));
897        var qty_ori = parseFloat($this.attr('data-o_qty'));
898        var attrs = $this.attr('data-attrs');
899
900        if (checked && (qty > 0) && (id > 0)) {
901            if (attrs !== undefined) {
902                attrs = encodeURIComponent(attrs);
903            } else {
904                attrs = '';
905            }
906
907            if (sync_qty === 'on') {
908                items.push(id + '/' + key + '/' + qty_ori + '/' + attrs);
909            } else {
910                items.push(id + '/' + key + '/' + qty + '/' + attrs);
911            }
912        }
913    });
914
915    if (items.length > 0) {
916        $ids.val(items.join(','));
917    } else {
918        $ids.val('');
919    }
920
921    jQuery(document.body).trigger('woobt_save_ids', [items, $wrap]);
922}
923
924function woobt_update_count($wrap) {
925    var pid = $wrap.attr('data-id');
926    var ignore_this = $wrap.attr('data-ignore-this');
927    var $products = $wrap.find('.woobt-products');
928    var $main_btn = jQuery('.woobt-ids-' + pid).closest('form.cart').find('.single_add_to_cart_button:not(.wpcbn-btn)');
929    var $separate_btn = jQuery('.woobt-ids-' + pid).closest('.woobt-form').find('.single_add_to_cart_button:not(.wpcbn-btn)');
930    var qty = 0;
931    var num = 0;
932
933    $products.find('.woobt-product').each(function () {
934        var $this = jQuery(this);
935        var _checked = $this.find('.woobt-checkbox').prop('checked');
936        var _id = parseInt($this.attr('data-id'));
937        var _qty = parseFloat($this.attr('data-qty'));
938
939        if (_checked && (_qty > 0) && (_id > 0)) {
940            qty += _qty;
941            num++;
942        }
943    });
944
945    if ((num > 1) || (ignore_this === 'yes' && num > 0)) {
946        if (woobt_vars.counter === 'individual') {
947            if ($main_btn.find('.woobt-count').length) {
948                $main_btn.find('.woobt-count').text(num);
949            } else {
950                $main_btn.append('<span class="woobt-count">' + num + '</span>');
951            }
952
953            if ($separate_btn.find('.woobt-count').length) {
954                $separate_btn.find('.woobt-count').text(num);
955            } else {
956                $separate_btn.append('<span class="woobt-count">' + num + '</span>');
957            }
958        } else {
959            if ($main_btn.find('.woobt-count').length) {
960                $main_btn.find('.woobt-count').text(qty);
961            } else {
962                $main_btn.append('<span class="woobt-count">' + qty + '</span>');
963            }
964
965            if ($separate_btn.find('.woobt-count').length) {
966                $separate_btn.find('.woobt-count').text(qty);
967            } else {
968                $separate_btn.append('<span class="woobt-count">' + qty + '</span>');
969            }
970        }
971    } else {
972        $main_btn.find('.woobt-count').remove();
973        $separate_btn.find('.woobt-count').remove();
974    }
975
976    jQuery(document.body).trigger('woobt_update_count', [num, qty, $wrap]);
977}
978
979function woobt_format_money(number, places, symbol, thousand, decimal) {
980    number = number || 0;
981    places = !isNaN(places = Math.abs(places)) ? places : 2;
982    symbol = symbol !== undefined ? symbol : '$';
983    thousand = thousand !== undefined ? thousand : ',';
984    decimal = decimal !== undefined ? decimal : '.';
985
986    var negative = number < 0 ? '-' : '', i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '', j = 0;
987
988    if (i.length > 3) {
989        j = i.length % 3;
990    }
991
992    if (woobt_vars.trim_zeros === '1') {
993        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') : '');
994    } else {
995        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) : '');
996    }
997}
998
999function woobt_format_price(total) {
1000    var total_html = '<span class="woocommerce-Price-amount amount">';
1001    var total_formatted = woobt_format_money(total, woobt_vars.price_decimals, '', woobt_vars.price_thousand_separator, woobt_vars.price_decimal_separator);
1002
1003    switch (woobt_vars.price_format) {
1004        case '%1$s%2$s':
1005            // left
1006            total_html += '<span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span>' + total_formatted;
1007            break;
1008        case '%1$s %2$s':
1009            // left with space
1010            total_html += '<span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span> ' + total_formatted;
1011            break;
1012        case '%2$s%1$s':
1013            // right
1014            total_html += total_formatted + '<span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span>';
1015            break;
1016        case '%2$s %1$s':
1017            // right with space
1018            total_html += total_formatted + ' <span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span>';
1019            break;
1020        default:
1021            // default
1022            total_html += '<span class="woocommerce-Price-currencySymbol">' + woobt_vars.currency_symbol + '</span> ' + total_formatted;
1023    }
1024
1025    total_html += '</span>';
1026
1027    return total_html;
1028}
1029
1030function woobt_price_html(regular_price, sale_price) {
1031    var price_html = '';
1032
1033    if (parseFloat(woobt_round(sale_price)) < parseFloat(woobt_round(regular_price))) {
1034        price_html = '<del>' + woobt_format_price(regular_price) + '</del> <ins>' + woobt_format_price(sale_price) + '</ins>';
1035    } else {
1036        price_html = woobt_format_price(regular_price);
1037    }
1038
1039    return price_html;
1040}
1041
1042function woobt_decimal_places(num) {
1043    var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
1044
1045    if (!match) {
1046        return 0;
1047    }
1048
1049    return Math.max(0, // Number of digits right of decimal point.
1050        (match[1] ? match[1].length : 0)
1051        // Adjust for scientific notation.
1052        - (match[2] ? +match[2] : 0));
1053}
1054
1055function woobt_round(value) {
1056    return Number(Math.round(value + 'e' + woobt_vars.price_decimals) + 'e-' + woobt_vars.price_decimals);
1057}

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.