1//Nascondi Inglese 2 3/* 4jQuery(document).ready(function($) { 5 $('.lang-item-es').hide(); 6}); 7*/ 8 9jQuery(document).ready(function () { 10 11 // Mouse enters .menu-header-title 12 jQuery('.menu-header-title').mouseenter(function () { 13 jQuery('.menu-header-sub-cont').hide(); // Hide all sub-containers 14 var targetSelector = jQuery(this).data('target'); 15 jQuery(targetSelector).show(); // Show the targeted container 16 }); 17 18 // Mouse leaves .menu-header-sub-cont 19 jQuery('.menu-header-sub-cont').mouseleave(function () { 20 jQuery(this).hide(); // Hide the current sub-container 21 }); 22}); 23 24//add to cart 25 26jQuery(document).ready(function ($) { 27 $(document).on('click', '.ajax-add-to-cart', function () { 28 var $thisButton = $(this); 29 30 var product_id = $thisButton.attr('data-product_id'); 31 var product_name = $thisButton.attr('product-name'); 32 var quantity = $('#quantity').val() || 1; 33 var variation_id = $thisButton.attr('data-variation_id') || 0; 34 var attributes = {}; 35 36 // Nuovi dati dal bottone 37 var product_price = $thisButton.attr('data-price'); 38 var product_image = $thisButton.attr('data-image'); 39 var product_description = $thisButton.attr('data-description'); 40 41 $thisButton.addClass('loading').html('<div class="loader-white"></div>'); 42 $thisButton.removeClass('add-to-cart'); 43 44 $.ajax({ 45 type: 'POST', 46 url: ajaxobject.ajaxurl, 47 data: { 48 'action': 'add_to_cart', 49 'product_id': product_id, 50 'quantity': quantity, 51 'variation_id': variation_id, 52 'attributes': attributes 53 }, 54 success: function (response) { 55 $thisButton.removeClass('loading').text('Aggiunto al Carrello'); 56 $thisButton.addClass('add-to-cart'); 57 58 // Leggi i dati dal bottone 59 const product_name = $thisButton.attr('product-name'); 60 const product_price = $thisButton.attr('data-price'); 61 const product_image = $thisButton.attr('data-image'); 62 const product_description = $thisButton.attr('data-description') || ' '; 63 const product_acf_quantity = $thisButton.attr('data-quantita') || '-'; 64 const product_acf_sottotitolo = $thisButton.attr('data-sottotitolo') || '-'; 65 const quantity = $('#quantity').val() || 1; 66 67 // Inserisci nel popup 68 $('#productAddedMessage').text(product_name); 69 $('#productSottotitolo').text(product_acf_sottotitolo); 70 $('#productDetails').text(product_description); 71 $('#productPrice').html('€' + product_price); 72 $('#productQuantity').text(quantity); 73 $('#productACFQuantity').text(product_acf_quantity); 74 $('#productImage').attr('src', product_image); 75 76 // Mostra modale 77 $('#productAddedModal').modal('show'); 78 79 updateCartContent(); 80 updateCartQuantity(); 81 82 // GTM Push 83 window.dataLayer = window.dataLayer || []; 84 window.dataLayer.push({ 85 'event': 'add_to_cart', 86 'productID': $thisButton.data('product_id'), 87 'productName': product_name, 88 'quantity': quantity 89 }); 90 }, 91 error: function (error) { 92 console.log('Error adding to cart', error); 93 } 94 }); 95 }); 96}); 97 98 99 100// remove item from cart 101 102jQuery(document).ready(function ($) { 103 $(document).on('click', '.ajax-remove-cart-item', function (e) { 104 e.preventDefault(); 105 106 var cartItemKey = $(this).data('cart_item_key'); 107 108 $.ajax({ 109 type: 'POST', 110 url: ajaxobject.ajaxurl, 111 data: { 112 action: 'remove_item_from_cart', 113 cart_item_key: cartItemKey 114 }, 115 success: function (response) { 116 if (response.success) { 117 // Fetch updated cart content 118 updateCartContent(); 119 updateCartQuantity(); 120 } else { 121 console.log('Failed to remove item'); 122 } 123 }, 124 error: function (error) { 125 console.log('Error removing item from cart', error); 126 } 127 }); 128 }); 129 130}); 131 132 133// refresh cart totals in header cart (#carrello-qty) 134 135function updateCartQuantity() { 136 jQuery.ajax({ 137 url: ajaxobject.ajaxurl, // Ensure this is defined in your script, similar to your existing AJAX calls 138 type: 'POST', 139 data: { 140 action: 'update_cart_qty' 141 }, 142 success: function (response) { 143 jQuery('#carrello-qty').text(response); 144 jQuery('.carrello-qty').text(response); 145 } 146 }); 147} 148 149 150 151 152function bindQuantityButtons() { 153 // Decrease quantity 154 jQuery('.wc-block-components-quantity-selector__button--minus-2').off('click').on('click', function (e) { 155 e.preventDefault(); 156 var input = jQuery(this).siblings('.wc-block-components-quantity-selector__input-2'); 157 var cartItemKey = input.closest('.cart-item').find('.ajax-remove-cart-item').data('cart_item_key'); 158 var value = parseInt(input.val(), 10); 159 if (value > 1) { 160 input.val(value - 1); 161 updateCartItem(cartItemKey, value - 1); 162 } 163 }); 164 165 // Increase quantity 166 jQuery('.wc-block-components-quantity-selector__button--plus-2').off('click').on('click', function (e) { 167 e.preventDefault(); 168 var input = jQuery(this).siblings('.wc-block-components-quantity-selector__input-2'); 169 var cartItemKey = input.closest('.cart-item').find('.ajax-remove-cart-item').data('cart_item_key'); 170 var value = parseInt(input.val(), 10); 171 var max = input.attr('max') ? parseInt(input.attr('max'), 10) : 9999; 172 if (value < max) { 173 input.val(value + 1); 174 updateCartItem(cartItemKey, value + 1); 175 } 176 }); 177} 178 179function updateCartItem(cartItemKey, quantity) { 180 jQuery.ajax({ 181 type: 'POST', 182 url: ajaxobject.ajaxurl, 183 data: { 184 action: 'update_cart_item_quantity', 185 cart_item_key: cartItemKey, 186 quantity: quantity 187 }, 188 success: function (response) { 189 if (response.success) { 190 jQuery('#offcanvasCart .offcanvas-body .offcanvas-body-dyn').html(response); 191 updateCartContent(); 192 updateCartQuantity(); 193 194 // Re-bind the quantity buttons as the cart content has been updated 195 bindQuantityButtons(); 196 } else { 197 console.log('Failed to update item quantity:', response.data); 198 } 199 }, 200 error: function (error) { 201 console.log('Error updating item quantity', error); 202 } 203 }); 204} 205 206function updateCartContent() { 207 208 var loaderHtml = '<div class="loader"></div>'; 209 jQuery('#offcanvasCart .offcanvas-body .offcanvas-body-dyn').html(loaderHtml); 210 211 jQuery.ajax({ 212 type: 'POST', 213 url: ajaxobject.ajaxurl, 214 data: { 215 action: 'get_updated_cart_content' 216 }, 217 success: function (response) { 218 if (response) { 219 jQuery('#offcanvasCart .offcanvas-body .offcanvas-body-dyn').html(response); 220 updateCartQuantity(); 221 bindQuantityButtons(); 222 } 223 }, 224 error: function () { 225 jQuery('#offcanvasCart .offcanvas-body .offcanvas-body-dyn').html('<p>Error loading cart content.</p>'); 226 }, 227 complete: function () { 228 jQuery('#offcanvasCart .offcanvas-body .offcanvas-body-dyn .loader').remove(); 229 } 230 }); 231} 232 233 234// paginazione AJAX 235 236jQuery(document).ready(function ($) { 237 $(document).on('click', '.pagination span a', function (e) { 238 e.preventDefault(); 239 var page = $(this).attr('href').split('paged=')[1]; 240 var cardPagContent = $(this).closest('.card-pag-content'); 241 var cat_id = $(this).closest('.card-pag-content').attr("id_cat"); 242 console.log(cat_id); 243 244 if (!page) { 245 var page = $(this).html(); 246 switch (page) { 247 case "1": 248 page = 1; 249 break; 250 case "2": 251 page = 2; 252 break; 253 case "3": 254 page = 3; 255 break; 256 case "4": 257 page = 4; 258 break; 259 default: 260 page = 2; 261 } 262 } 263 264 //console.log(cardPagContent); 265 266 $('.pagination span').hide(); 267 268 $(cardPagContent).addClass('loading').html('<div class="loader"></div>'); 269 270 fetch_posts(page, cardPagContent, cat_id); 271 }); 272 273 function fetch_posts(page, elementToUpdate, cat_id) { 274 $.ajax({ 275 url: ajaxobject.ajaxurl, 276 type: 'post', 277 data: { 278 action: 'ajax_pagination', 279 page: page, 280 cat_id: cat_id 281 }, 282 success: function (response) { 283 $('.pagination').removeClass('loading'); 284 $('.pagination span').show(); 285 elementToUpdate.html(response); 286 //console.log(response); 287 }, 288 error: function (error) { 289 $('.pagination').removeClass('loading'); 290 console.log("Error fetching posts: ", error); 291 } 292 }); 293 } 294}); 295 296 297// Ordinamento prodotti categoria prodotti 298 299jQuery(document).ready(function ($) { 300 $('#product-order').change(function () { 301 var orderBy = $(this).val(); 302 var cat_id = $("#product-order").attr("cat-id"); 303 var archive = $('#archive-products'); 304 305 var cardCount = $('#archive-products .card').length; 306 307 archive.addClass('loading').html('<div class="loader"></div>'); 308 309 $.ajax({ 310 url: ajaxobject.ajaxurl, 311 type: 'POST', 312 data: { 313 action: 'order_products', 314 order_by: orderBy, 315 term_id: cat_id, 316 card_count: cardCount 317 }, 318 success: function (response) { 319 archive.removeClass('loading'); 320 $('#archive-products').html(response); 321 } 322 }); 323 }); 324}); 325 326 327// Add to Wishlist 328 329jQuery(document).ready(function ($) { 330 331 $(document).on('click', '.wishlist-button', function () { 332 var $button = $(this); 333 var productId = $button.attr('product-id'); 334 $.ajax({ 335 type: 'POST', 336 url: ajaxobject.ajaxurl, 337 data: { 338 'action': 'handle_wishlist', 339 'product_id': productId, 340 'nonce': ajaxobject.nonce 341 }, 342 success: function (response) { 343 if (response.action === 'added') { 344 $button.removeClass("wishlist-button").addClass("wishlist-button-remove"); 345 $button.css("background-image", "url('https://www.benessence.it/wp-content/uploads/2025/05/heart-pieno.png')"); 346 } else if (response.action === 'exists') { 347 console.log("product already exist"); 348 } 349 }, 350 error: function () { 351 console.log('There was an error. Please try again.'); 352 } 353 }); 354 }); 355 356 $(document).on('click', '.wishlist', function () { 357 var $button = $(this); 358 var productId = $button.attr('product_id'); 359 $.ajax({ 360 type: 'POST', 361 url: ajaxobject.ajaxurl, 362 data: { 363 'action': 'handle_wishlist', 364 'product_id': productId, 365 'nonce': ajaxobject.nonce 366 }, 367 success: function (response) { 368 if (response.action === 'added') { 369 $button.removeClass("wishlist").addClass("wishlist-btn-rem"); 370 $button.css("background-image", "url('https://www.benessence.it/wp-content/uploads/2025/05/heart-pieno.png')"); 371 $button.html("rimuovi da Wishlist"); 372 } else if (response.action === 'exists') { 373 console.log("product already exist"); 374 } 375 }, 376 error: function () { 377 console.log('There was an error. Please try again.'); 378 } 379 }); 380 }); 381}); 382 383 384// Remove from Wishlist 385 386jQuery(document).ready(function ($) { 387 388 $(document).on('click', '.wishlist-button-remove', function () { 389 var $button = $(this); 390 var productId = $button.attr('product-id'); 391 var is_wish = $button.attr('wish'); 392 var wish_content = $("#wishlist-page"); 393 394 wish_content.addClass('loading').html('<div class="loader"></div>'); 395 396 $.ajax({ 397 type: 'POST', 398 url: ajaxobject.ajaxurl, 399 data: { 400 'action': 'handle_remove_from_wishlist', 401 'product_id': productId, 402 'is_wish': is_wish, 403 'nonce': ajaxobject.nonce 404 }, 405 success: function (response) { 406 wish_content.removeClass('loading'); 407 $button.removeClass("wishlist-button-remove").addClass("wishlist-button"); 408 $button.css("background-image", "url('https://www.benessence.it/wp-content/uploads/2025/05/heart-vuoto.png')"); 409 wish_content.html(response.html); 410 //alert(response.message); 411 }, 412 error: function () { 413 wish_content.removeClass('loading'); 414 wish_content.html(response.html); 415 console.log('There was an error. Please try again.'); 416 } 417 }); 418 }); 419 420 421 $(document).on('click', '.wishlist-btn-rem', function () { 422 var $button = $(this); 423 var productId = $button.attr('product_id'); 424 425 $.ajax({ 426 type: 'POST', 427 url: ajaxobject.ajaxurl, 428 data: { 429 'action': 'handle_remove_from_wishlist', 430 'product_id': productId, 431 'nonce': ajaxobject.nonce 432 }, 433 success: function (response) { 434 $button.removeClass("wishlist-btn-rem").addClass("wishlist"); 435 $button.css("background-image", "url('https://www.benessence.it/wp-content/uploads/2025/05/heart-vuoto.png')"); 436 $button.html("Aggiungi a Wishlist"); 437 //alert(response.message); 438 }, 439 error: function () { 440 console.log('There was an error. Please try again.'); 441 } 442 }); 443 }); 444}); 445 446 447 448jQuery(document).ready(function () { 449 // Show the button when the user scrolls down 100px from the top of the document 450 jQuery(window).scroll(function () { 451 if (jQuery(this).scrollTop() > 100) { 452 jQuery('#scrollTopButton').fadeIn(); 453 } else { 454 jQuery('#scrollTopButton').fadeOut(); 455 } 456 }); 457 458 // When the user clicks on the button, scroll to the top of the document 459 jQuery('#scrollTopButton').click(function () { 460 jQuery('html, body').animate({ scrollTop: 0 }, '300'); 461 return false;
462 }); 463}); 464 465 466jQuery(document).ready(function ($) { 467 $('#activecampaign-form').on('submit', function (e) { 468 e.preventDefault(); 469 $.ajax({ 470 url: ajaxobject.ajaxurl, 471 type: 'POST', 472 data: { 473 action: 'submit_to_activecampaign', 474 email: $('#email').val(), 475 acceptPrivacy: $('#acceptPrivacy').is(':checked') ? '1' : '0' 476 }, 477 success: function (response) { 478 // alert(response.data.message); 479 //$('#activecampaign-form').hide(); 480 $('#activecampaign-form-ok').text(response.data.message); 481 }, 482 error: function () { 483 alert('There was an error with your request.'); 484 } 485 }); 486 }); 487}); 488 489jQuery(document).ready(function ($) { 490 $('#activecampaign-form2').on('submit', function (e) { 491 e.preventDefault(); 492 $.ajax({ 493 url: ajaxobject.ajaxurl, 494 type: 'POST', 495 data: { 496 action: 'submit_to_activecampaign', 497 email: $('#email2').val(), 498 acceptPrivacy: $('#acceptPrivacy2').is(':checked') ? '1' : '0' 499 }, 500 success: function (response) { 501 // alert(response.data.message); 502 //$('#activecampaign-form').hide(); 503 $('#activecampaign-form-ok2').text(response.data.message); 504 }, 505 error: function () { 506 alert('There was an error with your request.'); 507 } 508 }); 509 }); 510}); 511 512/* 513 * DISABLED: Coupon form is now positioned directly in the template 514 * This old code was causing conflicts with the new checkout layout 515 * 516jQuery(document).ready(function($){ 517 // Move the coupon toggle and the form to a new location 518 $(document.body).on('updated_checkout', function(){ 519 // Check if the elements exist and the target location exists 520 if ($('.woocommerce-form-coupon-toggle').length && $('form.checkout_coupon').length && $('.woocommerce-checkout-payment').length) { 521 // Detach both the toggle and the form and insert them before the payment details 522 $('.woocommerce-form-coupon-toggle').detach().insertBefore('.woocommerce-checkout-payment'); 523 $('form.checkout_coupon').detach().insertBefore('.woocommerce-checkout-payment'); 524 } 525 }); 526}); 527*/ 528 529 530 531jQuery(document).ready(function ($) { 532 533 // Intercetta tutti i click su link "Visualizza carrello" anche se aggiunti dopo 534 $(document).on('click', 'a.added_to_cart.wc-forward', function (e) { 535 e.preventDefault(); 536 537 // Aggiorna il contenuto del carrello prima di aprirlo 538 updateCartContent(); 539 540 setTimeout(function () { 541 var offcanvasElement = document.getElementById('offcanvasCart'); 542 if (offcanvasElement) { 543 var bsOffcanvas = new bootstrap.Offcanvas(offcanvasElement); 544 bsOffcanvas.show(); 545 } 546 }, 300); 547 548 $(this).removeAttr('href'); 549 }); 550}); 551 552 553/* 554jQuery(document).ready(function() { 555 var lastScrollTop = 0; // This variable will hold the last scroll position 556 557 jQuery(window).scroll(function() { 558 var currentScroll = $(this).scrollTop(); // Get current scroll position 559 560 if (currentScroll > lastScrollTop) { 561 // If the current scroll position is greater than the last scroll position, the user is scrolling down 562 jQuery('.nav-mob').css('top', '-100px'); // Adjust '-100px' as needed to fully hide the element 563 } else { 564 // If the current scroll position is less than the last scroll position, the user is scrolling up 565 jQuery('.nav-mob').css('top', '0'); 566 } 567 568 // Update lastScrollTop to the current scroll position (but not below 0) 569 lastScrollTop = currentScroll > 0 ? currentScroll : 0; 570 }); 571 }); 572*/ 573
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.