PageSourceSearch

https://zumgarden.com/wp-content/plugins/buy-once-or-subscribe-for…/assets/js/single-product.js?ver=5.0.1

js zumgarden.com collected 2026-10-09 18:28:30 UTC 9,577 bytes, 239 lines download raw bytes

1/**
2 * Single product JS
3 *
4 * @package Buy Once or Subscribe for WooCommerce Subscriptions
5 * @since 1.0.0
6 */
7
8jQuery(
9    function ($) {
10        let bos4w_plan_select = $('.bos4w-buy-type');
11        let bos4w_button_text = $('.single_add_to_cart_button');
12        let bos4w_variable_product = $('form.variations_form');
13        let bos4w_display_dropdown_wrap = $('.bos4w-display-wrap');
14        let bos4w_display_dropdown = $('#bos4w-dropdown-plan');
15
16        if (wpr_bos4w_js.bos4w_is_product) {
17            // bos4w_button_text.html( wpr_bos4w_js.bos4w_buy_now );
18        }
19
20        if (bos4w_variable_product.length > 0) {
21            bos4w_display_dropdown_wrap.hide();
22        }
23
24        if ($('form.cart').hasClass('bundle_form')) {
25            jQuery(document.body).on(
26                'woocommerce-bundled-item-totals-changed',
27                function (event, bundle) {
28                    setTimeout(function () {
29                        let bundle_price_html = bundle.get_bundle().get_price_html(),
30                            bundle_price_inner_html = $(bundle_price_html).html();
31
32                        let the_price = bundle_price_inner_html.match(/\d+/g);
33                        let bundle_price = the_price[0] + '.' + the_price[1];
34
35                        if (the_price[2] && the_price[3]) {
36                            bundle_price = the_price[2] + '.' + the_price[3];
37                        }
38
39                        bundle_price = parseFloat(bundle_price);
40
41                        bos4w_display_dropdown.find('option').each(function (index, element) {
42                            let text = element.text;
43                            let current_price = element.dataset.price;
44                            let discount_amount = element.dataset.discount;
45                            let data_type = element.dataset.type;
46                            let bmult = 0;
47
48                            if ('fixed_price' === data_type) {
49                                bmult = discount_amount;
50                            } else {
51                                let dec = (discount_amount / 100).toFixed(2);
52                                bmult = bundle_price * dec;
53                            }
54
55                            let new_price = bundle_price - bmult;
56
57                            element.dataset.price = new_price.toFixed(2);
58                            new_price = new_price.toFixed(2);
59
60                            if (',' === wpr_bos4w_js.decimal_separator) {
61                                current_price = current_price.replace('.', ',');
62                                new_price = new_price.replace('.', ',');
63                            }
64
65                            text = text.replace(addZeroes(current_price), addZeroes(new_price));
66                            $(this).text(text);
67                        });
68
69                        $('#bos4w-selected-price').val($("#bos4w-dropdown-plan option:selected").attr("data-price"));
70
71                    }, 500);
72                }
73            );
74        } else if ($('form.cart').hasClass('composite_form')) {
75            $('.composite_data').on('wc-composite-initializing', function (event, composite) {
76                composite.actions.add_action('component_totals_changed', function () {
77
78                    let composite_price_html = composite.composite_price_view.get_price_html(),
79                        composite_price_inner_html = $(composite_price_html).html();
80
81                    let the_price = composite_price_inner_html.match(/\d+/g);
82                    let composite_price = the_price[0] + '.' + the_price[1];
83
84                    if (the_price[2] && the_price[3]) {
85                        composite_price = the_price[2] + '.' + the_price[3];
86                    }
87
88                    composite_price = parseFloat(composite_price);
89
90                    bos4w_display_dropdown.find('option').each(function (index, element) {
91                        let text = element.text;
92                        let current_price = element.dataset.price;
93                        let discount_amount = element.dataset.discount;
94                        let data_type = element.dataset.type;
95                        let mult = 0;
96
97                        if ('fixed_price' === data_type) {
98                            mult = discount_amount;
99                        } else {
100                            let dec = (discount_amount / 100).toFixed(2);
101                            mult = composite_price * dec;
102                        }
103
104                        let new_price = composite_price - mult;
105
106                        element.dataset.price = new_price.toFixed(2);
107                        new_price = new_price.toFixed(2);
108
109                        if (',' === wpr_bos4w_js.decimal_separator) {
110                            current_price = current_price.replace('.', ',');
111                            new_price = new_price.replace('.', ',');
112                        }
113
114                        text = text.replace(addZeroes(current_price), addZeroes(new_price));
115                        $(this).text(text);
116                    });
117
118                    setTimeout(function () {
119                        $('#bos4w-selected-price').val($("#bos4w-dropdown-plan option:selected").attr("data-price"));
120                    }, 500);
121                }, 51, this);
122            });
123        } else {
124            $('.single_variation_wrap').on(
125                'show_variation',
126                function (event, variation) {
127                    updateSubscriptionPlans(variation);
128                }
129            );
130        }
131
132        bos4w_display_dropdown.on('change', function () {
133            $('#bos4w-selected-price').val($(this).find(":selected").attr("data-price"));
134        });
135
136        bos4w_plan_select.on(
137            'click',
138            function () {
139                let bos4w_select = $(this).val();
140                if ('1' === bos4w_select) {
141                    $('.bos4w-display-dropdown').show('slow');
142                } else {
143                    $('.bos4w-display-dropdown').hide('slow');
144                }
145
146                if (wpr_bos4w_js.bos4w_is_product) {
147                    if ('1' === bos4w_select) {
148                        bos4w_button_text.html(wpr_bos4w_js.bos4w_subscribe);
149                    } else {
150                        bos4w_button_text.html(wpr_bos4w_js.bos4w_buy_now);
151                    }
152                }
153            }
154        );
155
156        function updateSubscriptionPlans(variation) {
157            let variationTitle = variation.bos4w_subscription_title || wpr_bos4w_js.bos4w_display_text;
158            let discountText = variation.bos4w_discount_text || '';
159
160            if (discountText) {
161                $('.bos-display-save-up-to').html(discountText);
162            }
163
164            // Update the display title
165            $('.bos4w-display-plan-text').text(variationTitle);
166
167            // Update the dropdown with the plans for the selected variation
168            bos4w_display_dropdown.empty();
169
170            let plans = variation.bos4w_discounted_price;
171
172            if (plans) {
173                bos4w_display_dropdown_wrap.show();
174
175                $.each(plans, function (index, plan) {
176                    let cleanDiscountedPrice = $(plan.discounted_price).text();
177                    let bos_type = plan.subscription_price ? 'fixed_price' : 'percentage_price';
178                    let display_discount = '';
179                    if (plan.display_discount && plan.display_discount.trim() !== '') {
180                        display_discount = ` (${plan.display_discount})`;
181                    }
182
183                    let optionText = htmlspecialchars_decode(plan.display);
184                    let optionValue = `${plan.subscription_period_interval}_${plan.subscription_period}_${bos_type === 'fixed_price' ? plan.subscription_price : plan.subscription_discount}`;
185                    let optionData = {
186                        'value': optionValue,
187                        'data-discount': bos_type === 'fixed_price' ? plan.subscription_price : plan.subscription_discount,
188                        'data-price': plan.float_discounted,
189                        'data-type': bos_type
190                    };
191                    bos4w_display_dropdown.append($('<option>', optionData).text(optionText));
192                });
193            } else {
194                bos4w_display_dropdown_wrap.hide();
195            }
196
197            setTimeout(function () {
198                $('#bos4w-selected-price').val($("#bos4w-dropdown-plan option:selected").attr("data-price"));
199            }, 500);
200        }
201
202        function addZeroes(num) {
203            let value, res;
204
205            num.toString();
206
207            if (',' === wpr_bos4w_js.decimal_separator) {
208                res = num.split(",");
209            } else {
210                res = num.split(".");
211            }
212
213            value = Number(num);
214            if (isNaN(Number(num))) {
215                value = num;
216            }
217
218            if (res.length === 1 || res[1].length < 3) {
219                if (undefined === res[1]) {
220                    value = res[0] + '.00';
221                } else {
222                    value = res[0] + '.' + res[1];
223                }
224
225                value = Number(value).toFixed(2);
226            }
227
228            if (',' === wpr_bos4w_js.decimal_separator) {
229                value = String(value).replace('.', ',');
230            }
231
232            return value;
233        }
234
235        function htmlspecialchars_decode(str) {
236            return $('<div>').html(str).text();
237        }
238    }
239);

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.