WooCommerce Code Reference

WC_Helper
in package

WC_Helper Class

The main entry-point for all things related to the Helper.

Table of Contents

$log  : mixed
A log object returned by wc_get_logger().
_flush_authentication_cache()  : mixed
Flush auth cache.
_flush_subscriptions_cache()  : mixed
Flush subscriptions cache.
_sort_by_name()  : int
Sort subscriptions by the Name.
_sort_by_product_name()  : int
Sort subscriptions by the product_name.
activated_plugin()  : mixed
Runs when any plugin is activated.
add_utm_params_to_url_for_subscription_link()  : string
Add tracking parameters to buttons (Renew, Purchase, etc.) on subscriptions page
admin_enqueue_scripts()  : mixed
Enqueue admin scripts and styles.
admin_notices()  : mixed
Various Helper-related admin notices.
connect_with_password()  : void|WP_Error
Allows to connect with WCCOM using application password. used it to connect via CLI
current_screen()  : mixed
Various early-phase actions with possible redirects.
deactivated_plugin()  : mixed
Runs when any plugin is deactivated.
disconnect()  : void
Handles WC Helper disconnect tasks.
get_current_filter()  : string
Get current filter.
get_filters()  : array<string|int, mixed>
Get available subscriptions filters.
get_filters_counts()  : array<string|int, mixed>
Get counts data for the filters array.
get_local_woo_plugins()  : mixed
Obtain a list of data about locally installed Woo extensions.
get_local_woo_themes()  : mixed
Get locally installed Woo themes.
get_subscriptions()  : array<string|int, mixed>
Get the connected user's subscriptions.
get_view_filename()  : string
Get an absolute path to the requested helper view.
has_product_subscription()  : bool
Checks whether current site has product subscription of a given ID.
is_site_connected()  : bool
Checks if `access_token` exists in `auth` option.
load()  : mixed
Loads the helper class, runs on init.
log()  : mixed
Log a helper event.
render_helper_output()  : mixed
Render the helper section content based on context.
update_auth_option()  : void
Updates auth options and flushes cache
includes()  : mixed
Include supporting helper classes.
_filter()  : mixed
Filter an array of subscriptions by $filter.
_flush_updates_cache()  : mixed
Flush updates cache.
_get_extensions_update_notice()  : string|null
Get an update notice if one or more Woo extensions has an update available.
_get_local_from_product_id()  : array<string|int, mixed>|bool
Get a local plugin/theme entry from product_id.
_get_return_notices()  : array<string|int, mixed>
Various success/error notices.
_get_subscriptions_from_product_id()  : array<string|int, mixed>|bool
Get a subscription entry from product_id. If multiple subscriptions are found with the same product id and $single is set to true, will return the first one in the list, so you can use this method to get things like extension name, version, etc.
_helper_auth_connect()  : mixed
Initiate a new OAuth connection.
_helper_auth_disconnect()  : mixed
Disconnect from WooCommerce.com, clear OAuth tokens.
_helper_auth_refresh()  : mixed
User hit the Refresh button, clear all caches.
_helper_auth_return()  : mixed
Return from WooCommerce.com OAuth flow.
_helper_plugin_deactivate()  : mixed
Deactivate a plugin.
_helper_subscription_activate()  : mixed
Active a product subscription.
_helper_subscription_deactivate()  : mixed
Deactivate a product subscription.
_woo_core_update_available()  : bool
Whether WooCommerce has an update available.

Properties

Methods

_sort_by_name()

Sort subscriptions by the Name.

public static _sort_by_name(array<string|int, mixed> $a, array<string|int, mixed> $b) : int
Parameters
$a : array<string|int, mixed>

Product array.

$b : array<string|int, mixed>

Product array.

Return values
int

_sort_by_product_name()

Sort subscriptions by the product_name.

public static _sort_by_product_name(array<string|int, mixed> $a, array<string|int, mixed> $b) : int
Parameters
$a : array<string|int, mixed>

Subscription array.

$b : array<string|int, mixed>

Subscription array.

Return values
int

activated_plugin()

Runs when any plugin is activated.

public static activated_plugin(string $filename) : mixed

Depending on the activated plugin attempts to look through available subscriptions and auto-activate one if possible, so the user does not need to visit the Helper UI at all after installing a new extension.

Parameters
$filename : string

The filename of the activated plugin.

