Customize Value Postfix

Forums › Forums › Search & Filter Pro › Customize Value Postfix

Viewing 4 posts – 21 through 24 (of 24 total)
  • Ross Moderator
    #215170

    Hi Andrew

    Your link went offline so I couldn’t see. I’m guessing you tried something like the following section of code (this adds a prefix / postfix outside the select field itself).

    Also, notice the name doesn’t have the brackets _sfm_distance:

    function filter_input_object($input_object, $sfid){
    	
    	if(($input_object['name']!='_sfm_distance')){
    		return $input_object;
    	}
    	
    	//add/override prefix & postfix to the field
    	$input_object['prefix'] = "Prefix ";
    	$input_object['postfix'] = " Postfix";
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);

    However if you wanted to change the labels (or in this case append text to it) it would be like:

    function filter_input_object($input_object, $sfid){
    	
    	if(($input_object['name']!='_sfm_distance')){
    		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;
    	}
    	
    	//now we know there are options we can loop through each one, and change what we need
    	foreach($input_object['options'] as $option){
    		$option->label .= " miles";
    	}
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);

    Thanks

    PS – I’ve actaully tested both of these just now with my own field, so there shouldn’t be syntax errors.

    Anonymous
    #215176

    Thank you Ross. This works great except it also adds it to the ‘Change All Items’ label. So it’s displaying as:

    Distance miles
    5 – 15 miles
    15 – 25 miles

    whereas I just want:

    Distance
    5 – 15 miles
    15 – 25 miles

    Would that be possible?.

    Ross Moderator
    #215180

    Ah sure, then change the foreach loop to:

    	//now we know there are options we can loop through each one, and change what we need
    	foreach($input_object['options'] as $option){
    		
    		if($option->value!=''){
    			$option->label .= " miles";
    		}
    	}
    
    Anonymous
    #215182

    Perfect, thank you!

Viewing 4 posts – 21 through 24 (of 24 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.