Support Forums

Looking for support? You can access the support system via your account.

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

Tagged: ,

Viewing 8 posts - 1 through 8 (of 8 total)
  • Warren O’Donoghue
    #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 Moderator
    #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.

    Warren O’Donoghue
    #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 Moderator
    #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?

    Warren O’Donoghue
    #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 Moderator
    #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);
    Warren O’Donoghue
    #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 Moderator
    #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)

The topic ‘WooCommerce Price UI Options Steps with Everything Over’ is closed to new replies.