WooCommerce Code Reference

Packages
in package

Packages class.

Tags
since
3.7.0

Table of Contents

$base_packages  : array<string|int, mixed>
Array of package names and their main package classes.
$merged_packages  : array<string|int, mixed>
Similar to $base_packages, but the packages included in this array can be deactivated via the 'woocommerce_merged_packages' filter.
$packages  : array<string|int, mixed>
Array of package names and their main package classes. Once a package has been merged into WooCommerce directly it should be removed from here and added to the merged packages array.
deactivate_merged_plugins()  : mixed
Prevent plugins already merged into WooCommerce core from getting activated as standalone plugins.
display_notice_for_merged_plugins()  : mixed
Displays a maintenance notice next to merged plugins, to inform users that the plugin functionality is now offered by WooCommerce core.
init()  : mixed
Init the package loader.
is_package_enabled()  : bool
Checks if a package is enabled.
mark_merged_plugins_as_pending_update()  : mixed
Mark merged plugins as pending update.
on_init()  : mixed
Callback for WordPress init hook.
package_exists()  : bool
Checks a package exists by looking for it's directory.
prepare_packages()  : mixed
Prepare merged packages for initialization.
should_load_class()  : bool
Checks a package exists by looking for it's directory.
deactivate_merged_packages()  : mixed
Deactivates merged feature plugins.
get_enabled_packages()  : array<string|int, mixed>
Gets all merged, enabled packages.
initialize_packages()  : mixed
Loads packages after plugins_loaded hook.
missing_package()  : mixed
If a package is missing, add an admin notice.
__construct()  : mixed
Static-only class.

Properties

$base_packages

Array of package names and their main package classes.

protected static array<string|int, mixed> $base_packages = array('woocommerce-admin' => '\Automattic\WooCommerce\Admin\Composer\Package', 'woocommerce-gutenberg-products-block' => '\Automattic\WooCommerce\Blocks\Package')

One a package has been merged into WooCommerce Core it should be moved from the package list and placed in this list. This will ensure that the feature plugin is disabled as well as provide the class to handle initialization for the now-merged feature plugin.

Once a package has been merged into WooCommerce Core it should have its slug added here. This will ensure that we deactivate the feature plugin automatically to prevent any problems caused by conflicts between the two versions caused by them both being active.

The packages included in this array cannot be deactivated and will always load with WooCommerce core.

$merged_packages

Similar to $base_packages, but the packages included in this array can be deactivated via the 'woocommerce_merged_packages' filter.

protected static array<string|int, mixed> $merged_packages = array('woocommerce-brands' => '\Automattic\WooCommerce\Internal\Brands')

$packages

Array of package names and their main package classes. Once a package has been merged into WooCommerce directly it should be removed from here and added to the merged packages array.

protected static array<string|int, mixed> $packages = array('email-editor' => '\Automattic\WooCommerce\Internal\EmailEditor\Package')

Methods

deactivate_merged_plugins()

Prevent plugins already merged into WooCommerce core from getting activated as standalone plugins.

public static deactivate_merged_plugins(string $plugin) : mixed
Parameters
$plugin : string

Plugin name.

Return values
mixed

display_notice_for_merged_plugins()

Displays a maintenance notice next to merged plugins, to inform users that the plugin functionality is now offered by WooCommerce core.

public static display_notice_for_merged_plugins(string $plugin_file) : mixed

Requires 'mark_merged_plugins_as_pending_update' to properly display this notice.

Parameters
$plugin_file : string

Plugin file.

Return values
mixed

init()

Init the package loader.

public static init() : mixed
Tags
since
3.7.0
Return values
mixed

is_package_enabled()

Checks if a package is enabled.

public static is_package_enabled(string $package) : bool
Parameters
$package : string

Package name.

Return values
bool

mark_merged_plugins_as_pending_update()

Mark merged plugins as pending update.

public static mark_merged_plugins_as_pending_update(array<string|int, mixed> $plugins) : mixed

This is required for correctly displaying maintenance notices.

Parameters
$plugins : array<string|int, mixed>

Plugins list.

Return values
mixed

on_init()

Callback for WordPress init hook.

public static on_init() : mixed
Return values
mixed

package_exists()

Checks a package exists by looking for it's directory.

public static package_exists(string $package) : bool
Parameters
$package : string

Package name.

Return values
bool

prepare_packages()

Prepare merged packages for initialization.

public static prepare_packages() : mixed

Especially useful when running actions early in the 'plugins_loaded' timeline.

Return values
mixed

should_load_class()

Checks a package exists by looking for it's directory.

public static should_load_class(string $class_name) : bool
Parameters
$class_name : string

Class name.

Return values
bool

deactivate_merged_packages()

Deactivates merged feature plugins.

protected static deactivate_merged_packages() : mixed

Once a feature plugin is merged into WooCommerce Core it should be deactivated. This method will ensure that a plugin gets deactivated. Note that for the first request it will still be active, and as such, there may be some odd behavior. This is unlikely to cause any issues though because it will be deactivated on the request that updates or activates WooCommerce.

Return values
mixed

get_enabled_packages()

Gets all merged, enabled packages.

protected static get_enabled_packages() : array<string|int, mixed>
Return values
array<string|int, mixed>

initialize_packages()

Loads packages after plugins_loaded hook.

protected static initialize_packages() : mixed

Each package should include an init file which loads the package so it can be used by core.

Return values
mixed

missing_package()

If a package is missing, add an admin notice.

protected static missing_package(string $package) : mixed
Parameters
$package : string

Package name.

Return values
mixed

__construct()

Static-only class.

private __construct() : mixed
Return values
mixed