WooCommerce Code Reference

WooCommerce
in package

Main WooCommerce Class.

Tags
class

WooCommerce

Table of Contents

$api  : WC_API
API instance
$cart  : WC_Cart
Cart instance.
$countries  : WC_Countries
Countries instance.
$customer  : WC_Customer
Customer instance.
$db_version  : string
WooCommerce Schema version.
$deprecated_hook_handlers  : array<string|int, mixed>
Array of deprecated hook handlers.
$integrations  : WC_Integrations
Integrations instance.
$order_factory  : WC_Order_Factory
Order factory instance.
$product_factory  : WC_Product_Factory
Product factory instance.
$query  : WC_Query
Query instance.
$session  : WC_Session|WC_Session_Handler
Session instance.
$structured_data  : WC_Structured_Data
Structured data instance.
$version  : string
WooCommerce version.
$_instance  : WooCommerce
The single instance of the class.
__clone()  : mixed
Cloning is forbidden.
__construct()  : mixed
WooCommerce Constructor.
__get()  : mixed
Auto-load in-accessible properties on demand.
__wakeup()  : mixed
Unserializing instances of this class is forbidden.
activated_plugin()  : mixed
Ran when any plugin is activated.
add_image_sizes()  : mixed
Add WC Image sizes to WP.
add_woocommerce_inbox_variant()  : mixed
Add woocommerce_inbox_variant for the Remote Inbox Notification.
ajax_url()  : string
Get Ajax URL.
api_request_url()  : string
Return the WC API URL for a given request.
build_dependencies_notice()  : void
Output a admin notice when build dependencies not met.
build_dependencies_satisfied()  : bool
Check if plugin assets are built and minified
call_function()  : mixed
Call a user function. This should be used to execute any non-idempotent function, especially those in the `includes` directory or provided by WordPress.
call_static()  : mixed
Call a static method in a class. This should be used to execute any non-idempotent method in classes from the `includes` directory.
checkout()  : WC_Checkout
Get Checkout Class.
deactivated_plugin()  : mixed
Ran when any plugin is deactivated.
frontend_includes()  : mixed
Include required frontend files.
get_global()  : mixed
Gets the value of a global.
get_instance_of()  : object
Gets an instance of a given legacy class.
include_template_functions()  : mixed
Function used to Init WooCommerce Template Functions - This makes them pluggable by plugins and themes.
includes()  : mixed
Include required core files used in admin and on the frontend.
init()  : mixed
Init WooCommerce when WordPress Initialises.
init_jetpack_connection_config()  : void
Initiali Jetpack Connection Config.
initialize_cart()  : void
Initialize the customer and cart objects and setup customer saving on shutdown.
initialize_session()  : void
Initialize the session class.
instance()  : WooCommerce
Main WooCommerce Instance.
is_rest_api_request()  : bool
Returns true if the request is a non-legacy REST API request.
is_wc_admin_active()  : bool
Is the WooCommerce Admin actively included in the WooCommerce core? Based on presence of a basic WC Admin function.
load_plugin_textdomain()  : mixed
Load Localisation files.
load_rest_api()  : mixed
Load REST API.
log_errors()  : mixed
Ensures fatal errors are logged so they can be picked up in the status report.
mailer()  : WC_Emails
Email Class.
on_plugins_loaded()  : mixed
When WP has loaded all plugins, trigger the `woocommerce_loaded` hook.
payment_gateways()  : WC_Payment_Gateways
Get gateways class.
plugin_path()  : string
Get the plugin path.
plugin_url()  : string
Get the plugin url.
queue()  : WC_Queue_Interface
Get queue instance.
setup_environment()  : mixed
Ensure theme and server variable compatibility and setup image sizes.
shipping()  : WC_Shipping
Get shipping class.
template_path()  : string
Get the template path.
wpdb_table_fix()  : mixed
Set tablenames inside WPDB object.
add_thumbnail_support()  : mixed
Ensure post thumbnail support is turned on.
define()  : mixed
Define constant if not already set.
define_constants()  : mixed
Define WC Constants.
define_tables()  : mixed
Register custom tables within $wpdb object.
init_hooks()  : mixed
Hook into actions and filters.
is_request()  : bool
What type of request is this?
load_webhooks()  : mixed
Load & enqueue active webhooks.
theme_support_includes()  : mixed
Include classes for theme support.

Properties

$db_version

WooCommerce Schema version.

public string $db_version = '430'
Tags
since
4.3

started with version string 430.

$deprecated_hook_handlers

Array of deprecated hook handlers.

public array<string|int, mixed> $deprecated_hook_handlers = array()

Methods

__get()

Auto-load in-accessible properties on demand.

public __get(mixed $key) : mixed
Parameters
$key : mixed

Key name.

Return values
mixed

__wakeup()

Unserializing instances of this class is forbidden.

public __wakeup() : mixed
Tags
since
2.1
Return values
mixed

activated_plugin()

Ran when any plugin is activated.

public activated_plugin(string $filename) : mixed
Parameters
$filename : string

The filename of the activated plugin.

Tags
since
3.6.0
Return values
mixed

add_image_sizes()

Add WC Image sizes to WP.

public add_image_sizes() : mixed

As of 3.3, image sizes can be registered via themes using add_theme_support for woocommerce and defining an array of args. If these are not defined, we will use defaults. This is handled in wc_get_image_size function.

3.3 sizes:

woocommerce_thumbnail - Used in product listings. We assume these work for a 3 column grid layout. woocommerce_single - Used on single product pages for the main image.

Tags
since
2.3
Return values
mixed

add_woocommerce_inbox_variant()

Add woocommerce_inbox_variant for the Remote Inbox Notification.

public add_woocommerce_inbox_variant() : mixed

P2 post can be found at https://wp.me/paJDYF-1uJ.

