WooCommerce Code Reference

FeaturesUtil
in package

Class with methods that allow to retrieve information about the existing WooCommerce features, also has methods for WooCommerce plugins to declare (in)compatibility with the features.

Table of Contents

allow_activating_plugins_with_incompatible_features()  : void
Sets a flag indicating that it's allowed to activate plugins for which incompatible features are enabled from the WordPress plugins page.
allow_enabling_features_with_incompatible_plugins()  : void
Sets a flag indicating that it's allowed to enable features for which incompatible plugins are active from the WooCommerce feature settings page.
declare_compatibility()  : bool
Declare (in)compatibility with a given feature for a given plugin.
feature_is_enabled()  : bool
Check if a given feature is currently enabled.
get_compatible_features_for_plugin()  : array<string|int, mixed>
Get the ids of the features that a certain plugin has declared compatibility for.
get_compatible_plugins_for_feature()  : array<string|int, mixed>
Get the names of the plugins that have been declared compatible or incompatible with a given feature.
get_features()  : array<string|int, mixed>
Get all the existing WooCommerce features.

Methods

allow_activating_plugins_with_incompatible_features()

Sets a flag indicating that it's allowed to activate plugins for which incompatible features are enabled from the WordPress plugins page.

public static allow_activating_plugins_with_incompatible_features() : void
Return values
void

allow_enabling_features_with_incompatible_plugins()

Sets a flag indicating that it's allowed to enable features for which incompatible plugins are active from the WooCommerce feature settings page.

public static allow_enabling_features_with_incompatible_plugins() : void
Return values
void

declare_compatibility()

Declare (in)compatibility with a given feature for a given plugin.

public static declare_compatibility(string $feature_id, string $plugin_file[, bool $positive_compatibility = true ]) : bool

This method MUST be executed from inside a handler for the 'before_woocommerce_init' hook and SHOULD be executed from the main plugin file passing FILE or 'my-plugin/my-plugin.php' for the $plugin_file argument.

Parameters
$feature_id : string

Unique feature id.

$plugin_file : string

The full plugin file path.

$positive_compatibility : bool = true

True if the plugin declares being compatible with the feature, false if it declares being incompatible.

Return values
boolTrue on success, false on error (feature doesn't exist or not inside the required hook).

feature_is_enabled()

Check if a given feature is currently enabled.

public static feature_is_enabled(string $feature_id) : bool
Parameters
$feature_id : string

Unique feature id.

Return values
boolTrue if the feature is enabled, false if not or if the feature doesn't exist.

get_compatible_features_for_plugin()

Get the ids of the features that a certain plugin has declared compatibility for.

public static get_compatible_features_for_plugin(string $plugin_name) : array<string|int, mixed>

This method can't be called before the 'woocommerce_init' hook is fired.

Parameters
$plugin_name : string

Plugin name, in the form 'directory/file.php'.

Return values
array<string|int, mixed>An array having a 'compatible' and an 'incompatible' key, each holding an array of plugin ids.

get_compatible_plugins_for_feature()

Get the names of the plugins that have been declared compatible or incompatible with a given feature.

public static get_compatible_plugins_for_feature(string $feature_id) : array<string|int, mixed>
Parameters
$feature_id : string

Feature id.

Return values
array<string|int, mixed>An array having a 'compatible' and an 'incompatible' key, each holding an array of plugin names.

get_features()

Get all the existing WooCommerce features.

public static get_features([bool $include_experimental = false ][, bool $include_enabled_info = false ]) : array<string|int, mixed>

Returns an associative array where keys are unique feature ids and values are arrays with these keys:

  • name
  • description
  • is_experimental
  • is_enabled (if $include_enabled_info is passed as true)
Parameters
$include_experimental : bool = false

Include also experimental/work in progress features in the list.

$include_enabled_info : bool = false

True to include the 'is_enabled' field in the returned features info.

Tags
returns

array An array of information about existing features.

Return values
array<string|int, mixed>