PageSourceSearch

https://www.mshvmanos.com/wp-content/plugins/wt-smart-coupons-for-…/assets/js/main.js?ver=2.2.4

js mshvmanos.com collected 2026-09-25 12:05:00 UTC 7,719 bytes, 206 lines download raw bytes

1jQuery(function ($) {
2    "use strict";
3
4    $(document).on('change', '.wt_give_away_product_attr', function(){
5               
6        const parent = $(this).closest('.wt_get_away_product');
7        const attributes = {};
8        parent.find('.wt_give_away_product_attr').each(function(index) {
9            attributes[$(this).attr('data-attribute_name')] = $(this).val();
10        });
11
12        if(""==$(this).val())
13        {
14            parent.find('input[name="variation_id"]').val(0);
15            parent.find('input[name="wt_variation_options"]').val(JSON.stringify( attributes ));
16            return false;
17        }
18
19        const product_id =parent.attr('product-id');
20
21        const data = {
22            'action'        : 'update_variation_id',
23            'attributes'    : attributes,
24            'product'       : product_id,
25            '_wpnonce'      : WTSmartCouponOBJ.nonces.public
26        };
27
28        $('.wt_choose_free_product, .wt_add_to_cart_all_btn, .checkout-button').prop('disabled', true).css({'opacity':.5, 'cursor':'not-allowed'});
29        $('.wt_get_away_product').css({'opacity':.5, 'cursor':'wait'});
30        jQuery.ajax({
31            type: "POST",
32            async: true,
33            url: WTSmartCouponOBJ.ajaxurl,
34            data: data,
35            dataType: 'json',
36            success:function(response)
37            {
38                $('.wt_choose_free_product, .wt_add_to_cart_all_btn, .checkout-button').prop('disabled', false).css({'opacity':1, 'cursor':'pointer'});
39                $('.wt_get_away_product').css({'opacity':1, 'cursor':'default'});
40                if(response.status==true)
41                {
42                    parent.find('input[name="variation_id"]').val(response.variation_id);
43                    parent.find('input[name="wt_variation_options"]').val(JSON.stringify( attributes ));
44                }else{
45                    parent.find('input[name="variation_id"]').val(0);
46                    alert(response.status_msg);
47                }              
48            },
49            error:function()
50            {
51                parent.find('input[name="variation_id"]').val(0);
52                $('.wt_choose_free_product, .wt_add_to_cart_all_btn, .checkout-button').prop('disabled', false).css({'opacity':1, 'cursor':'pointer'});
53                $('.wt_get_away_product').css({'opacity':1, 'cursor':'default'});
54                alert(WTSmartCouponOBJ.labels.error);
55            }
56        });
57    });
58
59    $(document).on('click', '.wt_add_to_cart_all_btn', function(e){
60        
61        e.preventDefault();
62        const coupon_id=$(this).attr('coupon-id');
63        const free_product_container=$('.wt_give_away_products[coupon="'+coupon_id+'"]');
64        
65        const variation_id_arr=new Array();
66        const product_id_arr=new Array();
67        const attributes_arr=new Array();
68        let is_error=false;
69        free_product_container.find('.wt_get_away_product').each(function(){
70            
71            if($(this).attr('data-is_purchasable')==1)
72            {
73                const variation_id_obj=$(this).find('[name="variation_id"]');
74                if(variation_id_obj.length>0) /* variable product */
75                {
76                    if(variation_id_obj.val().trim()=="" || variation_id_obj.val().trim()=="0")
77                    {
78                        alert(WTSmartCouponOBJ.labels.choose_variation);
79                        is_error=true;
80                        return false;
81                    }else
82                    {
83                        variation_id_arr.push(variation_id_obj.val());
84                        attributes_arr.push(JSON.parse($(this).find('[name="wt_variation_options"]').val()));
85                    }
86                }else{
87                    variation_id_arr.push(0);
88                    attributes_arr.push([]);
89                }
90                const product_id=$(this).attr('product-id');
91                product_id_arr.push(product_id);
92            }
93
94        });
95
96        if(is_error===true)
97        {
98            return false;
99        }
100
101        const data = {
102            'action'            : 'wt_choose_free_product',
103            '_wpnonce'          : WTSmartCouponOBJ.nonces.public,
104            'product_id'        : 0,
105            'variation_id'      : 0,
106            'attributes'        : attributes_arr,
107            'coupon_id'         : coupon_id,
108            'product_id_arr'    : product_id_arr,
109            'variation_id_arr'  : variation_id_arr,
110            'add_to_cart_all'   : 1
111        };
112        wt_sc_ajax_add_giveaway($(this), data);
113
114    });
115
116    function wt_sc_ajax_add_giveaway(btn_elm, data)
117    {
118        const html_back=btn_elm.html();
119        btn_elm.html(WTSmartCouponOBJ.labels.please_wait);
120        
121        const all_btn_elms=$('.wt_add_to_cart_all_btn, .wt_choose_free_product');
122
123        all_btn_elms.prop('disabled', true);
124
125        if ( ! $('.woocommerce-notices-wrapper').length ) {
126            $('#main').prepend( '<div class="woocommerce-notices-wrapper"></div>' );
127        }
128
129        $('.woocommerce-notices-wrapper').html('');
130        
131        jQuery.ajax({
132            type:"POST",
133            async:true,
134            url:WTSmartCouponOBJ.ajaxurl,
135            data:data,
136            success:function(response)
137            {
138                if(response=='success')
139                {
140                    location.reload();
141                }else
142                {
143                    $('.woocommerce-notices-wrapper').html(response);
144                    $("html, body").stop(true, true).animate({scrollTop:($('.woocommerce-notices-wrapper').offset().top-70)}, 500);
145                    
146                    btn_elm.html(html_back);
147                    all_btn_elms.prop('disabled', false);
148                }
149            },
150            error:function()
151            {
152                btn_elm.html(html_back);
153                all_btn_elms.prop('disabled', false);
154            }
155        });
156    }
157
158    $(document).on('click','.wt_choose_free_product',function( e ) {
159        e.preventDefault();
160       
161        const parent_obj = $(this).closest('.wt_get_away_product');
162        if(parent_obj.attr('data-is_purchasable')==1)
163        {
164            let variation_id = 0;
165            const variation_id_obj = parent_obj.find('[name="variation_id"]');
166            if(variation_id_obj.length>0) /* variable product */
167            {
168                if(variation_id_obj.val().trim()=="" || variation_id_obj.val().trim()=="0")
169                {
170                    alert(WTSmartCouponOBJ.labels.choose_variation);
171                    return false;
172                }else
173                {
174                    variation_id=variation_id_obj.val();
175                }
176            }
177
178            const coupon_id = $(this).closest('.wt_give_away_products').attr('coupon');
179            if(typeof coupon_id=='undefined')
180            {
181                return false;
182            }
183
184            const product_id = $(this).attr('prod-id');
185            if(typeof product_id=='undefined')
186            {
187                return false;
188            }
189
190            const variation_attributes=( parent_obj.find( 'input[name="wt_variation_options"]' ).length>0 ? JSON.parse( parent_obj.find( 'input[name="wt_variation_options"]' ).val() ) : '' );
191            const data = {
192                'action'        : 'wt_choose_free_product',
193                '_wpnonce'      : WTSmartCouponOBJ.nonces.public,
194                'product_id'    : product_id,
195                'variation_id'  : variation_id,
196                'attributes'    : variation_attributes,
197                'coupon_id'     : coupon_id
198            };
199
200            wt_sc_ajax_add_giveaway($(this), data);
201        }
202        
203    });
204
205
206});

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.