1( function ( $ ) { 2 const CartFlowsHelper = { 3 getUrlParameter( param ) { 4 const page_url = decodeURIComponent( 5 window.location.search.substring( 1 ) 6 ), 7 url_variables = page_url.split( '&' ); 8 let parameter_name, i; 9 10 for ( i = 0; i < url_variables.length; i++ ) { 11 parameter_name = url_variables[ i ].split( '=' ); 12 13 if ( parameter_name[ 0 ] === param ) { 14 return parameter_name[ 1 ] === undefined 15 ? true 16 : parameter_name[ 1 ]; 17 } 18 } 19 }, 20 is_doing_offer_ajax: false, 21 }; 22 23 const trigger_offer_events = function ( ajax_data ) { 24 if ( ajax_data.offer_action ) { 25 // Prepare the offer data to sent to event. 26 const event_data = { 27 action: ajax_data.action, 28 flow_id: ajax_data.flow_id, 29 input_qty: ajax_data.input_qty, 30 offer_action: ajax_data.offer_action, 31 offer_type: ajax_data.offer_type, 32 order_id: ajax_data.order_id, 33 product_id: ajax_data.product_id, 34 step_id: ajax_data.step_id, 35 variation_id: ajax_data.variation_id, 36 }; 37 38 // Create a custom event and dispatch it. 39 document.dispatchEvent( 40 new CustomEvent( ajax_data.action, { 41 bubbles: true, // The bubbles will make sure that the code executes in the line-by-line pattern only. 42 detail: event_data, // eslint-disable-line quote-props 43 } ) 44 ); 45 } 46 }; 47 48 const wcf_process_offer = function ( ajax_data ) { 49 ajax_data._nonce = cartflows_offer[ ajax_data.action + '_nonce' ]; 50 51 // Stop sending multiple ajax requests at the same time to avoid duplicate orders. 52 if ( ! CartFlowsHelper.is_doing_offer_ajax ) { 53 CartFlowsHelper.is_doing_offer_ajax = true; 54 } else { 55 console.log( 56 'Muliple Clicks detected: Offer accepted ajax is already in progress.' 57 ); 58 return; 59 } 60 61 $.ajax( { 62 url: cartflows.ajax_url, 63 data: ajax_data, 64 dataType: 'json', 65 type: 'POST', 66 success( data ) { 67 const msg = data.message; 68 const msg_class = 'wcf-payment-' + data.status; 69 // Trigger the offer accept/reject events. 70 trigger_offer_events( ajax_data ); 71 $( 'body' ).trigger( 'wcf-update-msg', [ msg, msg_class ] ); 72 // Updating the state to ajax complete. 73 CartFlowsHelper.is_doing_offer_ajax = false; 74 setTimeout( function () { 75 window.location.href = data.redirect; 76 }, 600 ); 77 }, 78 } ); 79 }; 80 81 const wcf_offer_button_action = function () { 82 const default_page_builder = cartflows.default_page_builder; 83 $( 'a[href*="wcf-up-offer-yes"]' ).each( function ( e ) { 84 const $this = $( this ); 85 86 if ( e === 0 ) { 87 if ( default_page_builder === 'bricks-builder' ) { 88 $this.attr( 'class', 'wcf-upsell-offer' ); 89 } else { 90 $this.attr( 'id', 'wcf-upsell-offer' ); 91 } 92 } else if ( default_page_builder === 'bricks-builder' ) { 93 $this.attr( 'class', 'wcf-upsell-offer-' + e ); 94 } else { 95 $this.attr( 'id', 'wcf-upsell-offer-' + e ); 96 } 97 } ); 98 99 $( 'a[href*="wcf-down-offer-yes"]' ).each( function ( e ) { 100 const $this = $( this ); 101 102 if ( e === 0 ) { 103 if ( default_page_builder === 'bricks-builder' ) { 104 $this.attr( 'class', 'wcf-downsell-offer' ); 105 } else { 106 $this.attr( 'id', 'wcf-downsell-offer' ); 107 } 108 } else if ( default_page_builder === 'bricks-builder' ) { 109 $this.attr( 'class', 'wcf-downsell-offer' ); 110 } else { 111 $this.attr( 'id', 'wcf-downsell-offer-' + e ); 112 } 113 } ); 114 115 $( document ).on( 116 'click', 117 'a[href*="wcf-up-offer"], a[href*="wcf-down-offer"]', 118 function ( e ) { 119 e.preventDefault(); 120 121 //check if it is a bricks builder admin page 122 if ( true === cartflows.is_pb_preview ) { 123 e.stopPropagation(); 124 return; 125 } 126 127 const $this = $( this ), 128 href = $this.attr( 'href' ), 129 step_id = cartflows_offer.step_id, 130 product_id = cartflows_offer.product_id, 131 order_id = cartflows_offer.order_id, 132 order_key = cartflows_offer.order_key, 133 flow_id = cartflows.current_flow; 134 let offer_action = 'yes', 135 offer_type = 'upsell', 136 variation_id = 0, 137 input_qty = 0; 138 139 if ( href.indexOf( 'wcf-up-offer' ) !== -1 ) { 140 offer_type = 'upsell'; 141 142 if ( href.indexOf( 'wcf-up-offer-yes' ) !== -1 ) { 143 offer_action = 'yes'; 144 } else {
145 offer_action = 'no'; 146 } 147 } 148 149 if ( href.indexOf( 'wcf-down-offer' ) !== -1 ) { 150 offer_type = 'downsell'; 151 152 if ( href.indexOf( 'wcf-down-offer-yes' ) !== -1 ) { 153 offer_action = 'yes'; 154 } else { 155 offer_action = 'no'; 156 } 157 } 158 159 if ( 'yes' === offer_action ) { 160 const variation_wrapper = $( 161 '.wcf-offer-product-variation' 162 ); 163 164 if ( variation_wrapper.length > 0 ) { 165 const variation_form = variation_wrapper.find( 166 '.variations_form' 167 ), 168 variation_input = variation_form.find( 169 'input.variation_id' 170 ); 171 172 // Set variation id here. 173 variation_id = parseInt( variation_input.val() ); 174 175 if ( 176 $( '.var_not_selected' ).length > 0 || 177 '' === variation_id || 178 0 === variation_id 179 ) { 180 // variation_form.find('.variations select').addClass('var_not_selected'); 181 variation_form 182 .find( '.variations select' ) 183 .each( function () { 184 if ( $( this ).val().length === 0 ) { 185 $( this ).addClass( 186 'var_not_selected' 187 ); 188 } 189 } ); 190 191 $( [ 192 document.documentElement, 193 document.body, 194 ] ).animate( 195 { 196 scrollTop: 197 variation_form 198 .find( '.variations select' ) 199 .offset().top - 100, 200 }, 201 1000 202 ); 203 204 return false; 205 } 206 } 207 } 208 209 const is_disabled = $this.attr( 'disabled' ) ? true : false; 210 211 if ( ! is_disabled ) { 212 $this.attr( 'disabled', true ); 213 } else { 214 // Skip the workflow if clicked multiple times on the same buttons. 215 console.log( 216 'Restricted action: Multiple button clicks detected.' 217 ); 218 return false; 219 } 220 221 if ( 222 'yes' === cartflows_offer.skip_offer && 223 'yes' === offer_action 224 ) { 225 return; 226 } 227 228 $( 'body' ).trigger( 'wcf-show-loader', offer_action ); 229 230 if ( 'yes' === offer_action ) { 231 action = 'wcf_' + offer_type + '_accepted'; 232 } else { 233 action = 'wcf_' + offer_type + '_rejected'; 234 } 235 236 const quantity_wrapper = $( '.wcf-offer-product-quantity' ); 237 238 if ( quantity_wrapper.length > 0 ) { 239 const quantity_input = quantity_wrapper.find( 240 'input[name="quantity"]' 241 ); 242 const quantity_value = parseInt( quantity_input.val() ); 243 244 if ( quantity_value > 0 ) { 245 input_qty = quantity_value; 246 } 247 } 248 249 const ajax_data = { 250 action: '', 251 offer_action, 252 offer_type, 253 step_id, 254 product_id, 255 variation_id, 256 input_qty, 257 order_id, 258 order_key, 259 flow_id, 260 stripe_sca_payment: false, 261 stripe_intent_id: '', 262 _nonce: '', 263 }; 264 265 if ( 'yes' === offer_action ) { 266 if ( 'stripe' === cartflows_offer.payment_method ) { 267 ajax_data.action = 'wcf_stripe_sca_check'; 268 ajax_data._nonce = 269 cartflows_offer.wcf_stripe_sca_check_nonce; 270 $.ajax( { 271 url: cartflows.ajax_url, 272 data: ajax_data, 273 dataType: 'json', 274 type: 'POST', 275 success( response ) { 276 if ( 277 response.hasOwnProperty( 'intent_secret' ) 278 ) { 279 const stripe = Stripe( response.stripe_pk ); 280 stripe 281 .handleCardPayment( 282 response.intent_secret 283 ) 284 .then( function ( res ) { 285 if ( res.error ) { 286 throw res.error; 287 } 288 289 if ( 290 'requires_capture' !== 291 res.paymentIntent.status && 292 'succeeded' !== 293 res.paymentIntent.status 294 ) { 295 return; 296 } 297 298 ajax_data.action = action; 299 ajax_data.stripe_sca_payment = true; 300 ajax_data.stripe_intent_id = 301 res.paymentIntent.id; 302 wcf_process_offer( ajax_data ); 303 } ) 304 .catch( function () { 305 window.location.reload(); 306 } ); 307 } else { 308 ajax_data.action = action; 309 wcf_process_offer( ajax_data ); 310 } 311 }, 312 } ); 313 } else if ( 314 'mollie_wc_gateway_creditcard' === 315 cartflows_offer.payment_method || 316 'mollie_wc_gateway_ideal' === 317 cartflows_offer.payment_method 318 ) { 319 wcf_handle_mollie_payment_gateways( 320 ajax_data, 321 cartflows_offer.payment_method 322 ); 323 } else if ( 324 'ppcp-gateway' === cartflows_offer.payment_method 325 ) { 326 wcf_init_create_paypal_payments_order( 327 ajax_data, 328 cartflows_offer.payment_method 329 ); 330 } else if ( 331 'cpsw_stripe' === cartflows_offer.payment_method || 332 'cpsw_stripe_element' === cartflows_offer.payment_method 333 ) { 334 if ( 335 'cpsw_stripe' === cartflows_offer.payment_method 336 ) { 337 ajax_data.action = 'wcf_cpsw_create_payment_intent'; 338 ajax_data._nonce = 339 cartflows_offer.wcf_cpsw_create_payment_intent_nonce; 340 } else { 341 ajax_data.action = 342 'wcf_cpsw_create_payment_element_intent'; 343 ajax_data._nonce = 344 cartflows_offer.wcf_cpsw_create_payment_element_intent_nonce; 345 } 346 $.ajax( { 347 url: cartflows.ajax_url, 348 data: ajax_data, 349 dataType: 'json', 350 type: 'POST', 351 success( response ) { 352 if ( 353 response.hasOwnProperty( 354 'client_secret' 355 ) && 356 '' !== response.client_secret 357 ) { 358 const stripe = Stripe( response.cpsw_pk ); 359 stripe 360 .confirmCardPayment( 361 response.client_secret 362 ) 363 .then( function ( resp ) { 364 console.log( resp ); 365 if ( resp.error ) { 366 throw resp.error; 367 } 368 if ( 369 'requires_capture' !== 370 resp.paymentIntent.status && 371 'succeeded' !== 372 resp.paymentIntent.status 373 ) { 374 return; 375 } 376 377 ajax_data.action = action; 378 ajax_data.cpsw_intent_id =
379 resp.paymentIntent.id; 380 ajax_data.cpsw_payment_method = 381 resp.paymentIntent.payment_method; 382 wcf_process_offer( ajax_data ); 383 } ) 384 .catch( function () { 385 window.location.reload(); 386 } ); 387 } else { 388 ajax_data.action = action; 389 wcf_process_offer( ajax_data ); 390 } 391 }, 392 } ); 393 } else if ( 394 'woocommerce_payments' === 395 cartflows_offer.payment_method 396 ) { 397 ajax_data.action = 'wcf_woop_create_payment_intent'; 398 ajax_data.wcf_wc_payment_nonce = 399 cartflows_offer.wcf_woop_create_payment_intent_nonce; 400 $.ajax( { 401 url: cartflows.ajax_url, 402 data: ajax_data, 403 dataType: 'json', 404 type: 'POST', 405 success( response ) { 406 if ( 407 response.hasOwnProperty( 408 'client_secret' 409 ) && 410 '' !== response.client_secret && 411 'succeeded' !== response.status 412 ) { 413 const stripe = Stripe( 414 response.client_public 415 ); 416 417 stripe 418 .confirmCardPayment( 419 response.client_secret 420 ) 421 .then( function ( resp ) { 422 console.log( resp ); 423 if ( resp.error ) { 424 throw resp.error; 425 } 426 427 if ( 428 'requires_capture' !== 429 resp.paymentIntent.status && 430 'succeeded' !== 431 resp.paymentIntent.status 432 ) { 433 console.log( 434 'Order not complete. Received status: ' + 435 resp.paymentIntent 436 .status 437 ); 438 return; 439 } 440 441 ajax_data.action = action; 442 ajax_data.woop_intent_id = 443 resp.paymentIntent.id; 444 ajax_data.woop_payment_method = 445 resp.paymentIntent.payment_method; 446 wcf_process_offer( ajax_data ); 447 } ) 448 .catch( function () { 449 window.location.reload(); 450 } ); 451 } else { 452 ajax_data.action = action; 453 ajax_data.woop_intent_id = 454 response.client_intend; 455 wcf_process_offer( ajax_data ); 456 } 457 }, 458 } ); 459 } else if ( 460 'cppw_paypal' === cartflows_offer.payment_method 461 ) { 462 ajax_data.action = 'wcf_cppw_create_paypal_order'; 463 ajax_data._nonce = 464 cartflows_offer.wcf_cppw_create_paypal_order_nonce; 465 $.ajax( { 466 url: cartflows.ajax_url, 467 data: ajax_data, 468 dataType: 'json', 469 type: 'POST', 470 success( response ) { 471 if ( 'succeeded' === response.status ) { 472 ajax_data.action = action; 473 ajax_data.transaction_id = 474 response.transaction_id; 475 wcf_process_offer( ajax_data ); 476 } else { 477 ajax_data.action = action; 478 wcf_process_offer( ajax_data ); 479 } 480 }, 481 } ); 482 } else { 483 ajax_data.action = action; 484 wcf_process_offer( ajax_data ); 485 } 486 } else { 487 ajax_data.action = action; 488 wcf_process_offer( ajax_data ); 489 } 490 491 return false; 492 } 493 ); 494 }; 495 496 const wcf_handle_mollie_payment_gateways = function ( ajax_data, gateway ) { 497 if ( 'mollie_wc_gateway_creditcard' === gateway ) { 498 ajax_data.action = 'wcf_mollie_creditcard_process'; 499 ajax_data._nonce = 500 cartflows_offer.wcf_mollie_creditcard_process_nonce; 501 } 502 if ( 'mollie_wc_gateway_ideal' === gateway ) { 503 ajax_data.action = 'wcf_mollie_ideal_process'; 504 ajax_data._nonce = cartflows_offer.wcf_mollie_ideal_process_nonce; 505 } 506 $.ajax( { 507 url: cartflows.ajax_url, 508 data: ajax_data, 509 dataType: 'json', 510 type: 'POST', 511 success( response ) { 512 console.log( response ); 513 if ( 'success' === response.result ) { 514 window.location.href = response.redirect; 515 } else { 516 ajax_data.action = action; 517 wcf_process_offer( ajax_data ); 518 } 519 }, 520 } ); 521 }; 522 523 /* 524 * Function to Create the PayPal Payments order as the offer is accepted. 525 */ 526 const wcf_init_create_paypal_payments_order = function ( ajax_data ) { 527 ajax_data.action = 'wcf_create_paypal_payments_order'; 528 ajax_data._nonce = cartflows_offer.wcf_create_paypal_order_nonce; 529 530 $.ajax( { 531 url: cartflows.ajax_url, 532 data: ajax_data, 533 dataType: 'json', 534 type: 'POST', 535 success( response ) { 536 console.log( response ); 537 if ( 'success' === response.status ) { 538 // Redirect to PayPal's page for approving the order by making the payment. 539 window.location.href = response.redirect; 540 } else { 541 ajax_data.action = 542 'wcf_' + ajax_data.offer_type + '_accepted'; 543 wcf_process_offer( ajax_data ); 544 } 545 }, 546 } ); 547 }; 548 549 /* 550 * Function to capture the PayPal Payments order once it is created. 551 */ 552 const wcf_capture_paypal_payments_order = function () { 553 // Capture the call after approving the created order. 554 555 if ( 'undefined' !== typeof cartflows_offer ) { 556 const is_ppcp_return = CartFlowsHelper.getUrlParameter( 557 'wcf-ppcp-return' 558 ); 559 560 let ppcp_nonce = ''; 561 562 if ( is_ppcp_return ) { 563 ppcp_nonce = cartflows_offer.wcf_capture_paypal_order_nonce; 564 565 const ajax_data = { 566 action: 'wcf_capture_paypal_order', 567 step_id: cartflows_offer.step_id, 568 order_id: cartflows_offer.order_id, 569 _nonce: ppcp_nonce, 570 }; 571 572 $( 'body' ).trigger( 'wcf-show-loader', 'yes' ); 573 574 $.ajax( { 575 url: cartflows.ajax_url, 576 data: ajax_data, 577 dataType: 'json', 578 type: 'POST', 579 success( response ) { 580 console.log( response ); 581 582 if ( 'success' === response.status ) { 583 const offer_type = cartflows_offer.offer_type; 584 585 const data = { 586 action: 'wcf_' + offer_type + '_accepted', 587 offer_action: 'yes', 588 offer_type, 589 step_id: cartflows_offer.step_id, 590 product_id: cartflows_offer.product_id, 591 order_id: cartflows_offer.order_id, 592 order_key: cartflows_offer.order_key, 593 flow_id: cartflows.current_flow, 594 stripe_sca_payment: false, 595 stripe_intent_id: '', 596 _nonce: ppcp_nonce, 597 }; 598 599 wcf_process_offer( data ); 600 } else { 601 data.action = data.action = 602 'wcf_' + data.offer_type + '_accepted'; 603 wcf_process_offer( data ); 604 } 605 }, 606 } ); 607 } 608 } 609 }; 610 611 const wcf_offer_quantity_shortcode = function () { 612 /* Offer Quantity Shortcode */ 613 const offer_quantity = $( '.wcf-offer-product-quantity' ); 614 615 if ( offer_quantity.length > 0 ) { 616 /* Sync all variation and quanity */ 617 $( '.wcf-offer-product-quantity .qty' ).on( 'change', function () {
618 const qty = $( this ).val(); 619 620 $( '.wcf-offer-product-quantity .qty' ).val( qty ); 621 } ); 622 } 623 }; 624 625 const wcf_offer_variation_shortcode = function () { 626 /* Offer Variation Shortcode */ 627 const offer_variation = $( 628 '.wcf-offer-product-variation .variations select' 629 ); 630 631 if ( offer_variation.length > 0 ) { 632 $( '.wcf-variable-price-range' ).show().siblings().remove(); 633 634 // $('.wcf-offer-product-variation input.variation_id').change(function(){ 635 $( '.wcf-offer-product-variation .variations select' ).on( 636 'change', 637 function () { 638 const $this = $( this ); 639 const attr_val = $this.data( 'attribute_name' ); 640 641 if ( 0 !== $this.length ) { 642 const selected_option = $this.val(); 643 644 $( 645 '.wcf-offer-product-variation [data-attribute_name ="' + 646 attr_val + 647 '"]' 648 ).each( function () { 649 $( this ).val( selected_option ); 650 if ( 651 '' === selected_option || 652 0 === selected_option 653 ) { 654 $( this ).addClass( 'var_not_selected' ); 655 } else { 656 $( this ).removeClass( 'var_not_selected' ); 657 } 658 } ); 659 } 660 } 661 ); 662 663 $( '.variations_form' ).on( 664 'found_variation', 665 function ( event, variation ) { 666 const discount_type = cartflows_offer.discount_type, 667 discount_value = cartflows_offer.discount_value, 668 currency_symbol = cartflows_offer.currency_symbol, 669 regular_price = variation.display_price; 670 let custom_price = variation.display_price; 671 672 if ( discount_value > 0 ) { 673 if ( 'discount_percent' === discount_type ) { 674 custom_price = 675 custom_price - 676 ( custom_price * discount_value ) / 100; 677 } else if ( 'discount_price' === discount_type ) { 678 custom_price = custom_price - discount_value; 679 } 680 } 681 682 let price_html = 683 '<span class="wcf-single-variation-price">'; 684 685 if ( regular_price !== custom_price ) { 686 price_html += '<span class="wcf-regular-price del">'; 687 price_html += 688 currency_symbol + regular_price.toFixed( 2 ); 689 price_html += '</span>'; 690 price_html += '<span class="wcf-discount-price">'; 691 price_html += 692 currency_symbol + custom_price.toFixed( 2 ); 693 price_html += '</span>'; 694 } else { 695 price_html += '<span class="wcf-regular-price">'; 696 price_html += 697 currency_symbol + regular_price.toFixed( 2 ); 698 price_html += '</span>'; 699 } 700 701 price_html += '</span>'; 702 703 $( '.wcf-offer-price' ).html( price_html ); 704 } 705 ); 706 } else { 707 $( '.wcf-variable-price-range' ).remove(); 708 $( '.wcf-offer-price-inner' ).show(); 709 } 710 }; 711 712 const wcf_offer_image_shortcode = function () { 713 /* Offer product gallery */ 714 const product_gallery = jQuery( '.woocommerce-product-gallery' ); 715 716 if ( product_gallery.length > 0 ) { 717 if ( 718 product_gallery.find( '.woocommerce-product-gallery__image' ) 719 .length >= 1 720 ) { 721 const slider_obj = jQuery( 722 '.woocommerce-product-gallery' 723 ).flexslider( { 724 animation: 'slide', 725 animationLoop: false, 726 controlNav: 'thumbnails', 727 selector: '.slides .woocommerce-product-gallery__image', 728 directionNav: false, 729 } ); 730 731 $( window ).on( 'load', function () { 732 slider_obj.trigger( 'resize' ); 733 } ); 734 735 /* Variation change gallery */ 736 const variations_form = $( '.variations_form' ); 737 738 if ( variations_form.length > 0 ) { 739 /** 740 * Reset the slide position if the variation has a different image than the current one 741 * 742 * @param {Object} variation variation data. 743 */ 744 const maybe_trigger_slide_position_reset = function ( 745 variation 746 ) { 747 const $form = variations_form, 748 $product_gallery = $( 749 '.woocommerce-product-gallery' 750 ), 751 new_image_id = 752 variation && variation.image_id 753 ? variation.image_id 754 : ''; 755 let reset_slide_position = false; 756 757 if ( $form.attr( 'current-image' ) !== new_image_id ) { 758 reset_slide_position = true; 759 } 760 761 $form.attr( 'current-image', new_image_id ); 762 763 if ( reset_slide_position ) { 764 $product_gallery.flexslider( 0 ); 765 } 766 }; 767 768 /** 769 * Sets product images for the chosen variation 770 * 771 * @param {Object} variation variation data. 772 */ 773 const variations_image_update = function ( variation ) { 774 const $form = variations_form, 775 $product_gallery = $( 776 '.woocommerce-product-gallery' 777 ), 778 $gallery_nav = $product_gallery.find( 779 '.flex-control-nav' 780 ); 781 782 if ( 783 variation && 784 variation.image && 785 variation.image.src && 786 variation.image.src.length > 1 787 ) { 788 // See if the gallery has an image with the same original src as the image we want to switch to. 789 const galleryHasImage = 790 $gallery_nav.find( 791 'li img[data-o_src="' + 792 variation.image.gallery_thumbnail_src + 793 '"]' 794 ).length > 0; 795 796 // If the gallery has the image, reset the images. We'll scroll to the correct one. 797 if ( galleryHasImage ) { 798 variations_image_reset(); 799 } 800 801 // See if gallery has a matching image we can slide to.
802 const slideToImage = $gallery_nav.find( 803 'li img[src="' + 804 variation.image.gallery_thumbnail_src + 805 '"]' 806 ); 807 808 if ( slideToImage.length > 0 ) { 809 slideToImage.trigger( 'click' ); 810 $form.attr( 811 'current-image', 812 variation.image_id 813 ); 814 window.setTimeout( function () { 815 $( window ).trigger( 'resize' ); 816 $product_gallery.trigger( 817 'woocommerce_gallery_init_zoom' 818 ); 819 }, 20 ); 820 return; 821 } 822 823 const $product_img_wrap = $product_gallery 824 .find( 825 '.woocommerce-product-gallery__image, .woocommerce-product-gallery__image--placeholder' 826 ) 827 .eq( 0 ), 828 $product_img = $product_img_wrap.find( 829 '.wp-post-image' 830 ), 831 $product_link = $product_img_wrap 832 .find( 'a' ) 833 .eq( 0 ); 834 835 $product_img.wc_set_variation_attr( 836 'src', 837 variation.image.src 838 ); 839 $product_img.wc_set_variation_attr( 840 'height', 841 variation.image.src_h 842 ); 843 $product_img.wc_set_variation_attr( 844 'width', 845 variation.image.src_w 846 ); 847 $product_img.wc_set_variation_attr( 848 'srcset', 849 variation.image.srcset 850 ); 851 $product_img.wc_set_variation_attr( 852 'sizes', 853 variation.image.sizes 854 ); 855 $product_img.wc_set_variation_attr( 856 'title', 857 variation.image.title 858 ); 859 $product_img.wc_set_variation_attr( 860 'data-caption', 861 variation.image.caption 862 ); 863 $product_img.wc_set_variation_attr( 864 'alt', 865 variation.image.alt 866 ); 867 $product_img.wc_set_variation_attr( 868 'data-src', 869 variation.image.full_src 870 ); 871 $product_img.wc_set_variation_attr( 872 'data-large_image', 873 variation.image.full_src 874 ); 875 $product_img.wc_set_variation_attr( 876 'data-large_image_width', 877 variation.image.full_src_w 878 ); 879 $product_img.wc_set_variation_attr( 880 'data-large_image_height', 881 variation.image.full_src_h 882 ); 883 $product_img_wrap.wc_set_variation_attr( 884 'data-thumb', 885 variation.image.src 886 ); 887 const $gallery_img = $gallery_nav.find( 888 'li:eq(0) img' 889 ); 890 $gallery_img.wc_set_variation_attr( 891 'src', 892 variation.image.gallery_thumbnail_src 893 ); 894 $product_link.wc_set_variation_attr( 895 'href', 896 variation.image.full_src 897 ); 898 } else { 899 variations_image_reset(); 900 } 901 902 window.setTimeout( function () { 903 $( window ).trigger( 'resize' ); 904 maybe_trigger_slide_position_reset( variation ); 905 }, 20 ); 906 }; 907 908 /** 909 * Reset main image to defaults. 910 */ 911 const variations_image_reset = function () { 912 const $product_gallery = $( 913 '.woocommerce-product-gallery' 914 ), 915 $gallery_nav = $product_gallery.find( 916 '.flex-control-nav' 917 ), 918 $gallery_img = $gallery_nav.find( 'li:eq(0) img' ), 919 $product_img_wrap = $product_gallery 920 .find( 921 '.woocommerce-product-gallery__image, .woocommerce-product-gallery__image--placeholder' 922 ) 923 .eq( 0 ), 924 $product_img = $product_img_wrap.find( 925 '.wp-post-image' 926 ), 927 $product_link = $product_img_wrap 928 .find( 'a' ) 929 .eq( 0 ); 930 931 $product_img.wc_reset_variation_attr( 'src' ); 932 $product_img.wc_reset_variation_attr( 'width' ); 933 $product_img.wc_reset_variation_attr( 'height' ); 934 $product_img.wc_reset_variation_attr( 'srcset' ); 935 $product_img.wc_reset_variation_attr( 'sizes' ); 936 $product_img.wc_reset_variation_attr( 'title' ); 937 $product_img.wc_reset_variation_attr( 'data-caption' ); 938 $product_img.wc_reset_variation_attr( 'alt' ); 939 $product_img.wc_reset_variation_attr( 'data-src' ); 940 $product_img.wc_reset_variation_attr( 941 'data-large_image' 942 ); 943 $product_img.wc_reset_variation_attr( 944 'data-large_image_width' 945 ); 946 $product_img.wc_reset_variation_attr( 947 'data-large_image_height' 948 ); 949 $product_img_wrap.wc_reset_variation_attr( 950 'data-thumb' 951 ); 952 $gallery_img.wc_reset_variation_attr( 'src' ); 953 $product_link.wc_reset_variation_attr( 'href' ); 954 }; 955 956 $( '.variations_form' ).on( 957 'found_variation', 958 function ( event, variation ) { 959 variations_image_update( variation ); 960 } 961 ); 962 } 963 } 964 } 965 }; 966 967 // ******************** For Image Slider ******************** 968 $( window ).on( 'elementor/frontend/init', function () { 969 elementorFrontend.hooks.addAction( 970 'frontend/element_ready/offer-product-image.default', 971 wcf_offer_image_shortcode 972 ); 973 } ); 974 975 const wcf_offer_shortcode_events = function () { 976 wcf_offer_quantity_shortcode(); 977 978 wcf_offer_variation_shortcode(); 979 980 wcf_offer_image_shortcode(); 981 }; 982 983 const wcf_facebook_pixel = function () { 984 jQuery( document ).ajaxComplete( function ( event, xhr ) { 985 if ( ! xhr.hasOwnProperty( 'responseJSON' ) ) { 986 return; 987 } 988 const fragmants = xhr.responseJSON.hasOwnProperty( 'fragments' ) 989 ? xhr.responseJSON.fragments 990 : null; 991 if ( 992 fragmants && 993 fragmants.hasOwnProperty( 'added_to_cart_data' ) 994 ) { 995 fbq( 996 'track', 997 'AddToCart', 998 fragmants.added_to_cart_data.added_to_cart 999 ); 1000 } 1001 1002 const cartflows_fb_data = cartflows.fb_setting; 1003 1004 if ( 1005 'enable' === 1006 cartflows_fb_data.facebook_pixel_add_payment_info && 1007 fragmants && 1008 fragmants.hasOwnProperty( 'fb_add_payment_info_data' ) 1009 ) { 1010 // Update cart data for add payment info event 1011 cartflows.fb_add_payment_info_data = 1012 fragmants.fb_add_payment_info_data; 1013 } 1014 } ); 1015 }; 1016 1017 const wcf_tiktok_pixel = function () { 1018 jQuery( document ).ajaxComplete( function ( event, xhr ) { 1019 if ( ! xhr.hasOwnProperty( 'responseJSON' ) ) { 1020 return; 1021 } 1022 1023 /* global ttq */ 1024 1025 const fragmants = xhr.responseJSON.hasOwnProperty( 'fragments' ) 1026 ? xhr.responseJSON.fragments 1027 : null; 1028 1029 if ( 1030 fragmants &&
1031 fragmants.hasOwnProperty( 'tiktok_added_to_cart_data' ) 1032 ) { 1033 ttq.track( 1034 'AddToCart', 1035 fragmants.tiktok_added_to_cart_data?.added_to_cart 1036 ); 1037 } 1038 1039 const cartflows_tiktok_data = cartflows.tik_setting; 1040 1041 if ( 1042 'enable' === 1043 cartflows_tiktok_data?.enable_tiktok_add_payment_info && 1044 fragmants && 1045 fragmants.hasOwnProperty( 'tiktok_add_payment_info_data' ) 1046 ) { 1047 // Update cart data for add payment info event 1048 cartflows.tiktok_add_payment_info_data = 1049 fragmants.tiktok_add_payment_info_data; 1050 } 1051 } ); 1052 }; 1053 1054 const wcf_pinterest_pixel = function () { 1055 jQuery( document ).ajaxComplete( function ( event, xhr ) { 1056 if ( ! xhr.hasOwnProperty( 'responseJSON' ) ) { 1057 return; 1058 } 1059 1060 /* global pintrk */ 1061 1062 const fragmants = xhr.responseJSON.hasOwnProperty( 'fragments' ) 1063 ? xhr.responseJSON.fragments 1064 : null; 1065 1066 if ( 1067 typeof pintrk !== 'undefined' && 1068 fragmants && 1069 fragmants.hasOwnProperty( 'pinterest_added_to_cart_data' ) 1070 ) { 1071 pintrk( 1072 'track', 1073 'AddToCart', 1074 fragmants.pinterest_added_to_cart_data?.added_to_cart 1075 ); 1076 } 1077 1078 const cartflows_pinterest_data = cartflows.pinterest_setting; 1079 1080 if ( 1081 'enable' === 1082 cartflows_pinterest_data?.enable_pinterest_add_payment_info && 1083 fragmants && 1084 fragmants.hasOwnProperty( 'pinterest_add_payment_info_data' ) 1085 ) { 1086 // Update cart data for add payment info event 1087 cartflows.pinterest_add_payment_info_data = 1088 fragmants.pinterest_add_payment_info_data; 1089 } 1090 } ); 1091 }; 1092 1093 const wcf_snapchat_pixel = function () { 1094 jQuery( document ).ajaxComplete( function ( event, xhr ) { 1095 if ( ! xhr.hasOwnProperty( 'responseJSON' ) ) { 1096 return; 1097 } 1098 1099 /* global snaptr */ 1100 1101 const fragmants = xhr.responseJSON.hasOwnProperty( 'fragments' ) 1102 ? xhr.responseJSON.fragments 1103 : null; 1104 1105 if ( 1106 fragmants && 1107 fragmants.hasOwnProperty( 'snapchat_added_to_cart_data' ) 1108 ) { 1109 snaptr( 1110 'track', 1111 'ADD_CART', 1112 fragmants.snapchat_added_to_cart_data?.added_to_cart 1113 ); 1114 } 1115 } ); 1116 }; 1117 1118 const wcf_google_analytics = function () { 1119 jQuery( document ).ajaxComplete( function ( event, xhr, settings ) { 1120 if ( ! xhr.hasOwnProperty( 'responseJSON' ) ) { 1121 return; 1122 } 1123 1124 const cartflows_ga_data = cartflows.ga_setting; 1125 const ga_add_to_cart = cartflows_ga_data.enable_add_to_cart; 1126 1127 const ga_payment_info = cartflows_ga_data.enable_add_payment_info; 1128 1129 const is_checkout_page = cartflows.is_checkout_page; 1130 if ( is_checkout_page ) { 1131 // track only if the bump order is accepted. 1132 const fragmants = xhr.responseJSON.hasOwnProperty( 'fragments' ) 1133 ? xhr.responseJSON.fragments 1134 : null; 1135 1136 if ( settings.hasOwnProperty( 'data' ) ) { 1137 if ( 1138 settings.data.indexOf( 1139 'action=wcf_bump_order_process' 1140 ) !== -1 1141 ) { 1142 if ( 'enable' === ga_add_to_cart ) { 1143 if ( 1144 fragmants && 1145 fragmants.hasOwnProperty( 1146 'ga_added_to_cart_data' 1147 ) 1148 ) { 1149 gtag( 1150 'event', 1151 'add_to_cart', 1152 JSON.parse( 1153 fragmants.ga_added_to_cart_data 1154 .add_to_cart 1155 ) 1156 ); 1157 } 1158 1159 if ( 1160 fragmants && 1161 fragmants.hasOwnProperty( 1162 'ga_remove_to_cart_data' 1163 ) 1164 ) { 1165 gtag( 1166 'event', 1167 'remove_from_cart', 1168 JSON.parse( 1169 fragmants.ga_remove_to_cart_data 1170 .remove_from_cart 1171 ) 1172 ); 1173 } 1174 } 1175 1176 if ( 'enable' === ga_payment_info ) { 1177 if ( 1178 fragmants && 1179 fragmants.hasOwnProperty( 1180 'ga_add_payment_info_data' 1181 ) 1182 ) { 1183 // Update cart data for add payment info event 1184 cartflows.add_payment_info_data = 1185 fragmants.ga_add_payment_info_data; 1186 } 1187 } 1188 } 1189 } 1190 } 1191 } ); 1192 }; 1193 1194 const wcf_google_ads_pixel = function () { 1195 jQuery( document ).ajaxComplete( function ( event, xhr, settings ) { 1196 if ( ! xhr.hasOwnProperty( 'responseJSON' ) ) { 1197 return; 1198 } 1199 1200 const cartflows_gads_data = cartflows?.gads_setting; 1201 const gads_add_to_cart =
1202 cartflows_gads_data?.enable_google_ads_add_to_cart; 1203 1204 const gads_payment_info = 1205 cartflows_gads_data?.enable_google_ads_add_payment_info; 1206 1207 const is_checkout_page = cartflows?.is_checkout_page; 1208 if ( is_checkout_page ) { 1209 // track only if the bump order is accepted. 1210 const fragmants = xhr.responseJSON.hasOwnProperty( 'fragments' ) 1211 ? xhr.responseJSON.fragments 1212 : null; 1213 1214 if ( settings.hasOwnProperty( 'data' ) ) { 1215 if ( 1216 settings.data.indexOf( 1217 'action=wcf_bump_order_process' 1218 ) !== -1 1219 ) { 1220 if ( 'enable' === gads_add_to_cart ) { 1221 if ( 1222 fragmants && 1223 fragmants.hasOwnProperty( 1224 'gads_added_to_cart_data' 1225 ) 1226 ) { 1227 gtag( 1228 'event', 1229 'add_to_cart', 1230 JSON.parse( 1231 fragmants.gads_added_to_cart_data 1232 .add_to_cart 1233 ) 1234 ); 1235 } 1236 1237 if ( 1238 fragmants && 1239 fragmants.hasOwnProperty( 1240 'gads_remove_to_cart_data' 1241 ) 1242 ) { 1243 gtag( 1244 'event', 1245 'remove_from_cart', 1246 JSON.parse( 1247 fragmants.gads_remove_to_cart_data 1248 .remove_from_cart 1249 ) 1250 ); 1251 } 1252 } 1253 1254 if ( 'enable' === gads_payment_info ) { 1255 if ( 1256 fragmants && 1257 fragmants.hasOwnProperty( 1258 'gads_add_payment_info_data' 1259 ) 1260 ) { 1261 // Update cart data for add payment info event 1262 cartflows.add_payment_info_data = 1263 fragmants.gads_add_payment_info_data; 1264 } 1265 } 1266 } 1267 } 1268 } 1269 } ); 1270 }; 1271 1272 $( function () { 1273 $( 'body' ).on( 'wcf-show-loader', function ( event, action ) { 1274 if ( 'no' === action ) { 1275 jQuery( '.wcf-note-yes' ).hide(); 1276 jQuery( '.wcf-note-no' ).show(); 1277 jQuery( '.wcf-process-msg' ).hide(); 1278 } 1279 1280 $( '.wcf-loader-bg' ).addClass( 'show' ); 1281 } ); 1282 1283 $( 'body' ).on( 'wcf-hide-loader', function () { 1284 console.log( 'Hide Loader' ); 1285 $( '.wcf-loader-bg' ).removeClass( 'show' ); 1286 } ); 1287 $( 'body' ).on( 'wcf-update-msg', function ( event, msg, msg_class ) { 1288 $( '.wcf-order-msg .wcf-process-msg' ) 1289 .text( msg ) 1290 .addClass( msg_class ) 1291 .show(); 1292 } ); 1293 1294 wcf_offer_button_action(); 1295 wcf_offer_shortcode_events(); 1296 1297 if ( '1' !== cartflows.is_pb_preview ) { 1298 wcf_facebook_pixel(); 1299 wcf_tiktok_pixel(); 1300 wcf_google_analytics(); 1301 wcf_pinterest_pixel(); 1302 wcf_google_ads_pixel(); 1303 wcf_snapchat_pixel(); 1304 } 1305 1306 if ( 'undefined' !== typeof cartflows_offer ) { 1307 const is_mollie_return = CartFlowsHelper.getUrlParameter( 1308 'wcf-mollie-return' 1309 ); 1310 let mollie_nonce = ''; 1311 1312 if ( is_mollie_return ) { 1313 if ( 1314 'mollie_wc_gateway_creditcard' === 1315 cartflows_offer.payment_method 1316 ) { 1317 mollie_nonce = 1318 cartflows_offer.wcf_mollie_creditcard_process_nonce; 1319 } 1320 if ( 1321 'mollie_wc_gateway_ideal' === cartflows_offer.payment_method 1322 ) { 1323 mollie_nonce = 1324 cartflows_offer.wcf_mollie_ideal_process_nonce; 1325 } 1326 1327 const offer_type = cartflows_offer.offer_type; 1328 1329 const ajax_data = { 1330 action: 'wcf_' + offer_type + '_accepted', 1331 offer_action: 'yes', 1332 offer_type, 1333 step_id: cartflows_offer.step_id, 1334 product_id: cartflows_offer.product_id, 1335 order_id: cartflows_offer.order_id, 1336 order_key: cartflows_offer.order_key, 1337 flow_id: cartflows.current_flow, 1338 stripe_sca_payment: false, 1339 stripe_intent_id: '', 1340 _nonce: mollie_nonce, 1341 }; 1342 1343 wcf_process_offer( ajax_data ); 1344 } 1345 } 1346 1347 wcf_capture_paypal_payments_order(); 1348 } ); 1349} )( jQuery );
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.