Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives

Incentive::dismiss()publicWC 1.0

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() WC 9.6.1

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 );
}