Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives

Incentive::validate_incentive()protectedWC 1.0

Validate an incentive details.

It will check if the incentive details have the required keys.

Method of the class: Incentive{}

No Hooks.

Return

true|false. Whether the incentive data is valid.

Usage

// protected - for code of main (parent) or child class
$result = $this->validate_incentive( $incentive ): bool;
$incentive(array) (required)
The incentive details.

Incentive::validate_incentive() code WC 9.6.0

protected function validate_incentive( array $incentive ): bool {
	// The incentive must have an ID, a promo ID, and a type.
	$required_keys = array( 'id', 'promo_id', 'type' );
	foreach ( $required_keys as $key ) {
		if ( empty( $incentive[ $key ] ) ) {
			return false;
		}
	}

	return true;
}