Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Last active August 5, 2023 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plugin-republic/f94167090fda0d76ddf9eccd894dc432 to your computer and use it in GitHub Desktop.
Save plugin-republic/f94167090fda0d76ddf9eccd894dc432 to your computer and use it in GitHub Desktop.
<?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 );
@Ruzgfpegk
Copy link

Ruzgfpegk commented Feb 19, 2020

And for more flexibility (applying a custom step for some fields only), it's also possible to use either the 'field_id' or 'group_id' key of the $item array (here with field_id):

function prefix_number_field_step( $step, $item ) {
	switch ( $item['field_id'] ) {
		case 42:
		case 135:
			$step = 10;
			break;
		case 69:
			$step = 420;
			break;
	}
	
	return $step;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment