WooCommerce Code Reference

WC_Tracker
in package

WooCommerce Tracker Class

Table of Contents

MAX_CONSECUTIVE_SEND_FAILURES  = 3
Consecutive failed attempts after which the current snapshot is abandoned.
$api_url  : string
URL to the WooThemes Tracker API endpoint.
get_address_autocomplete_info()  : array<string|int, mixed>
Get address autocomplete info.
get_all_plugins()  : array<string|int, mixed>
Get all plugins grouped into activated or not.
get_all_template_overrides()  : array<string|int, mixed>
Look for any template override and return filenames.
get_block_tracker_data()  : array<string|int, mixed>
Get tracker data for a specific block type on a woocommerce page.
get_cart_checkout_info()  : array<string|int, mixed>
Get info about the cart & checkout pages.
get_checkout_additional_fields_data()  : array<string|int, mixed>
Get tracker data for additional fields on the checkout page.
get_core_email_overrides()  : array<string|int, mixed>
Check if any core emails are being overridden by a template override.
get_pickup_location_data()  : array<string|int, mixed>
Get tracker data for a pickup location method.
get_product_counts()  : array<string|int, mixed>
Get product totals based on product type.
get_theme_info()  : array<string|int, mixed>
Get the current theme info, theme name and version.
get_tracking_data()  : array<string|int, mixed>
Get all the tracking data.
get_woocommerce_mobile_usage()  : array<string|int, mixed>
Get info about WooCommerce Mobile App usage
init()  : mixed
Hook into cron event.
post_contains_text()  : string
Search a specific post for text content.
send_tracking_data()  : mixed
Decide whether to send tracking data or not.
extract_group_key()  : array<string|int, mixed>
Extract the group key for an associative array of objects which have unique ids in the key.
finish_snapshot()  : void
Close out the current tracking attempt, whether a snapshot was sent or the attempt was abandoned before one existed.
get_active_payment_gateways()  : array<string|int, mixed>
Get a list of all active payment gateways.
get_active_shipping_methods()  : array<string|int, mixed>
Get a list of all active shipping methods.
get_additional_order_data()  : array<string|int, mixed>
Fetch additional data for a specific set of orders.
get_all_woocommerce_options_values()  : array<string|int, mixed>
Get all options starting with woocommerce_ prefix.
get_brands_counts()  : int
Get the number of product brands.
get_category_counts()  : int
Get the number of product categories.
get_core_email_status_counts()  : array<string|int, mixed>
Get counts of enabled and disabled core emails.
get_email_improvements_info()  : array<string|int, mixed>
Get email improvements tracking data.
get_enabled_features()  : array<string|int, string>
Get an array of slugs for WC features that are enabled on the site.
get_helper_connected()  : string
Check to see if the helper is connected to WooCommerce.com
get_last_send_time()  : int|bool
Get the time the current tracking attempt was closed out.
get_migrator_data()  : array<string|int, mixed>
Get migrator CLI statistics.
get_mini_cart_info()  : array<string|int, mixed>
Get info about the Mini Cart Block.
get_order_counts()  : array<string|int, mixed>
Get order counts.
get_order_data()  : array<string|int, mixed>
Fetch main order data.
get_order_dates()  : string
Get last order date.
get_order_snapshot()  : array<string|int, mixed>
Get a snapshot of the first 20 orders and the last 20 orders.
get_order_totals()  : array<string|int, mixed>
Get order totals.
get_orders()  : array<string|int, mixed>
Combine all order data.
get_orders_by_gateway()  : array<string|int, mixed>
Get order details by gateway.
get_orders_origins()  : array<string|int, mixed>
Get orders origin details.
get_refund_order_data()  : array<string|int, mixed>
Fetch refund data for a specific set of orders.
get_review_counts()  : array<string|int, mixed>
Get review counts for different statuses.
get_server_info()  : array<string|int, mixed>
Get server related info.
get_store_emails()  : array<string|int, mixed>
Get store email usage.
get_user_counts()  : array<string|int, mixed>
Get user totals based on user role.
get_wcpay_settings()  : array<string|int, mixed>
Get the settings of WooCommerce Payments plugin
get_wordpress_info()  : array<string|int, mixed>
Get WordPress related data.
is_jetpack_staging_site()  : bool
Test whether this site is a staging site according to the Jetpack criteria.
is_retryable_status()  : bool
Whether a delivery failure with the given status is worth retrying.
map_legacy_meta_key_name()  : string
Map legacy order meta keys to a column name.
record_send_failure()  : void
Record a failed delivery attempt.
record_send_result()  : void
Record the outcome of a delivery attempt.

Constants

MAX_CONSECUTIVE_SEND_FAILURES

Consecutive failed attempts after which the current snapshot is abandoned.

private int MAX_CONSECUTIVE_SEND_FAILURES = 3

