Prices – change ranges to custom

Forums › Forums › Search & Filter Pro › Prices – change ranges to custom

Tagged: 

Viewing 10 posts – 11 through 20 (of 25 total)
  • Anonymous
    #257046
    This reply has been marked as private.
    Trevor
    #257121
    This reply has been marked as private.
    Anonymous
    #257176
    This reply has been marked as private.
    Anonymous
    #257180
    This reply has been marked as private.
    Trevor
    #257230
    This reply has been marked as private.
    Anonymous
    #257240
    This reply has been marked as private.
    Trevor
    #257249
    This reply has been marked as private.
    Ross Moderator
    #257419
    This reply has been marked as private.
    Anonymous
    #257451

    Thanks Ross, a dropdown with the 3 below options sound great !
    0-100 kr
    101-250 kr
    250 kr and up

    But can you help me write the function ?

    Ross Moderator
    #257605

    Hi Thomas

    I just did a test, this code, replaces the 4 th option in a list, with what you mention:

    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 4th one in the list (including the default), so we can do :
    	if ( isset ( $input_object['options'][3] ) ) {
    		$new_option = new StdClass();
    		$new_option->value = "250+10000000";
    		$new_option->label = "250 kr and up";
    		$input_object['options'][3] = $new_option;
    	}
    	
    
    	return $input_object;
    }
    
    add_filter('sf_input_object_pre', 'update_field_options', 10, 2);

    That should get you going 🙂

    Read the comments for a few clues.

    Best

Viewing 10 posts – 11 through 20 (of 25 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.