JS code improvement
-
I noticed that your Javascript code assumes that product has either all select boxes or all input fields. I have worked on several websites that have one select and one input which fails with your current JS code.
I propose Javascript change to amend this:
$( '.ajaxerrors' ).remove(); var item = {}, check = true, variations = $variation_form.find( '[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 //.css( 'border', '1px solid red' ) .addClass( 'required error' ) //.addClass( 'barizi-class' ) .before( '<div class="ajaxerrors"><p>Please select ' + attributeTaxName + '</p></div>' ) check = false; } else { item[attributeName] = attributevalue; } // Easy to add some specific code for select but doesn't seem to be needed // if ( $this.is( 'select' ) ) { // } else { // } } ); if ( !check ) { return false; }https://ww.wp.xz.cn/plugins/woocommerce-ajax-add-to-cart-for-variable-products/
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘JS code improvement’ is closed to new replies.