By default, Number fields can be increased in increments of 1. If you want to change this value, e.g. to use decimals, add this snippet:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter the step parameter in Number fields to return decimals | |
*/ | |
function prefix_number_field_step( $step, $item ) { | |
return 0.01; | |
} | |
add_filter( 'pewc_number_field_step', 'prefix_number_field_step', 10, 2 ); | |
/** | |
* Filter the step parameter in some Number fields to return decimals | |
*/ | |
function prefix_specific_number_field_step( $step, $item ) { | |
if( $item['field_id'] == 1234 ) { // Change this to the ID of your field | |
return 0.01; | |
} | |
return $step; | |
} | |
add_filter( 'pewc_number_field_step', 'prefix_specific_number_field_step', 10, 2 ); |
Here’s how to add a snippet to your site.
Filtering the minimum / maximum step values
You can use a similar filter on the Min Value and Max Value settings for Number fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter the step value for min and max values | |
*/ | |
function prefix_min_max_val_step( $step, $item ) { | |
return 0.01; | |
} | |
add_filter( 'pewc_min_max_val_step', 'prefix_min_max_val_step', 10, 2 ); |