Return values
mixed

api_request_url()

Return the WC API URL for a given request.

public api_request_url(string $request[, bool|null $ssl = null ]) : string
Parameters
$request : string

Requested endpoint.

$ssl : bool|null = null

If should use SSL, null if should auto detect. Default: null.

Return values
string

build_dependencies_notice()

Output a admin notice when build dependencies not met.

public build_dependencies_notice() : void
Return values
void

build_dependencies_satisfied()

Check if plugin assets are built and minified

public build_dependencies_satisfied() : bool
Return values
bool

call_function()

Call a user function. This should be used to execute any non-idempotent function, especially those in the `includes` directory or provided by WordPress.

public call_function(string $function_name, mixed ...$parameters) : mixed

This method can be useful for unit tests, since functions called using this method can be easily mocked by using WC_Unit_Test_Case::register_legacy_proxy_function_mocks.

Parameters
$function_name : string

The function to execute.

$parameters : mixed

The parameters to pass to the function.

Tags
since
4.4
Return values
mixedThe result from the function.

call_static()

Call a static method in a class. This should be used to execute any non-idempotent method in classes from the `includes` directory.

public call_static(string $class_name, string $method_name, mixed ...$parameters) : mixed

This method can be useful for unit tests, since methods called using this method can be easily mocked by using WC_Unit_Test_Case::register_legacy_proxy_static_mocks.

Parameters
$class_name : string

The name of the class containing the method.

$method_name : string

The name of the method.

$parameters : mixed

The parameters to pass to the method.

Tags
since
4.4
Return values
mixedThe result from the method.

deactivated_plugin()

Ran when any plugin is deactivated.

public deactivated_plugin(string $filename) : mixed
Parameters
$filename : string

The filename of the deactivated plugin.

Tags
since
3.6.0
Return values
mixed

frontend_includes()

Include required frontend files.

public frontend_includes() : mixed
Return values
mixed

get_global()

Gets the value of a global.

public get_global(string $global_name) : mixed
Parameters
$global_name : string

The name of the global to get the value for.

Return values
mixedThe value of the global.

get_instance_of()

Gets an instance of a given legacy class.

public get_instance_of(string $class_name, mixed ...$args) : object

This must not be used to get instances of classes in the src directory.

This method can be useful for unit tests, since objects obtained using this method can be easily mocked by using WC_Unit_Test_Case::register_legacy_proxy_class_mocks.

Parameters
$class_name : string

The name of the class to get an instance for.

$args : mixed

Parameters to be passed to the class constructor or to the appropriate internal 'get_instance_of_' method.

Tags
throws
Exception

The requested class belongs to the src directory, or there was an error creating an instance of the class.

since
4.4
Return values
objectThe instance of the class.

include_template_functions()

Function used to Init WooCommerce Template Functions - This makes them pluggable by plugins and themes.

public include_template_functions() : mixed
Return values
mixed

includes()

Include required core files used in admin and on the frontend.

public includes() : mixed
Return values
mixed

init_jetpack_connection_config()

Initiali Jetpack Connection Config.

public init_jetpack_connection_config() : void
Return values
void

initialize_cart()

Initialize the customer and cart objects and setup customer saving on shutdown.

public initialize_cart() : void
Tags
since
3.6.4
Return values
void

initialize_session()

Initialize the session class.

public initialize_session() : void
Tags
since
3.6.4
Return values
void

is_rest_api_request()

Returns true if the request is a non-legacy REST API request.

public is_rest_api_request() : bool

Legacy REST requests should still run some extra code for backwards compatibility.

Tags
todo:

replace this function once core WP function is available: https://core.trac.wordpress.org/ticket/42061.

Return values
bool

is_wc_admin_active()

Is the WooCommerce Admin actively included in the WooCommerce core? Based on presence of a basic WC Admin function.

public is_wc_admin_active() : bool
Return values
bool

load_plugin_textdomain()

Load Localisation files.

public load_plugin_textdomain() : mixed

Note: the first-loaded translation file overrides any following ones if the same translation is present.

Locales found in: - WP_LANG_DIR/woocommerce/woocommerce-LOCALE.mo - WP_LANG_DIR/plugins/woocommerce-LOCALE.mo

Return values
mixed

log_errors()

Ensures fatal errors are logged so they can be picked up in the status report.

public log_errors() : mixed
Tags
since
3.2.0
Return values
mixed

on_plugins_loaded()

When WP has loaded all plugins, trigger the `woocommerce_loaded` hook.

public on_plugins_loaded() : mixed

This ensures woocommerce_loaded is called only after all other plugins are loaded, to avoid issues caused by plugin directory naming changing the load order. See #21524 for details.

Tags
since
3.6.0
Return values
mixed

setup_environment()

Ensure theme and server variable compatibility and setup image sizes.

public setup_environment() : mixed
Return values
mixed

add_thumbnail_support()

Ensure post thumbnail support is turned on.

private add_thumbnail_support() : mixed
Return values
mixed

define()

Define constant if not already set.

private define(string $name, string|bool $value) : mixed
Parameters
$name : string

Constant name.

$value : string|bool

Constant value.

Return values
mixed

define_tables()

Register custom tables within $wpdb object.

private define_tables() : mixed
Return values
mixed

init_hooks()

Hook into actions and filters.

private init_hooks() : mixed
Tags
since
2.3
Return values
mixed

is_request()

What type of request is this?

private is_request(string $type) : bool
Parameters
$type : string

admin, ajax, cron or frontend.

Return values
bool

load_webhooks()

Load & enqueue active webhooks.

private load_webhooks() : mixed
Tags
since
2.2
Return values
mixed

theme_support_includes()

Include classes for theme support.

private theme_support_includes() : mixed
Tags
since
3.3.0
Return values
mixed