/* Wc add to cart version 2.2 */ jQuery( function( $ ) { // wc_add_to_cart_params is required to continue, ensure the object exists if ( typeof wc_add_to_cart_params === 'undefined' ) return false; // Ajax add to cart $( document ).on( 'click', '.variations_form .single_add_to_cart_button', function(e) { e.preventDefault(); $variation_form = $( this ).closest( '.variations_form' ); var var_id = $variation_form.find( 'input[name=variation_id]' ).val(); var product_id = $variation_form.find( 'input[name=product_id]' ).val(); var quantity = $variation_form.find( 'input[name=quantity]' ).val(); //attributes = []; $( '.ajaxerrors' ).remove(); var item = {}, check = true; variations = $variation_form.find( 'select[name^=attribute]' ); /* Updated code to work with radio button - mantish - WC Variations Radio Buttons - 8manos */ if ( !variations.length) { variations = $variation_form.find( '[name^=attribute]:checked' ); } /* Backup Code for getting input variable */ if ( !variations.length) { variations = $variation_form.find( 'input[name^=attribute]' ); } variations.each( function() { var $this = $( this ), attributeName = $this.attr( 'name' ), attributevalue = $this.val(), index, attributeTaxName; $this.removeClass( 'error' ); if ( attributevalue.length === 0 ) { index = attributeName.lastIndexOf( '_' ); attributeTaxName = attributeName.substring( index + 1 ); $this .addClass( 'required error' ) .before( '
Please select ' + attributeTaxName + '