PageSourceSearch

https://www.particleformen.com/wp-content/themes/particleformen/as…/js/new_product_cart_js.js?ver=1770284522

js particleformen.com collected 2026-09-28 12:15:15 UTC 6,459 bytes, 161 lines download raw bytes

1jQuery(document).ready(function ($) {
2    var selectedProduct = 1; // Default to the first product
3    var activatedGifts = 0;
4
5    // Define the maximum number of gifts to activate for each product
6    var maxGifts = [4, 3, 2, 1]; // Adjust the numbers according to your requirements
7
8    function updateGifts() {
9        // 1) read the selected pack size
10        var selectedQty = parseInt($(".price-option.selected-product").attr("qty"), 10) || 0;
11
12        // 2) find the largest pack size across all options
13        var allQty = $(".price-option")
14            .map(function () {
15                return parseInt($(this).attr("qty"), 10) || 0;
16            })
17            .get();
18        var maxQty = Math.max.apply(null, allQty);
19
20        // 3) update the “gifts unlocked” text
21        $(".green-bottom-block .second").text("gifts unlocked: " + selectedQty + "/" + maxQty);
22    }
23
24    // ============================== Saving Block Function =========================================
25    function updateSavings() {
26        var originalPrice = parseFloat($(".price-option.selected-product").data("original-price"));
27        var discountedPrice = parseFloat($(".price-option.selected-product").data("discounted-price"));
28        var quantity = parseInt($(".price-option.selected-product").attr("qty"), 10); // Use attr to fetch the qty attribute
29
30        if (!isNaN(originalPrice) && !isNaN(discountedPrice) && !isNaN(quantity) && quantity > 0) {
31            // Calculate the total savings for the given quantity of items
32            var totalSavings = (originalPrice - discountedPrice) * quantity;
33            totalSavings = totalSavings.toFixed(); // Rounds to two decimal places for precision
34
35            // Update the savings amount text
36            $(".green-bottom-block .savings-amount").text(totalSavings); // Prefix with $ for currency
37
38            // Adjust visibility based on totalSavings
39            $(".green-bottom-block .first").css("visibility", totalSavings <= 0 ? "hidden" : "visible");
40        } else {
41            console.error("Invalid price data or quantity:", { originalPrice, discountedPrice, quantity });
42            $(".green-bottom-block .first").text("Error calculating savings");
43        }
44    }
45
46    // ============== Function to handle the product selection change ==========
47    $(".price-option").click(function (e) {
48        // Remove the active class from all price options
49        e.preventDefault();
50        $(".price-option").removeClass("active");
51
52        // Add the active class to the clicked price option
53        $(this).addClass("active");
54
55        // Remove the selected-product class from all price options
56        $(".price-option").removeClass("selected-product");
57
58        // Add the selected-product class to the clicked price option's container
59        $(this).addClass("selected-product");
60
61        // Determine the selected product based on its position in the list
62        selectedProduct = $(".price-option").index(this) + 1;
63
64        // Update the number of activated giftss
65        updateGifts();
66        updateSavings();
67
68        // 1. figure out what the max pack size is
69        var qtyOptions = $(".price-option")
70            .map(function () {
71                return parseInt($(this).attr("qty"), 10);
72            })
73            .get();
74        var maxQty = Math.max.apply(null, qtyOptions);
75
76        // 2. how many units the customer clicked
77        var qtySelected = parseInt($(this).attr("qty"), 10);
78
79        // 3. loop through each gift block
80        $(".sale-info-blocks .block").each(function () {
81            var $blk = $(this);
82            var $inactive = $blk.find(".inactive-overlay");
83            var $active = $blk.find(".active-overlay");
84
85            // shipping block has no inactive-overlay ⇒ always show
86            if (!$inactive.length) {
87                $blk.show();
88                return;
89            }
90
91            // read the threshold number out of "2+Bottles", "3+Bottles"
92            var threshold = parseInt($inactive.find("p").text(), 10);
93
94            // if threshold > your max pack size ⇒ drop the entire block
95            if (threshold > maxQty) {
96                $blk.hide();
97                return;
98            }
99
100            // otherwise show it…
101            $blk.show();
102
103            // …and lock/unlock based on selected qty
104            if (qtySelected >= threshold) {
105                $inactive.hide();
106                $active.show();
107            } else {
108                $inactive.show();
109                $active.hide();
110            }
111        });
112
113        $(".radio").removeClass("active");
114        $(this).find(".radio").addClass("active");
115        $(".radio").each(function () {
116            var isChecked = $(this).hasClass("active");
117            $(this).find(".checked").toggle(isChecked);
118            $(this).find(".unchecked").toggle(!isChecked);
119        });
120
121        var qty = $(this).attr("qty");
122        var discounted_price = $(this).attr("data-discounted-price");
123
124        var form = $(this).closest("form");
125        $("input[name='quantity']", form).val(qty);
126        if (discounted_price) {
127            $("input[name='custom_price']", form).val(discounted_price);
128        }
129    });
130
131    // Initial call to update gifts based on the default selected product
132    updateGifts();
133
134    // Simulate a click on the first product to make it active by default
135    $(".price-option:first").trigger("click");
136
137    // Trigger the update on initial load
138    $(".price-option:first").click();
139});
140
141jQuery(document).ready(function ($) {
142    $(".one-time-select-item").on("click", function (e) {
143        e.preventDefault();
144        $this = $(this);
145        $this.addClass("active").siblings(".one-time-select-item").removeClass("active");
146
147        if ($this.data("price")) {
148            let newPrice = $this.data("price"),
149                $closestDelivery = $this.closest(".delivery"),
150                $priceElement = $closestDelivery.find(".woocommerce-Price-amount bdi");
151
152            // Replace the price while keeping the currency symbol
153            let currencySymbol = $priceElement.find(".woocommerce-Price-currencySymbol").html();
154            $priceElement.html(`<span class="woocommerce-Price-currencySymbol">${currencySymbol}</span>${newPrice}`);
155        }
156
157        $form = $this.closest("form");
158        $form.find("input[name=quantity]").attr("value", $this.data("qty"));
159        $form.find(".btn").removeClass("inactive");
160    });
161});

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.