Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives
Incentive::dismiss()
Dismiss an incentive.
Method of the class: Incentive{}
No Hooks.
Return
true|false
. True if the incentive was not previously dismissed and now it is. False if the incentive was already dismissed, or we failed to persist the dismissal data.
Usage
$Incentive = new Incentive(); $Incentive->dismiss( $id, $context, ?int $timestamp ): bool;
- $id(string) (required)
- The incentive ID to dismiss.
- $context(string)
- The context ID in which the incentive is dismissed. This can be used to dismiss the same incentive in different contexts. If no context ID is provided, the incentive will be dismissed for all contexts.
Default: 'all' - ?int $timestamp **
- -
Default: null
Incentive::dismiss() Incentive::dismiss code WC 9.6.0
public function dismiss( string $id, string $context = 'all', ?int $timestamp = null ): bool { // If it is already dismissed, don't dismiss it again. if ( $this->is_dismissed( $id, $context ) ) { return false; } $all_dismissed_incentives = $this->get_all_dismissed_incentives(); if ( empty( $all_dismissed_incentives[ $this->suggestion_id ] ) ) { $all_dismissed_incentives[ $this->suggestion_id ] = array(); ksort( $all_dismissed_incentives ); } $all_dismissed_incentives[ $this->suggestion_id ][] = array( 'id' => $id, 'context' => $context, 'timestamp' => $timestamp ?? time(), ); return $this->save_all_dismissed_incentives( $all_dismissed_incentives ); }