WooCommerce Code Reference

Search results

WooCommerce

Main WooCommerce Class.

Table of Contents

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

Properties

$deprecated_hook_handlers

Array of deprecated hook handlers.

public array $deprecated_hook_handlers = array()

Methods

instance()

Main WooCommerce Instance.

public static instance( ) : WooCommerce

Ensures only one instance of WooCommerce is loaded or can be loaded.

Tags
since
static
see
Return values
WooCommerce
  • Main instance.

__clone()

Cloning is forbidden.

public __clone( ) : mixed
Tags
since
Return values
mixed

__wakeup()

Unserializing instances of this class is forbidden.

public __wakeup( ) : mixed
Tags
since
Return values
mixed

__get()

Auto-load in-accessible properties on demand.

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

Key name.

Return values
mixed

__construct()

WooCommerce Constructor.

public __construct( ) : mixed
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
Return values
mixed

init_hooks()

Hook into actions and filters.

private init_hooks( ) : mixed
Tags
since
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
Return values
mixed

define_constants()

Define WC Constants.

private define_constants( ) : mixed
Return values
mixed

define_tables()

Register custom tables within $wpdb object.

private define_tables( ) : mixed
Return values
mixed

define()

Define constant if not already set.

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

Constant name.

$value : string|bool

Constant value.

Return values
mixed

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_request()

What type of request is this?

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

admin, ajax, cron or frontend.

Return values
bool

includes()

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

public includes( ) : mixed
Return values
mixed

theme_support_includes()

Include classes for theme support.

private theme_support_includes( ) : mixed
Tags
since
Return values
mixed

frontend_includes()

Include required frontend files.

public frontend_includes( ) : mixed
Return values
mixed

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

init()

Init WooCommerce when WordPress Initialises.

public init( ) : mixed
Return values
mixed

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

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

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
Return values
mixed

plugin_url()

Get the plugin url.

public plugin_url( ) : string
Return values
string

plugin_path()

Get the plugin path.

public plugin_path( ) : string
Return values
string

template_path()

Get the template path.

public template_path( ) : string
Return values
string

api_request_url()

Return the WC API URL for a given request.

public api_request_url( $request : string [, $ssl : bool|null = 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

load_webhooks()

Load & enqueue active webhooks.

private load_webhooks( ) : mixed
Tags
since
Return values
mixed

initialize_cart()

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

public initialize_cart( ) : void
Tags
since

initialize_session()

Initialize the session class.

public initialize_session( ) : void
Tags
since

wpdb_table_fix()

Set tablenames inside WPDB object.

public wpdb_table_fix( ) : mixed
Return values
mixed

activated_plugin()

Ran when any plugin is activated.

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

The filename of the activated plugin.

Tags
since
Return values
mixed

deactivated_plugin()

Ran when any plugin is deactivated.

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

The filename of the deactivated plugin.

Tags
since
Return values
mixed

build_dependencies_satisfied()

Check if plugin assets are built and minified

public build_dependencies_satisfied( ) : bool
Return values
bool

build_dependencies_notice()

Output a admin notice when build dependencies not met.

public build_dependencies_notice( ) : void

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
Back to the top