Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives
Incentive::dismiss
Dismiss an incentive.
Метод класса: Incentive{}
Возвращает
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.
Использование
$Incentive = new Incentive(); $Incentive->dismiss( $id, $context, ?int $timestamp ): bool;
- $id(строка) (обязательный)
- The incentive ID to dismiss.
- $context(строка)
- 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.
По умолчанию: 'all' - ?int $timestamp
- .
По умолчанию: null
Код Incentive::dismiss() Incentive::dismiss WC 10.3.4
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 );
}