WooCommerce Code Reference

WC_Frontend_Scripts
in package

Frontend scripts class.

These scripts are enqueued in the frontend of the store. The registered script handles in this class can be used to enqueue the scripts in the frontend by third party plugins and the handles will follow WooCommerce's L-1 support policy. Scripts registered outside of this class do not guarantee support and can be removed in future versions of WooCommerce.

Table of Contents

$registered_scripts  : array<string|int, mixed>
Contains an array of script handles registered by WC.
$styles  : array<string|int, mixed>
Contains an array of script handles registered by WC.
$wp_localize_scripts  : array<string|int, mixed>
Contains an array of script handles localized by WC.
add_legacy_script_warnings()  : mixed
Add warnings for deprecated script handles.
get_styles()  : array<string|int, mixed>
Get styles for the frontend.
init()  : mixed
Hook in methods.
load_scripts()  : mixed
Register/queue frontend scripts.
localize_printed_scripts()  : mixed
Localize scripts only when enqueued.
enqueue_script()  : mixed
Register and enqueue a script for use.
enqueue_style()  : mixed
Register and enqueue a styles for use.
get_asset_url()  : string
Return asset URL.
get_script_data()  : array<string|int, mixed>|bool
Return data for script handles.
get_scripts()  : array<string|int, mixed>
Get scripts for the frontend.
localize_script()  : mixed
Localize a WC script once.
register_script()  : mixed
Register a script for use.
register_scripts()  : mixed
Register all WC scripts.
register_style()  : mixed
Register a style for use.
register_styles()  : mixed
Register all WC styles.

Properties

$wp_localize_scripts

Contains an array of script handles localized by WC.

private static array<string|int, mixed> $wp_localize_scripts = array()

Methods

add_legacy_script_warnings()

Add warnings for deprecated script handles.

public static add_legacy_script_warnings() : mixed
Return values
mixed

enqueue_script()

Register and enqueue a script for use.

private static enqueue_script(string $handle[, string $path = '' ][, array<string|int, string> $deps = array('jquery') ][, string $version = WC_VERSION ][, bool $in_footer = array('strategy' => 'defer') ]) : mixed
Parameters
$handle : string

Name of the script. Should be unique.

$path : string = ''

Full URL of the script, or path of the script relative to the WordPress root directory.

$deps : array<string|int, string> = array('jquery')

An array of registered script handles this script depends on.

$version : string = WC_VERSION

String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.

$in_footer : bool = array('strategy' => 'defer')

Whether to enqueue the script before instead of in the . Default 'false'.

Tags
uses
wp_enqueue_script()
Return values
mixed

enqueue_style()

Register and enqueue a styles for use.

private static enqueue_style(string $handle[, string $path = '' ][, array<string|int, string> $deps = array() ][, string $version = WC_VERSION ][, string $media = 'all' ][, bool $has_rtl = false ]) : mixed
Parameters
$handle : string

Name of the stylesheet. Should be unique.

$path : string = ''

Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.

$deps : array<string|int, string> = array()

An array of registered stylesheet handles this stylesheet depends on.

$version : string = WC_VERSION

String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.

$media : string = 'all'

The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.

$has_rtl : bool = false

If has RTL version to load too.

Tags
uses
wp_enqueue_style()
Return values
mixed

get_asset_url()

Return asset URL.

private static get_asset_url(string $path) : string
Parameters
$path : string

Assets path.

Return values
string

get_script_data()

Return data for script handles.

private static get_script_data(string $handle) : array<string|int, mixed>|bool
Parameters
$handle : string

Script handle the data will be attached to.

Return values
array<string|int, mixed>|bool

localize_script()

Localize a WC script once.

private static localize_script(string $handle) : mixed
Parameters
$handle : string

Script handle the data will be attached to.

Tags
since
2.3.0

this needs less wp_script_is() calls due to https://core.trac.wordpress.org/ticket/28404 being added in WP 4.0.

Return values
mixed

register_script()

Register a script for use.

private static register_script(string $handle, string $path[, array<string|int, string> $deps = array('jquery') ][, string $version = WC_VERSION ][, bool $in_footer = array('strategy' => 'defer') ]) : mixed
Parameters
$handle : string

Name of the script. Should be unique.

$path : string

Full URL of the script, or path of the script relative to the WordPress root directory.

$deps : array<string|int, string> = array('jquery')

An array of registered script handles this script depends on.

$version : string = WC_VERSION

String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.

$in_footer : bool = array('strategy' => 'defer')

Whether to enqueue the script before instead of in the . Default 'false'.

Tags
uses
wp_register_script()
Return values
mixed

register_style()

Register a style for use.

private static register_style(string $handle, string $path[, array<string|int, string> $deps = array() ][, string $version = WC_VERSION ][, string $media = 'all' ][, bool $has_rtl = false ]) : mixed
Parameters
$handle : string

Name of the stylesheet. Should be unique.

$path : string

Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.

$deps : array<string|int, string> = array()

An array of registered stylesheet handles this stylesheet depends on.

$version : string = WC_VERSION

String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.

$media : string = 'all'

The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.

$has_rtl : bool = false

If has RTL version to load too.

Tags
uses
wp_register_style()
Return values
mixed