Automattic\WooCommerce\StoreApi\Utilities

QuantityLimits::limit_to_multiple()publicWC 1.0

Return a number using the closest multiple of another number. Used to enforce step/multiple values.

Method of the class: QuantityLimits{}

No Hooks.

Return

Int.

Usage

$QuantityLimits = new QuantityLimits();
$QuantityLimits->limit_to_multiple( $number, $multiple_of, $rounding_ );
$number(int) (required)
Number to round.
$multiple_of(int) (required)
The multiple.
$rounding_(string)
-
Default: 'round'

QuantityLimits::limit_to_multiple() code WC 8.7.0

public function limit_to_multiple( int $number, int $multiple_of, string $rounding_function = 'round' ) {
	if ( $multiple_of <= 1 ) {
		return $number;
	}
	$rounding_function = in_array( $rounding_function, [ 'ceil', 'floor', 'round' ], true ) ? $rounding_function : 'round';
	return $rounding_function( $number / $multiple_of ) * $multiple_of;
}