Counts attempts rather than delivery failures, so a snapshot that cannot be built is bounded too. Retries happen on the daily tracker action, so this is a few days.

Properties

$api_url

URL to the WooThemes Tracker API endpoint.

private static string $api_url = 'https://tracking.woocommerce.com/v1/'

Methods

get_address_autocomplete_info()

Get address autocomplete info.

public static get_address_autocomplete_info() : array<string|int, mixed>
Return values
array<string|int, mixed> — Address autocomplete info.

get_all_plugins()

Get all plugins grouped into activated or not.

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

get_all_template_overrides()

Look for any template override and return filenames.

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

get_block_tracker_data()

Get tracker data for a specific block type on a woocommerce page.

public static get_block_tracker_data(string $block_name, string $woo_page_name) : array<string|int, mixed>
Parameters
$block_name : string

The name (id) of a block, e.g. woocommerce/cart.

$woo_page_name : string

The woo page to search, e.g. cart.

Return values
array<string|int, mixed> — Associative array of tracker data with keys: - page_contains_block - block_attributes

get_cart_checkout_info()

Get info about the cart & checkout pages.

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

get_checkout_additional_fields_data()

Get tracker data for additional fields on the checkout page.

public static get_checkout_additional_fields_data() : array<string|int, mixed>
Return values
array<string|int, mixed> — Array of fields count and names.

get_core_email_overrides()

Check if any core emails are being overridden by a template override.

public static get_core_email_overrides(array<string|int, mixed> $template_overrides) : array<string|int, mixed>
Parameters
$template_overrides : array<string|int, mixed>

Template overrides.

Return values
array<string|int, mixed> — Array with count of core email overrides and the templates that are overridden.

get_pickup_location_data()

Get tracker data for a pickup location method.

public static get_pickup_location_data() : array<string|int, mixed>
Return values
array<string|int, mixed> — Associative array of tracker data with keys: - pickup_location_enabled - pickup_locations_count

get_product_counts()

Get product totals based on product type.

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

get_theme_info()

Get the current theme info, theme name and version.

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

get_tracking_data()

Get all the tracking data.

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

get_woocommerce_mobile_usage()

Get info about WooCommerce Mobile App usage

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

post_contains_text()

Search a specific post for text content.

public static post_contains_text(int $post_id, string $text) : string
Parameters
$post_id : int

The id of the post to search.

$text : string

The text to search for.

Return values
string — 'Yes' if post contains $text (otherwise 'No').

send_tracking_data()

Decide whether to send tracking data or not.

public static send_tracking_data([bool $override = false ]) : mixed
Parameters
$override : bool = false

Should override?.

Return values
mixed —

extract_group_key()

Extract the group key for an associative array of objects which have unique ids in the key.

private static extract_group_key(array<string|int, mixed> $objects, string $default_key) : array<string|int, mixed>

A 'group_key' property is introduced in the object. For example, two objects with keys like 'WooDataPay ** #123' and 'WooDataPay ** #78' would both have a group_key of 'WooDataPay **' after this function call.

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

The array of objects that need to be grouped.

$default_key : string

The property that will be the default group_key.

Return values
array<string|int, mixed> — Contains the objects with a group_key property.

finish_snapshot()

Close out the current tracking attempt, whether a snapshot was sent or the attempt was abandoned before one existed.

private static finish_snapshot() : void

The scheduled gate reads only the send time, so advancing it is what puts the store back on the weekly interval and stops the daily retries.

Return values
void —

get_active_payment_gateways()

Get a list of all active payment gateways.

private static get_active_payment_gateways() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_active_shipping_methods()

Get a list of all active shipping methods.

private static get_active_shipping_methods() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_additional_order_data()

Fetch additional data for a specific set of orders.

private static get_additional_order_data(array<string|int, mixed> $order_ids) : array<string|int, mixed>
Parameters
$order_ids : array<string|int, mixed>

List of order ID's to fetch data for.

Return values
array<string|int, mixed> — Additional data, indexed by order ID.

get_all_woocommerce_options_values()

Get all options starting with woocommerce_ prefix.

private static get_all_woocommerce_options_values() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_brands_counts()

Get the number of product brands.

private static get_brands_counts() : int
Return values
int —

get_category_counts()

Get the number of product categories.

private static get_category_counts() : int
Return values
int —

get_core_email_status_counts()

Get counts of enabled and disabled core emails.

private static get_core_email_status_counts() : array<string|int, mixed>
Return values
array<string|int, mixed> — Array with counts of enabled and disabled emails.

get_email_improvements_info()

Get email improvements tracking data.

private static get_email_improvements_info(array<string|int, mixed> $template_overrides) : array<string|int, mixed>
Parameters
$template_overrides : array<string|int, mixed>

Template overrides.

Return values
array<string|int, mixed> — Email improvements tracking data.

get_enabled_features()

Get an array of slugs for WC features that are enabled on the site.

