WooCommerce Price UI Options Steps with Everything Over

Forums › Forums › Search & Filter Pro › WooCommerce Price UI Options Steps with Everything Over

Tagged: ,

Viewing 8 posts – 1 through 8 (of 8 total)
  • Anonymous
    #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
    Warren

    Trevor
    #268235

    It 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
    #268340

    Thanks 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
    Warren

    Trevor
    #268410

    Based 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
    #268414

    Thanks 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
    #268419

    This 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
    #268437

    Thanks 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
    #268439

    So 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.

Viewing 8 posts – 1 through 8 (of 8 total)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.