WC_Shipping_Flat_Rate::is_math_expression │ protected │ WC 1.0

Check if a value is a math expression.

Matches two or more numeric operands separated by arithmetic operators.

Метод класса: WC_Shipping_Flat_Rate{}

Хуков нет.

Возвращает

bool. True if value is a well-formed math expression.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->is_math_expression( $value ): bool;
$value(строка) (обязательный)
Value to test.

Код WC_Shipping_Flat_Rate::is_math_expression() WC 11.2.2

protected function is_math_expression( string $value ): bool {
	$decimal_separator = wc_get_price_decimal_separator();

	// Use preg_quote() to safely escaping separator.
	$separator = preg_quote( $decimal_separator, '/' );

	// Breakdown:
	// [\d{sep}\s]+             - First operand: digits, separator, or spaces.
	// (                        - Begin repeating group:
	// [+\-*\/]               -   An arithmetic operator (+, -, *, /).
	// [\d{sep}\s]+           -   Next operand: digits, separator, or spaces.
	// )+                       - One or more operator+operand pairs (ensures no trailing operator).
	return (bool) preg_match(
		'/^[\d' . $separator . '\s]+([+\-*\/][\d' . $separator . '\s]+)+$/',
		trim( $value )
	);
}