Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives
Incentive::is_dismissed
Check if an incentive has been manually dismissed.
Method of the class: Incentive{}
No Hooks.
Returns
true|false. Whether the incentive has been manually dismissed.
Usage
$Incentive = new Incentive(); $Incentive->is_dismissed( $id, $context ): bool;
- $id(string) (required)
- The incentive ID to check for dismissal.
- $context(string)
- The context ID in which to check for dismissal. If no context ID is provided, we check for dismissal in all contexts.
Default: ''
Incentive::is_dismissed() Incentive::is dismissed code WC 10.3.3
public function is_dismissed( string $id, string $context = '' ): bool {
if ( empty( $id ) ) {
return false;
}
$all_dismissed_incentives = $this->get_all_dismissed_incentives();
// If there are no dismissed incentives for the suggestion, return early.
$dismissed_incentives = $all_dismissed_incentives[ $this->suggestion_id ] ?? array();
if ( empty( $dismissed_incentives ) ) {
return false;
}
// Check if the incentive is dismissed in the given context.
if ( in_array(
$id,
array_column(
array_filter(
$dismissed_incentives,
// All context dismissals are always included.
fn( $dismissed_incentive ) => 'all' === $dismissed_incentive['context'] || $context === $dismissed_incentive['context']
),
'id'
),
true
) ) {
return true;
}
return false;
}