Return values
mixed

Add tracking parameters to buttons (Renew, Purchase, etc.) on subscriptions page

public static add_utm_params_to_url_for_subscription_link(string $url, string $utm_content) : string
Parameters
$url : string

URL to product page or to https://woocommerce.com/my-account/my-subscriptions/

$utm_content : string

value of utm_content query parameter used for tracking

Return values
stringURL including utm parameters for tracking

connect_with_password()

Allows to connect with WCCOM using application password. used it to connect via CLI

public static connect_with_password(string $password) : void|WP_Error
Parameters
$password : string

The application password.

Return values
void|WP_Error

current_screen()

Various early-phase actions with possible redirects.

public static current_screen(object $screen) : mixed
Parameters
$screen : object

WP screen object.

Return values
mixed

deactivated_plugin()

Runs when any plugin is deactivated.

public static deactivated_plugin(string $filename) : mixed

When a user deactivates a plugin, attempt to deactivate any subscriptions associated with the extension.

Parameters
$filename : string

The filename of the deactivated plugin.

Return values
mixed

get_filters()

Get available subscriptions filters.

public static get_filters() : array<string|int, mixed>
Return values
array<string|int, mixed>An array of filter keys and labels.

get_filters_counts()

Get counts data for the filters array.

public static get_filters_counts([array<string|int, mixed> $subscriptions = null ]) : array<string|int, mixed>
Parameters
$subscriptions : array<string|int, mixed> = null

The array of all available subscriptions.

Return values
array<string|int, mixed>Filter counts (filter => count).

get_local_woo_plugins()

Obtain a list of data about locally installed Woo extensions.

public static get_local_woo_plugins() : mixed
Return values
mixed

get_subscriptions()

Get the connected user's subscriptions.

public static get_subscriptions() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_view_filename()

Get an absolute path to the requested helper view.

public static get_view_filename(string $view) : string
Parameters
$view : string

The requested view file.

Return values
stringThe absolute path to the view file.

has_product_subscription()

Checks whether current site has product subscription of a given ID.

public static has_product_subscription(int $product_id) : bool
Parameters
$product_id : int

The product id.

Tags
since
3.7.0
Return values
boolReturns true if product subscription exists, false otherwise.

log()

Log a helper event.

public static log(string $message[, string $level = 'info' ]) : mixed
Parameters
$message : string

Log message.

$level : string = 'info'

Optional, defaults to info, valid levels: emergency|alert|critical|error|warning|notice|info|debug.

Return values
mixed

update_auth_option()

Updates auth options and flushes cache

public static update_auth_option(string $access_token, string $access_token_secret, int $site_id) : void
Parameters
$access_token : string

The access token.

$access_token_secret : string

The secret access token.

$site_id : int

The site id returned by the API.

Return values
void

_filter()

Filter an array of subscriptions by $filter.

private static _filter(array<string|int, mixed> &$subscriptions, string $filter) : mixed
Parameters
$subscriptions : array<string|int, mixed>

The subscriptions array, passed by ref.

$filter : string

The filter.

Return values
mixed

_get_extensions_update_notice()

Get an update notice if one or more Woo extensions has an update available.

private static _get_extensions_update_notice() : string|null
Return values
string|nullThe update notice or null if everything is up to date.

_get_local_from_product_id()

Get a local plugin/theme entry from product_id.

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

The product id.

Return values
array<string|int, mixed>|boolThe array containing the local plugin/theme data or false.

_get_return_notices()

Various success/error notices.

private static _get_return_notices() : array<string|int, mixed>

Runs during admin page render, so no headers/redirects here.

Return values
array<string|int, mixed>Array pairs of message/type strings with notices.

_get_subscriptions_from_product_id()

Get a subscription entry from product_id. If multiple subscriptions are found with the same product id and $single is set to true, will return the first one in the list, so you can use this method to get things like extension name, version, etc.

private static _get_subscriptions_from_product_id(int $product_id[, bool $single = true ]) : array<string|int, mixed>|bool
Parameters
$product_id : int

The product id.

$single : bool = true

Whether to return a single subscription or all matching a product id.

Return values
array<string|int, mixed>|boolThe array containing sub data or false.

_woo_core_update_available()

Whether WooCommerce has an update available.

private static _woo_core_update_available() : bool
Return values
boolTrue if a Woo core update is available.