📁 File Manager Pro
v10.0.3 | PHP: 8.1.34
Server: LiteSpeed
2026-07-02 02:30:41
📂
/ (Root)
/
home
/
apkbfjox
/
joygame.com.pk
/
wp-content
/
plugins
/
kadence-pro
/
dist
/
woocommerce-addons
/
src
📍 /home/apkbfjox/joygame.com.pk/wp-content/plugins/kadence-pro/dist/woocommerce-addons/src
🔄 Refresh
✏️
Editing: single-ajax-add-to-cart.js
Writable
( function ( $ ) { $.fn.serializeArrayAll = function () { var rCRLF = /\r?\n/g; return this.map( function () { return this.elements ? jQuery.makeArray( this.elements ) : this; } ) .map( function ( i, elem ) { var val = jQuery( this ).val(); if ( val == null ) { return val == null; } else if ( this.type == 'checkbox' && this.checked == false ) { return { name: this.name, value: this.checked ? this.value : '' }; } else { return jQuery.isArray( val ) ? jQuery.map( val, function ( val, i ) { return { name: elem.name, value: val.replace( rCRLF, '\r\n' ) }; } ) : { name: elem.name, value: val.replace( rCRLF, '\r\n' ) }; } } ) .get(); }; $( document ).on( 'click', '.single_add_to_cart_button:not(.disabled)', function ( e ) { var $thisbutton = $( this ), $form = $thisbutton.closest( 'form.cart' ), data = $form .find( 'input:not([name="product_id"]):not([type="radio"]):not([type="button"]), input[type="radio"]:checked, select, button, textarea' ) .serializeArrayAll() || 0; var final_data = { action: 'kadence_pro_add_to_cart', }; //sometimes (like for woocommerce subscription changes) there's imporatant data in the action url params //gather them up and add to post data for processing server side. const formAction = $form.attr( 'action' ); const formActionParsed = URL.parse( formAction ); formActionParsed.searchParams.forEach( ( value, key ) => { final_data[ key ] = value; } ); $.each( data, function ( i, item ) { if ( item.name == 'add-to-cart' ) { item.name = 'product_id'; item.value = $form.find( 'input[name=variation_id]' ).val() || $thisbutton.val(); final_data[ 'product_id' ] = $form.find( 'input[name=variation_id]' ).val() || $thisbutton.val(); } else if ( item.name ) { //if it's another value of a multiple input (such as checkboxes) if( final_data[ item.name ] && item.name.includes('[]') ) { Array.isArray(final_data[ item.name ]) ? final_data[ item.name ].push(item.value) : final_data[ item.name ] = [final_data[ item.name ], item.value]; }else { final_data[ item.name ] = item.value; } } } ); e.preventDefault(); $( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] ); $.ajax( { type: 'POST', //url: woocommerce_params.wc_ajax_url.toString().replace('%%endpoint%%', 'add_to_cart'), // url: woocommerce_params.ajax_url + '?' + formActionParams, url: woocommerce_params.ajax_url, data: final_data, beforeSend: function ( response ) { $thisbutton.removeClass( 'added' ).addClass( 'loading' ); }, complete: function ( response ) { $thisbutton.addClass( 'added' ).removeClass( 'loading' ); }, success: function ( response ) { if ( response.error && response.product_url ) { location.reload(); return; } // Legacy (WC < 10.6): jQuery fragments for classic mini cart widget/shortcode. $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); // WC 10.6+ iAPI mini cart block: dispatch the DOM event it listens for. if( document.body.querySelector( '[data-block-name="woocommerce/mini-cart"]' ) ) { document.dispatchEvent( new CustomEvent( 'wc-blocks_added_to_cart' ) ); } }, } ); return false; } ); } )( jQuery );
💾 Save Changes
❌ Cancel