Forums › Forums › Search & Filter Pro › WooCommerce Price UI Options Steps with Everything Over
Tagged: V3, woocommerce
- This topic has 7 replies, 2 voices, and was last updated 3 years, 11 months ago by Trevor.
-
Anonymous(Private) November 30, 2020 at 12:44 pm #268183
Hi Trevor,
Hope you’re well and had a good weekend.
Is it possible to have more control over the price steps please?
Its been requested that the options here be set as follows:
- All Items
- 0 – 10,000
- 10,000 – 20,000
- 20,000 – 30,000
- 30,000 – 40,000
- 40,000 – 50,000
- 50,000 plus
So basically the **50,000 plus** shows all products from £50,000 upwards to whatever the most expensive item might be in that search.
Many thanks
WarrenTrevor(Private) November 30, 2020 at 4:06 pm #268235It is, but you will need to use PHP to do it. This post from our developer, Ross, has an example:
https://support.searchandfilter.com/forums/topic/prices-change-ranges-to-custom/page/2/#post-257605
I think this will become an option in V3, due in a few months.
Anonymous(Private) December 1, 2020 at 11:22 am #268340Thanks Trevor,
I tried the following but it hasn’t worked sadly:
function update_field_options($input_object, $sfid){ // ensure we are only filtering the correct field name - in this case the field we want to filter has the name '_sft_post_tag' if( $input_object['name'] != '_price' ) { return $input_object; } // if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types) if( ! isset( $input_object['options'] ) ) { return $input_object; } // this is an array of all the options, we can remove them all, recreate them, etc // var_dump( $input_object['options'] ); // we know the option you want to replace is the 4th one in the list (including the default), so we can do : if ( isset ( $input_object['options'][4] ) ) { $new_option = new StdClass(); $new_option->value = "50000+10000000"; $new_option->label = "50000 plus"; $input_object['options'][4] = $new_option; } return $input_object; } add_filter('sf_input_object_pre', 'update_field_options', 10, 2);
Do you have any ideas?
Many thanks
WarrenTrevor(Private) December 1, 2020 at 3:41 pm #268410Based on what you said in the original post, this:
// we know the option you want to replace is the 4th one in the list (including the default), so we can do : if ( isset ( $input_object['options'][4] ) ) { $new_option = new StdClass(); $new_option->value = "50000+10000000"; $new_option->label = "50000 plus"; $input_object['options'][4] = $new_option; }
Should be:
// we know the option you want to replace is the 7th one in the list (including the default), so we can do : if ( isset ( $input_object['options'][6] ) ) { $new_option = new StdClass(); $new_option->value = "50000+10000000"; $new_option->label = "50000 plus"; $input_object['options'][6] = $new_option; }
Does that work, if not, does it alter the list at all?
Anonymous(Private) December 1, 2020 at 3:51 pm #268414Thanks Trevor, no sorry that doesn’t seem to have any affect, please see link:
https://retrieved.usedkitchenexchange.co.uk/product-category/ex-display-kitchen/
Trevor(Private) December 1, 2020 at 4:15 pm #268419This line is wrong:
if( $input_object['name'] != '_price' ) {
It should be:
if( $input_object['name'] != '_sfm__price' ) {
I think. You also need to limit the number of entries in the dropdown to just 7. You would have to slice the array. Maybe like this at the end:
$input_object = array_slice( $input_object , 0 , 7, true ); return $input_object; } add_filter('sf_input_object_pre', 'update_field_options', 10, 2);
Anonymous(Private) December 1, 2020 at 5:12 pm #268437Thanks Trevor, that works perfectly — you’re a star!
Here’s the full working version for anyone else who’s interested:
function update_field_options($input_object, $sfid){ // ensure we are only filtering the correct field name - in this case the field we want to filter has the name '_sft_post_tag' if( $input_object['name'] != '_sfm__price' ) { return $input_object; } // if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types) if( ! isset( $input_object['options'] ) ) { return $input_object; } // this is an array of all the options, we can remove them all, recreate them, etc // var_dump( $input_object['options'] ); // we know the option you want to replace is the 7th one in the list (including the default), so we can do : if ( isset ( $input_object['options'][5] ) ) { $new_option = new StdClass(); $new_option->value = "40000+10000000"; $new_option->label = "40000 plus"; $input_object['options'][5] = $new_option; } return $input_object; } add_filter('sf_input_object_pre', 'update_field_options', 10, 2);
And finally I adjusted the UI options to Max value 40000 so no more options are displayed in the popup selector.
Trevor(Private) December 1, 2020 at 5:20 pm #268439So this comment:
we know the option you want to replace is the 7th one in the list (including the default), so we can do :
would correctly be:
we know the option you want to replace is the 6th one in the list (including the default), so we can do :
The reason is that you are editing element numbered 5, but as arrays number from 0, it is sixth element 😉
No need for my array splice either, you realized.
I will close this thread for now.
-
AuthorPosts