Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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 );
@Ruzgfpegk

This comment has been minimized.

Copy link

@Ruzgfpegk 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