Skip Navigation

[Resolved] New Price Range Filter for WooComerce

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 29 replies, has 3 voices.

Last updated by Shane 4 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1826665

Tell us what you are trying to do?
I'm trying to create a Price range filter for woocommerce products per category. We have 3 main listings categories. Each one needs different ranges of prices because of the type of properties they are.

Is there any documentation that you are following?
I have not been following any documentation. We where able to do the filter before but using toolset Legacy plugins. We now have switched to the Blocks and can't seem to find the option to create this type of filter.

Is there a similar example that we can see?
Yes you can. Here is a link for our old site that we are re-building with toolset now hidden link Check the last filter in the sort by section and you'll see the price ranges that we want.

What is the link to your site?
hidden link

I would appreciate if you guys can show me the right direction to create this type of filter or maybe help me create it so I can learn.

Thanks in advance.

#1827701

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for getting in touch.

Actually this should still be possible with blocks, however Is it the basic price filter that you want to use ?

Please let me know .
Thanks,
Shane

#1827709
Screenshot 2020-10-28 160840.jpg
Screenshot 2020-10-28 160531.jpg

Hi,

I want to have the sorting that i currently have but i also want to add a range price filter on a dropdown.

On the pic I uploaded is my current setup. On the other picture I Uploaded is the field i want to sort by which is the woo_price but i don't gate any options to add sorting by price range

#1827741

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2020-10-28 at 3.27.16 PM.png

Hello,

I want to have the sorting that i currently have but i also want to add a range price filter on a dropdown.

Thats because you are missing the filter section on this archive. You need to enable the search section in order to allow for filtering by the price. See Screenshot

To enable this you will need to use the block navigator on the top left hand side of the editor then click on the WordPress Archive block.

Thanks,
Shane

#1827777
Screenshot 2020-10-28 163857.jpg
Screenshot 2020-10-28 163730.jpg

I have activated the search. I tried this before but the woo_price field is not showing on the list.

I have also attached an image on how i want this filter to look. The picture with the filter is from another website

#1828597

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Would you mind allowing me to have admin access to the site so that I can see what is happening here?

I've enabled the private fields for your next response.

Thanks,
Shane

#1828837

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I see where your Toolset plugins are outdated which could be why the fields are not showing up.

Can you download the latest updates and update all the Toolset plugins and let me know if the issue remains?

You can get the latest versions from the link below.
https://toolset.com/account/downloads/

Thanks,
Shane

#1828853

I have updated the plugins and still can't see the Woocommerce price field on the drop down when creating the search field.

However on the sort by filter i am able to select the field fine.

#1828871

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

The fields should now be showing up now.

What I did was to assign the field group to the Default post type and then removed them.

Can you confirm that you are now able to see the fields in the search option.

Thanks
Shae

#1828897

It does show now, thanks. But I'm confused now on how I can create this filter.

This is what I want, just like I showed you before.

I need a dropdown with price ranges which are different per product category, for example:

Condos Dropdown:
All
0 to US$99,999
US$100,000 to US$299,999
Above US$300,000

House Dropdown :
All
0 to US$99,999
US$100,000 to US$299,999
US$300,000 to US$499,999
Above US$500,000

Lots Dropdown:
All
0 to US$99,999
US$100,000 to US$299,999
Above US$300,000

so if i click on one of those price ranges it should show me the properties un that price range sorted by default from low to high

#1832447

Hello Shane,

So, you have any tips on how I can accomplish this filter?

#1832465

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

For this I would recommend that your create your price filter as a between filter.

This means that you will end up having 2 dropdown where you will have both value.

So the user will have a From: and a To:

They can choose the lower price limit and the upper price limit and be able to search within those limits.

When adding the filter you should be able to get the option to create the filter as a between attribute.

Thanks,
Shane

#1833393

Hi Shane,

We had one of your collegues before help us with this filter. We had it working before on a previous site but unfortunately we lost the site.

here are the snippets codes and custom codes that was used. We've tried recreating this with no luck.

Here are the codes:

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
add_filter('wpv_filter_query', 'func_search_price_range_views_woo_price', 90, 2);
function func_search_price_range_views_woo_price($query, $setting) {
    if($setting['view_id'] == 19139) {
          
        foreach((array)$query['meta_query'] as $k=>$v):
            if(isset($v['key']) and $v['key']=='views_woo_price'){
                          
                   
                      $query['meta_query'][$k]['key'] = 'views_woo_price';
                      $query['meta_query'][$k]['type'] = 'NUMERIC';
                     if($v['value']=='>=500000'){
                       $query['meta_query'][$k]['compare'] = '>=';
                       $query['meta_query'][$k]['value'] = str_replace(">=","",$v['value']);
                     }else{
                        $query['meta_query'][$k]['compare'] = 'between';
                        $query['meta_query'][$k]['value'] = str_replace("-",",",$v['value']);
                     }
                 
            }
        endforeach;
    }
    return $query;
}
 
[wpv-control-postmeta type="select" field="views_woo_price" source="custom" url_param="wpv-views_woo_price" values=",0-99999,10000-299999,300000-499999,>=500000" display_values="All,US$ 0.00 - US$ 99%%COMMA%%999,US$ 100%%COMMA%%000 - US$ 299%%COMMA%%999,US$ 300%%COMMA%%000 - US$ 499%%COMMA%%999,Above US$ 500%%COMMA%%000"]
#1833413

Just for your reference this was discussed in this topic https://toolset.com/forums/topic/i-need-to-make-a-dropdown-filter/

#1833757

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I tried to log into the site again to assist further but it seems the admin credentials don't work anymore.

Can you check on this for me and let me know when I can have another look ?

Thanks,
Shane