Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors

TotalPaymentsVolumeProcessor::validatepublicWC 1.0

Validates the rule.

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

Хуков нет.

Возвращает

true|false. Pass/fail.

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

$TotalPaymentsVolumeProcessor = new TotalPaymentsVolumeProcessor();
$TotalPaymentsVolumeProcessor->validate( $rule );
$rule(объект) (обязательный)
The rule to validate.

Код TotalPaymentsVolumeProcessor::validate() WC 10.5.2

public function validate( $rule ) {
	$allowed_timeframes = array(
		'last_week',
		'last_month',
		'last_quarter',
		'last_6_months',
		'last_year',
	);

	if ( ! isset( $rule->timeframe ) || ! in_array( $rule->timeframe, $allowed_timeframes, true ) ) {
		return false;
	}

	if ( ! isset( $rule->value ) ) {
		return false;
	}

	if ( ! isset( $rule->operation ) ) {
		return false;
	}

	// If the operation is range, the value must be an array of two numbers.
	if ( 'range' === $rule->operation ) {
		if ( ! is_array( $rule->value ) || count( $rule->value ) !== 2 ) {
			return false;
		}

		if ( ! is_numeric( $rule->value[0] ) || ! is_numeric( $rule->value[1] ) ) {
			return false;
		}
	} elseif ( ! is_numeric( $rule->value ) ) {
			return false;
	}

	return true;
}