private static get_enabled_features() : array<string|int, string>
Return values
array<string|int, string> —

get_helper_connected()

Check to see if the helper is connected to WooCommerce.com

private static get_helper_connected() : string
Return values
string —

get_last_send_time()

Get the time the current tracking attempt was closed out.

private static get_last_send_time() : int|bool

Despite the option name, this is not only set on delivery: it also advances when an attempt is abandoned, including before a snapshot could be built. The scheduled gate reads it as "this cycle is done", not "a snapshot was sent".

Return values
int|bool —

get_migrator_data()

Get migrator CLI statistics.

private static get_migrator_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_mini_cart_info()

Get info about the Mini Cart Block.

private static get_mini_cart_info() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_order_counts()

Get order counts.

private static get_order_counts() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_order_data()

Fetch main order data.

private static get_order_data([string $sort_order = 'ASC' ][, int $limit = 20 ]) : array<string|int, mixed>
Parameters
$sort_order : string = 'ASC'

Date sort order (ASC or DESC).

$limit : int = 20

Limit the amount of orders to return (default 20).

Return values
array<string|int, mixed> — Found orders indexed by ID.

get_order_snapshot()

Get a snapshot of the first 20 orders and the last 20 orders.

private static get_order_snapshot() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_order_totals()

Get order totals.

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

Keeping the internal statuses names as strings to avoid regression issues (not referencing Automattic\WooCommerce\Enums\OrderInternalStatus class).

Tags
since
5.4.0
Return values
array<string|int, mixed> —

get_orders()

Combine all order data.

private static get_orders() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_orders_by_gateway()

Get order details by gateway.

private static get_orders_by_gateway() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_orders_origins()

Get orders origin details.

private static get_orders_origins() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_refund_order_data()

Fetch refund data for a specific set of orders.

private static get_refund_order_data(array<string|int, mixed> $order_ids) : array<string|int, mixed>
Parameters
$order_ids : array<string|int, mixed>

List of order ID's to fetch data for.

Return values
array<string|int, mixed> — Refund data, indexed by order ID.

get_review_counts()

Get review counts for different statuses.

private static get_review_counts() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_server_info()

Get server related info.

private static get_server_info() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_store_emails()

Get store email usage.

private static get_store_emails() : array<string|int, mixed>
Return values
array<string|int, mixed> — Email usage.

get_user_counts()

Get user totals based on user role.

private static get_user_counts() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_wcpay_settings()

Get the settings of WooCommerce Payments plugin

private static get_wcpay_settings() : array<string|int, mixed>
Return values
array<string|int, mixed> —

get_wordpress_info()

Get WordPress related data.

private static get_wordpress_info() : array<string|int, mixed>
Return values
array<string|int, mixed> —

is_jetpack_staging_site()

Test whether this site is a staging site according to the Jetpack criteria.

private static is_jetpack_staging_site() : bool

With Jetpack 8.1+, Jetpack::is_staging_site has been deprecated. \Automattic\Jetpack\Status::is_staging_site is the replacement. However, there are version of JP where \Automattic\Jetpack\Status exists, but does not contain is_staging_site method, so with those, code still needs to use the previous check as a fallback.

After upgrading Jetpack Status to v3.3.2 is_staging_site is also deprecated and in_safe_mode is the new replacement. So we check this first of all.

Return values
bool —

is_retryable_status()

Whether a delivery failure with the given status is worth retrying.

private static is_retryable_status(int $status) : bool

Transport failures (status 0), rate limiting, timeouts and server errors are retried; other client errors mean the snapshot itself was rejected.

Parameters
$status : int

HTTP status code, 0 for a transport failure.

Return values
bool —

map_legacy_meta_key_name()

Map legacy order meta keys to a column name.

private static map_legacy_meta_key_name(string $meta_key) : string
Parameters
$meta_key : string

Legacy meta key name.

Return values
string — Mapped column name.

record_send_failure()

Record a failed delivery attempt.

private static record_send_failure(bool $retryable, int $status, string $error_code, int $body_bytes) : void

The attempt was already counted before the snapshot was built, so this only decides whether to keep retrying: a non-retryable failure or the last allowed attempt gives up on the current snapshot. Retry state is discarded when tracking was turned off while the request was in flight.

Parameters
$retryable : bool

Whether the next scheduled run should try again.

$status : int

HTTP status code, 0 when no response was received.

$error_code : string

Error code when no response was received.

$body_bytes : int

Size of the snapshot.

Return values
void —

record_send_result()

Record the outcome of a delivery attempt.

private static record_send_result(array<string|int, mixed>|WP_Error $response, int $body_bytes) : void

The send time is recorded after acceptance or permanent abandonment. A transient failure remains pending for the next run.

Parameters
$response : array<string|int, mixed>|WP_Error

Response from wp_safe_remote_post().

$body_bytes : int

Size of the posted snapshot.

Return values
void —