1/* Wc add to cart version 1.2.9 */ 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 $( document ).on( 'click', '.variations_form .single_add_to_cart_button', function(e) { 10 11 e.preventDefault(); 12 13 $variation_form = $( this ).closest( '.variations_form' ); 14 var var_id = $variation_form.find( 'input[name=variation_id]' ).val(); 15 16 var product_id = $variation_form.find( 'input[name=product_id]' ).val(); 17 var quantity = $variation_form.find( 'input[name=quantity]' ).val(); 18 19 //attributes = []; 20 $( '.ajaxerrors' ).remove(); 21 var item = {}, 22 check = true; 23 24 variations = $variation_form.find( 'select[name^=attribute]' ); 25 26 /* Updated code to work with radio button - mantish - WC Variations Radio Buttons - 8manos */ 27 if ( !variations.length) { 28 variations = $variation_form.find( '[name^=attribute]:checked' ); 29 } 30 31 /* Backup Code for getting input variable */ 32 if ( !variations.length) {
33 variations = $variation_form.find( 'input[name^=attribute]' ); 34 } 35 36 variations.each( function() { 37 38 var $this = $( this ), 39 attributeName = $this.attr( 'name' ), 40 attributevalue = $this.val(), 41 index, 42 attributeTaxName; 43 44 $this.removeClass( 'error' ); 45 46 if ( attributevalue.length === 0 ) { 47 index = attributeName.lastIndexOf( '_' ); 48 attributeTaxName = attributeName.substring( index + 1 ); 49 50 $this 51 //.css( 'border', '1px solid red' ) 52 .addClass( 'required error' ) 53 //.addClass( 'barizi-class' ) 54 .before( '<div class="ajaxerrors"><p>Please select ' + attributeTaxName + '</p></div>' ) 55 56 check = false; 57 } else { 58 item[attributeName] = attributevalue; 59 } 60 61 // Easy to add some specific code for select but doesn't seem to be needed 62 // if ( $this.is( 'select' ) ) { 63 // } else { 64 // } 65 66 } ); 67 68 if ( !check ) { 69 return false; 70 } 71 72 //item = JSON.stringify(item); 73 //alert(item); 74 //return false; 75 76 // AJAX add to cart request 77 78 var $thisbutton = $( this ); 79 80 if ( $thisbutton.is( '.variations_form .single_add_to_cart_button' ) ) { 81 82 $thisbutton.removeClass( 'added' ); 83 $thisbutton.addClass( 'loading' ); 84 85 var data = { 86 action: 'woocommerce_add_to_cart_variable_rc', 87 product_id: product_id, 88 quantity: quantity, 89 variation_id: var_id, 90 variation: item 91 }; 92 93 // Trigger event 94 $( 'body' ).trigger( 'adding_to_cart', [ $thisbutton, data ] ); 95 96 // Ajax action 97 $.post( wc_add_to_cart_params.ajax_url, data, function( response ) { 98 99 if ( ! response ) 100 return; 101 102 var this_page = window.location.toString(); 103 104 this_page = this_page.replace( 'add-to-cart', 'added-to-cart' ); 105 106 if ( response.error && response.product_url ) { 107 window.location = response.product_url; 108 return; 109 } 110 111 if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) { 112 113 window.location = wc_add_to_cart_params.cart_url; 114 return; 115 116 } else { 117 118 $thisbutton.removeClass( 'loading' ); 119 120 var fragments = response.fragments; 121 var cart_hash = response.cart_hash; 122 123 // Block fragments class 124 if ( fragments ) { 125 $.each( fragments, function( key ) { 126 $( key ).addClass( 'updating' ); 127 }); 128 } 129 130 // Block widgets and fragments 131 $( '.shop_table.cart, .updating, .cart_totals' ).fadeTo( '400', '0.6' ).block({ 132 message: null, 133 overlayCSS: { 134 opacity: 0.6 135 } 136 }); 137 138 // Changes button classes 139 $thisbutton.addClass( 'added' ); 140 141 // View cart text 142 if ( ! wc_add_to_cart_params.is_cart && 143 //Edit, was .size() instead of .length 144 $thisbutton.parent().find( '.added_to_cart' ).length === 0 145 ) { 146 $thisbutton.after( ' <a href="' + wc_add_to_cart_params.cart_url + '" class="added_to_cart wc-forward" title="' + 147 wc_add_to_cart_params.i18n_view_cart + '">' + wc_add_to_cart_params.i18n_view_cart + '</a>' ); 148 } 149 150 // Replace fragments 151 if ( fragments ) { 152 $.each( fragments, function( key, value ) { 153 $( key ).replaceWith( value ); 154 }); 155 } 156 157 // Unblock 158 $( '.widget_shopping_cart, .updating' ).stop( true ).css( 'opacity', '1' ).unblock(); 159 160 // Cart page elements 161 $( '.shop_table.cart' ).load( this_page + ' .shop_table.cart:eq(0) > *', function() { 162 163 $( '.shop_table.cart' ).stop( true ).css( 'opacity', '1' ).unblock(); 164 165 $( document.body ).trigger( 'cart_page_refreshed' ); 166 }); 167 168 $( '.cart_totals' ).load( this_page + ' .cart_totals:eq(0) > *', function() { 169 $( '.cart_totals' ).stop( true ).css( 'opacity', '1' ).unblock(); 170 }); 171 172 // Trigger event so themes can refresh other areas 173 $( document.body ).trigger( 'added_to_cart', [ fragments, cart_hash, $thisbutton ] ); 174 } 175 }); 176 177 return false; 178 179 } else { 180 return true; 181 } 182 183 }); 184 185});
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.