Viewing 2 replies - 1 through 2 (of 2 total)
  • Same problem here… Can anyone help us?

    Thread Starter alexlana

    (@alexlana)

    I solve it! ?? It work for my site, with some changes, it can work for other sites.

    I copy the file yith-wcan-frontend.js from “yith-woocommerce-ajax-navigation/assets/js/” to my theme “javascript” folder. After that, I include the following to my theme functions.php file:

    function yith_ajaxnlist_fix()  {
    	wp_dequeue_script( 'yith_wcan_frontend' );
    	wp_enqueue_script( 'yith_wcan_frontend', get_stylesheet_directory_uri() . '/javascripts/yith-wcan-frontend.js', array( 'jquery' ) );
    }
    add_action( 'init', 'yith_ajaxnlist_fix', 100 );
    function fc_prods_attr () {
    	global $woocommerce, $_attributes_array;
    
    	echo '<div id="prods_attr" style="display:none;">';
    
    	$current_term 	 = '';
    	$current_tax 	 = '';
    	$query_type 	 = 'or';
    	$display_type 	 = 'list';
    	$terms_type_list = 'all';
    	$qfiltro = 'tamanho';
    //	FIX TO WOOCOMMERCE 2.1
    	if ( function_exists( 'wc_attribute_taxonomy_name' ) ) {
    		$taxonomy = wc_attribute_taxonomy_name($qfiltro);
    	} else {
    		$taxonomy = $woocommerce->attribute_taxonomy_name($qfiltro);
    	}
    	$terms = yit_get_terms( $terms_type_list, $taxonomy );
    	if ( count( $terms ) > 0 ) {
    		foreach ( $terms as $term ) {
    			$t[] = $term->term_id;
    		}
    	}
    	$t = implode(',',$t);
    	echo $t;
    	echo '</div>';
    }
    add_action( 'wp_footer', 'fc_prods_attr' );

    Then use the folowing code on “yith-wcan-frontend.js” after line 98 ( $(document).trigger(“yith-wcan-ajax-filtered”); ):

    if ( $('.yith-wcan-list').length ) {
    					$.urlParam = function(url,name){
    						var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(url);
    						if ( url.indexOf( name )>0 ) {
    							return results[1] || 0;
    						} else {
    							return '';
    						}
    					}
    					var qfiltro = 'filter_tamanho';
    					var tams = $.urlParam(window.location.href,qfiltro);
    					tams = decodeURIComponent( tams );
    					var alltams = new Array();
    					alltams = $('#prods_attr').text().split(',');
    					var c = 0;
    					$(".yith-wcan-list li a").each(function(){
    						var acturl = $(this).attr('href');
    						var todostams = new Array();
    						todostams = tams.split(',');
    						if ( $.inArray('0',todostams) > -1 ) {
    							todostams.splice($.inArray('0',todostams),1);
    						}
    						if ( $.inArray(alltams[c],todostams)===-1 ) {
    							todostams[todostams.length] = alltams[c];
    							$(this).parent().removeClass('chosen');
    						} else {
    							todostams.splice($.inArray(alltams[c],todostams),1);
    							$(this).parent().addClass('chosen');
    						}
    						var tamurl = todostams.join(',');
    						var filtroaqui = acturl.indexOf(qfiltro+'=');
    						var retorno = acturl.substr( 0, filtroaqui );
    						var sparte = acturl.substr( filtroaqui );
    						sparte = sparte.substr( sparte.indexOf('&') );
    						retorno = retorno+qfiltro+'='+tamurl+sparte;
    						retorno = retorno.replace(/(<([^>]+)>)/ig,"");
    						$(this).attr('href',retorno);
    
    						c++;
    					});
    				}

    And I do not test if it breaks type = select. You want to change the variable “qfiltro” to your own product attribute on .JS file. And on functions.php too.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘YITH WooCommerce Ajax Navigation list not working’ is closed to new replies.