• Resolved umbzwp

    (@umbzwp)


    Hi,

    I am trying to filter a Woocommerce attribute by numeric range.
    Woocommerce attributes are text based, but there are some plugins around that offer attribute filter by range.
    Any idea how to setup a non-numeric range?

    
        <?php 
    	if ( woocommerce_product_loop() ) { 
    
    		$prodLenghtMin = intval( $prodLenghtMin );
    		$prodLenghtMax = intval( $prodLenghtMax );
    		$range = range($prodLenghtMin, $prodLenghtMax);
        
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    		$args = array(
    		'post_type'      => 'product',
    		'posts_per_page' => 10,
    		'orderby'=>'title',
    		'order' => 'ASC', 
    		'paged' => $paged
    		);
    
    		if ( $prodColor || $prodBrand || $prodLenghtMin ||  $prodLenghtMax ) {
    		  $args['tax_query'] = array();
    		  if ( $prodColor ) {
    		    $args['tax_query'][] = array(
    		      'taxonomy' => 'pa_color',
    		      'field' => 'slug',
    		      'terms' => $prodColor
    		    );
    		  }
    
    		  if ( $prodBrand ) {
    		   $args['tax_query'][] = array(
    		     'taxonomy' => 'pa_width',
    		     'field' => 'slug',
    		     'terms' => $prodBrand
    		    );
    		  }
              // this doesn't work:
    		  if ( $prodLenghtMin ||  $prodlenghtMax ) {
    		   $args['tax_query'][] = array(
    		     'taxonomy' => 'pa_lenght',
    		     'field' => 'slug',
    		     'type' => 'NUMERIC',
    		     'terms' => $range
    		    );
    		  } // end this doesn't work
    
    		}
    
            $loop = new WP_Query( $args );
    		   while ( $loop->have_posts() ) : $loop->the_post();
    			  global $product;
    
                 // [...] 
              endwhile; 
           wp_reset_postdata(); 
    
         }?>
    
    
Viewing 1 replies (of 1 total)
  • Plugin Support Paulo P – a11n

    (@paulostp)

    Hello,

    Thanks for reaching out!

    This is a fairly complex development topic – code customization is outside our scope of support.

    I’m going to leave it open for a bit to see if anyone from the community is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Best,

Viewing 1 replies (of 1 total)

The topic ‘Attribute numeric range filter’ is closed to new replies.