Automattic\WooCommerce\Internal\StockNotifications

StockNotifications::on_feature_enabled_changed │ public │ WC 1.0

Set up or tear down the feature's side effects when it is toggled.

Toggling from the Features screen fires no install event, so the daily data retention task and the rewrite rules have to be handled here.

Params are untyped and coerced in the body because any third-party code can fire this action with fewer or differently-typed arguments.

Метод класса: StockNotifications{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$StockNotifications = new StockNotifications();
$StockNotifications->on_feature_enabled_changed( $feature_id, $enabled ): void;
$feature_id(разное) (обязательный)
The feature that changed.
$enabled(разное)
Whether the feature is now enabled.
По умолчанию: false

Код StockNotifications::on_feature_enabled_changed() WC 11.2.2

public function on_feature_enabled_changed( $feature_id, $enabled = false ): void {
	if ( self::FEATURE_NAME !== $feature_id ) {
		return;
	}

	$enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );

	// The My Account endpoint appears or disappears with the feature.
	update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );

	$data_retention_controller = wc_get_container()->get( DataRetentionController::class );

	if ( $enabled ) {
		$data_retention_controller->on_woo_install_or_update();
	} else {
		$data_retention_controller->clear_daily_task();
	}
}