Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives
Incentive::dismiss
Dismiss an incentive.
Method of the class: Incentive{}
Hooks from the method
Returns
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 10.5.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(),
);
/**
* Fires when a payments extension suggestion incentive is dismissed.
*
* @param string $id The incentive ID.
* @param string $suggestion_id The suggestion ID the incentive belongs to.
* @param string $context The context ID in which the incentive is dismissed.
* Defaults to 'all'.
*
* @since 9.9.0
*/
do_action( 'woocommerce_admin_payments_extension_suggestion_incentive_dismissed', $id, $this->suggestion_id, $context );
return $this->save_all_dismissed_incentives( $all_dismissed_incentives );
}