PageSourceSearch

https://restaurantmargineni.ro/wp-content/plugins/woocommerce-ajax…/js/add-to-cart-variation.js?ver=7.1.2

js restaurantmargineni.ro collected 2026-10-02 15:44:05 UTC 3,463 bytes, 132 lines download raw bytes

1/* Wc add to cart version 2.2 */
2jQuery(function ($) {
3
4	// wc_add_to_cart_params is required to continue, ensure the object exists
5	if (typeof wc_add_to_cart_params === 'undefined')
6		return false;
7
8	// Ajax add to cart
9
10	var checkRequiredFields = $('.single_variation_wrap .wc-pao-required-addon').length;
11	$(document).on('click', '.variations_form .single_add_to_cart_button', function (e) {
12
13		e.preventDefault();
14
15		if (($(".single_variation_wrap .wc-pao-required-addon input:checked").length) < checkRequiredFields) {
16			alert("Selectati toate campurile obligatorii.");
17
18			return true;
19		}
20
21		$variation_form = $(this).closest('.variations_form');
22		var var_id = $variation_form.find('input[name=variation_id]').val();
23		var product_id = $variation_form.find('input[name=product_id]').val();
24		var quantity = $variation_form.find('input[name=quantity]').val();
25
26		//attributes = [];
27		$('.ajaxerrors').remove();
28		var item = {},
29			check = true;
30
31		variations = $variation_form.find('select[name^=attribute]');
32
33		/* Updated code to work with radio button - mantish - WC Variations Radio Buttons - 8manos */
34		if (!variations.length) {
35			variations = $variation_form.find('[name^=attribute]:checked');
36		}
37
38		/* Backup Code for getting input variable */
39		if (!variations.length) {
40			variations = $variation_form.find('input[name^=attribute]');
41		}
42
43		variations.each(function () {
44
45			var $this = $(this),
46				attributeName = $this.attr('name'),
47				attributevalue = $this.val(),
48				index,
49				attributeTaxName;
50
51			$this.removeClass('error');
52
53			if (attributevalue.length === 0) {
54				index = attributeName.lastIndexOf('_');
55				attributeTaxName = attributeName.substring(index + 1);
56
57				$this
58					.addClass('required error')
59					.before('<div class="ajaxerrors"><p>Please select ' + attributeTaxName + '</p></div>')
60
61				check = false;
62			} else {
63				item[attributeName] = attributevalue;
64			}
65
66		});
67
68		if (!check) {
69			return false;
70		}
71
72		var $thisbutton = $(this);
73
74		if ($thisbutton.is('.variations_form .single_add_to_cart_button')) {
75
76			$thisbutton.removeClass('added');
77			$thisbutton.addClass('loading');
78
79			var data = {
80				action: 'woocommerce_add_to_cart_variable_rc',
81			};
82
83			$variation_form.serializeArray().map(function (attr) {
84				if (attr.name !== 'add-to-cart') {
85					if (attr.name.endsWith('[]')) {
86						let name = attr.name.substring(0, attr.name.length - 2);
87						if (!(name in data)) {
88							data[name] = [];
89						}
90						data[name].push(attr.value);
91					} else {
92						data[attr.name] = attr.value;
93					}
94				}
95			});
96
97			// Trigger event
98			$('body').trigger('adding_to_cart', [$thisbutton, data]);
99
100			// Ajax action
101			$.post(wc_add_to_cart_params.ajax_url, data, function (response) {
102
103				if (!response) {
104					return;
105				}
106
107				if (response.error && response.product_url) {
108					window.location = response.product_url;
109					return;
110				}
111
112				// Redirect to cart option
113				if (wc_add_to_cart_params.cart_redirect_after_add === 'yes') {
114					window.location = wc_add_to_cart_params.cart_url;
115					return;
116				}
117
118				// Trigger event so themes can refresh other areas.
119				$(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $thisbutton]);
120				$("#cart_trigger").click();
121			});
122
123			return false;
124
125		} else {
126
127			return true;
128		}
129
130	});
131
132});

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.