• Resolved jelly_bean

    (@jelly_bean)


    I’m having a problem on my site. I want to select Country and then Region i.e. Autralia, McLaren Vale. However the filter shows me all the products from Australia and all the products from McLaren Vale.

    This problem seems to be on the demo site too. If I select Music and Albums it shows all Music including the singles.

    The problem is with the search
    ?swoof=1&page=1&product_cat=music,albums

    It should be
    ?swoof=1&page=1&product_cat=music&product_cat=albums

    However that only shows the Albums filter at the top of the page, which seems to defeat the purpose of the plugin.

    https://www.ads-software.com/plugins/woocommerce-products-filter/

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author RealMag777

    (@realmag777)

    Hello
    You are using multi-drop-down for it? For such scenario as this one you should use radio or drop-down only
    Example: https://www.demo.woocommerce-filter.com/?swoof=1&page=1&product_tag=tag2

    OR

    You can realize it if ‘Country’ is the taxonomy and ‘Region’ is the taxonomy, and both realized as drop-downs with dynamic recount …

    Thread Starter jelly_bean

    (@jelly_bean)

    I’m using checkboxes because I want to select more than one category at a time. It seems to be using an OR rather than an AND operator. I had a look at index.php of the plugin, but couldn’t work out what to change to add ‘relation’ => ‘AND’ to the query.

    Thread Starter jelly_bean

    (@jelly_bean)

    I’ve found a solution!

    index.php line 1513 add
    'operator' => 'AND' to

    $res[] = array(
         'taxonomy' => $tax_slug,
          'field' => 'slug',
          'terms' => $value,
          'operator' => 'AND'
    );
    Plugin Author RealMag777

    (@realmag777)

    Great. Thank you …

    Thanks for this solution jelly_bean, I have been looking for a way to add AND operator in categories too. But one problem remains: If someone bookmarks the URL and then reopens it, the results will be displayed with OR operator, not AND.

    It would be nice to have a selection in the plugin settings for OR/AND operator in categories (if the results should have either one of the categories selected or the results must have all the categories selected). This choice should change URL too.

    Plugin Author RealMag777

    (@realmag777)

    @geo2arc
    Hello
    Good, I will think of it in the next version of the WOOF, looks like it has sense, thank you …

    corybeal

    (@corybeal)

    Hey guys,

    I tried to implement this solution but it doesn’t seem to be working…

    Is there an official fix for this yet?

    Thread Starter jelly_bean

    (@jelly_bean)

    Sorry, I should have updated. I can’t remember what exactly the problem was, but it didn’t work. I gave up and I am using the layered navigation that comes with WordPress now and using attributes rather than categories for my products.

    Plugin Author RealMag777

    (@realmag777)

    @corybeal

    Hello, what fix do you mean? The plugin works only with ‘AND’ logic now …

    @realmag777
    AND works between terms from different taxonomies, for example Category1 AND tag1. When you want to combine terms from the same taxonomy (Category1 AND Category2) so the results must have BOTH terms from this taxonomy, it doesn’t work. Results have Category1 OR Category 2.
    Since I upgraded to v.1.1.3.1 the above hack doesn’t work anymore…

    Plugin Author RealMag777

    (@realmag777)

    @geo2arc

    Hello

    And what can I say – if you need use that hack you can continue using v.1.1.2 https://www.woocommerce-filter.com/wp-content/uploads/2015/12/woocommerce-products-filter-112.zip

    OR

    in v.1.1.3.1 open index.php, find there private function get_tax_query($additional_taxes = ”) and try realize that hack there: https://clip2net.com/s/3sSdovA – try it …

    @realmag777

    Maybe you should make it a feature then? I’d love to be able to select either AND or OR options for the categories.

    Without this it’s really limiting. Almost to the point I’d consider it a ‘bug’.

    Plugin Author RealMag777

    (@realmag777)

    @corybeal

    Maybe you should make it a feature then? – I think it can be realised more simply using wp filter:

    private function get_tax_query($additional_taxes = '')
        {
            $data = $this->get_request_data();
            $res = array();
            //static $woo_taxonomies = NULL;
            $woo_taxonomies = NULL;
            //if (!$woo_taxonomies)
            {
                $woo_taxonomies = get_object_taxonomies('product');
            }
    
            //+++
    
            if (!empty($data) AND is_array($data))
            {
                foreach ($data as $tax_slug => $value)
                {
                    if (in_array($tax_slug, $woo_taxonomies))
                    {
                        $value = explode(',', $value);
    
                        $operator = apply_filters('woof_get_tax_query', $tax_slug, $value);
                        if (!empty($operator))
                        {
                            $res[] = array(
                                'taxonomy' => $tax_slug,
                                'field' => 'slug',
                                'terms' => $value,
                                'operator' => $operator
                            );
                        } else
                        {
                            $res[] = array(
                                'taxonomy' => $tax_slug,
                                'field' => 'slug',
                                'terms' => $value
                            );
                        }
                    }
                }
            }
            //+++
            //for shortcode
            //[woof_products is_ajax=1 per_page=8 dp=0 taxonomies=product_cat:9,12+locations:30,31]
            //dp - ID of shortcode of Display Product for WooCommerce
            $res = $this->_expand_additional_taxes_string($additional_taxes, $res);
            //+++
            if (!empty($res))
            {
                $res = array_merge(array('relation' => 'AND'), $res);
            }
    
            return $res;
        }

    I changed function a little, so try it ..

    Sorry to bring this up, but have you tried if the latest solution in your last post is working? I can’t seem to get it working.

    If I set the operator to AND the single category selection doesn’t filter anything, all the products are still shown and if I try to select two or more categories it doesn’t show any products but a message instead: “No products were found matching your selection.”

    Can you please try your solution to see if it’s working or needs changes?

    Plugin Author RealMag777

    (@realmag777)

    @debil123

    Hello

    No, as it is obsolete, read this please: https://www.woocommerce-filter.com/hook/woof_products_query/

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Issue with selecting more than one category’ is closed to new replies.