D
D
denism3002020-09-01 14:00:28
WooCommerce
denism300, 2020-09-01 14:00:28

How to implement a multi-select filter for WooCommerce?

I am writing a widget with filters for products and there was a gag when implementing multiple selection.
For example, there is this form:

<form id="woo-filter__form" class="woo-filter__form" method="GET" action="">
    <input id="pa_color_white" class="form-check-input woo-filter__checkbox" type="checkbox" name="filter_color" value="white">
    <label class="form-check-label woo-filter__label" for="pa_color_white">Белый</label>
    <input id="pa_color_black" class="form-check-input woo-filter__checkbox" type="checkbox" name="filter_color" value="black">
    <label class="form-check-label woo-filter__label" for="pa_color_black">Чёрный</label>
    <input id="pa_color_red" class="form-check-input woo-filter__checkbox" type="checkbox" name="filter_color" value="red">
    <label class="form-check-label woo-filter__label" for="pa_color_red">Красный</label>
    <input id="pa_color_blue" class="form-check-input woo-filter__checkbox" type="checkbox" name="filter_color" value="blue">
    <label class="form-check-label woo-filter__label" for="pa_color_blue">Голубой</label>
    <button id="woo-filter__submit" class="btn btn-primary woo-filter__submit" type="submit">Accept filters</button>
</form>

If you select one value, then everything is OK, the product is filtered.
If you select several, then the GET parameters are passed in this form:
?color=red&color=white
and the filter does not work.
How to send GET in format
?color=red,white
?

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