T
T
th3_h0st2020-06-08 21:45:34
WordPress
th3_h0st, 2020-06-08 21:45:34

WooCommerce Filter products by custom fields min/max slider?

I wanted to figure out how to make my own filter for products.
I made a slider using jquery ui:

<div class="projects-filter-full-s">
      <div id="result-filter-full-s"></div>
      <label for="filter-full-s">Площадь, м<sup>2</sup>:</label>
      <input type="num" id="filter-full-s" readonly style="border:0;">	
      
      <form method="get" id="filter-full-s">
    			<div class="price_slider_amount" data-step="10">
    			  <input type="text" id="min_full_s" name="min_full_s" value="50" data-min="50" placeholder="Минимальная площадь" style="display: none;">
    			  <input type="text" id="max_full_s" name="max_full_s" value="300" data-max="300" placeholder="Максимальная площадь" style="display: none;">
    			</div>
    			<button type="submit" class="button">Фильтровать</button>
    			<input type="hidden" name="action" value="myfilter">
    		</form>
    
    </div>


It looks like this:
5ede846045d98662910782.png

How I imagine the work of this filter
: at the output of the form 2 inputs, I need to pass them to the handler, which will take my custom field from the product and if it fits into the range between them, then display all products with a suitable parameter.
A custom field can be at least written through a plugin, it doesn’t matter to me.

It is not clear to me where in the handler to take the variable of the field itself in order to compare it with the values ​​from the form.
I don't know how to get this whole thing out.

I would also like to display all this through AJAX.
Read about admin-ajax.php
Read Misha Rudrastykh's article "3 Steps to Create AJAX Post Filters". There are no examples on the network except for his article.
I tried to do it through MDTF, but there is such a mess .. Haven't figured it out yet.

In fact, the complexity is in the final stage, in writing a form handler.
It is important that it works with other product filters (price, attributes)
If it is possible to combine the filter with sliders with a product attribute, then it will be even easier

.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question