Automattic\WooCommerce\Internal\StockNotifications
StockNotifications::on_feature_enabled_changed
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.
Method of the class: StockNotifications{}
No Hooks.
Returns
null. Nothing (null).
Usage
$StockNotifications = new StockNotifications(); $StockNotifications->on_feature_enabled_changed( $feature_id, $enabled ): void;
- $feature_id(mixed) (required)
- The feature that changed.
- $enabled(mixed)
- Whether the feature is now enabled.
Default:false
StockNotifications::on_feature_enabled_changed() StockNotifications::on feature enabled changed code WC 11.3.0
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();
}
}