Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives
Incentive::validate_incentive
Validate an incentive details.
It will check if the incentive details have the required keys.
Method of the class: Incentive{}
No Hooks.
Returns
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() Incentive::validate incentive code WC 10.5.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;
}