WC_Admin_Addons
in package
WC_Admin_Addons Class.
Table of Contents
- add_in_app_purchase_url_params() : mixed
- Add in-app-purchase URL params to link.
- build_parameter_string() : string
- Build url parameter string
- filter_admin_body_classes() : string
- We're displaying page=wc-addons and page=wc-addons§ion=helper as two separate pages.
- format_promotions() : array<string|int, mixed>
- Format the promotion data ready for display, ie fetch locales and actions.
- get_action_url() : string
- Take an action object and return the URL based on properties of the action.
- get_extension_data() : object|WP_Error
- Call API to get extensions
- get_featured() : array<string|int, mixed>
- Get featured for the addons screen
- get_in_app_purchase_url_params() : mixed
- Returns in-app-purchase URL params.
- get_section() : object|bool
- Get section for the addons screen.
- get_section_data() : array<string|int, mixed>
- Get section content for the addons screen.
- get_sections() : array<string|int, mixed>
- Get sections for the addons screen
- get_star_class() : string
- Determine which class should be used for a rating star: - golden - half-filled (50/50 golden and gray) - gray
- install_woocommerce_payments_addon() : void
- Install WooCommerce Payments from the Extensions screens.
- install_woocommerce_services_addon() : mixed
- Install WooCommerce Services from Extensions screens.
- is_ssl_error() : bool
- Check if the error is due to an SSL error
- map_product_card_data() : object
- Map data from different endpoints to a universal format
- output() : mixed
- Handles output of the addons page in admin.
- output_banner_block() : mixed
- Handles the outputting of a banner block.
- output_button() : mixed
- Outputs a button.
- output_column() : mixed
- Handles the outputting of a column.
- output_column_block() : mixed
- Handles the outputting of a column block.
- output_empty() : void
- Output HTML for a promotion action if data couldn't be fetched.
- output_featured_sections() : mixed
- Handles the outputting of featured sections
- output_promotion_action() : void
- Output HTML for a promotion action.
- output_promotion_block() : mixed
- Handles the output of a full-width block.
- output_search_promotion_block() : void
- Output the HTML for the promotion block.
- output_small_dark_block() : mixed
- Handles the outputting of a small dark block.
- output_small_light_block() : mixed
- Handles the outputting of a small light block.
- output_storefront_button() : mixed
- Handles the outputting of a contextually aware Storefront link (points to child themes if Storefront is already active).
- output_wcpay_banner_block() : mixed
- Handles the outputting of the WooCommerce Pay banner block.
- output_wcs_banner_block() : mixed
- Handles the outputting of the WooCommerce Services banner block.
- render_featured() : void
- Render featured products and banners using WCCOM's the Featured 2.0 Endpoint
- render_product_card() : void
- Render a product card
- get_locale_data_from_transient() : mixed
- Retrieves the locale data from a transient.
- output_banner() : void
- Render a banner contains a product
- output_featured() : mixed
- Handles the outputting of featured page
- output_group() : void
- Render a group block including products
- set_locale_data_in_transient() : bool
- Sets the locale data in a transient.
Methods
add_in_app_purchase_url_params()
Add in-app-purchase URL params to link.
public
static add_in_app_purchase_url_params(string $url) : mixed
Adds various url parameters to a url to support a streamlined flow for obtaining and setting up WooCommerce extensons.
Parameters
- $url : string
-
Destination URL.
Return values
mixed —build_parameter_string()
Build url parameter string
public
static build_parameter_string(string $category, string $term, string $country) : string
Parameters
- $category : string
-
Addon (sub) category.
- $term : string
-
Search terms.
- $country : string
-
Store country.
Return values
string — url parameter stringfilter_admin_body_classes()
We're displaying page=wc-addons and page=wc-addons§ion=helper as two separate pages.
public
static filter_admin_body_classes([string $admin_body_class = '' ]) : string
When we're on those pages, add body classes to distinguishe them.
Parameters
- $admin_body_class : string = ''
-
Unfiltered body class.
Return values
string — Body class with added class for Marketplace or My Subscriptions page.format_promotions()
Format the promotion data ready for display, ie fetch locales and actions.
public
static format_promotions(array<string|int, mixed> $promotions) : array<string|int, mixed>
Parameters
- $promotions : array<string|int, mixed>
-
Array of promotoin objects.
Return values
array<string|int, mixed> — Array of formatted promotions ready for output.get_action_url()
Take an action object and return the URL based on properties of the action.
public
static get_action_url(object $action) : string
Parameters
- $action : object
-
Action object.
Return values
string — URL.get_extension_data()
Call API to get extensions
public
static get_extension_data(string $category, string $term, string $country) : object|WP_Error
Parameters
- $category : string
-
Addon (sub) category.
- $term : string
-
Search terms.
- $country : string
-
Store country.
Return values
object|WP_Error — Object with products and promotions properties, or WP_Errorget_featured()
Get featured for the addons screen
public
static get_featured() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — of objectsget_in_app_purchase_url_params()
Returns in-app-purchase URL params.
public
static get_in_app_purchase_url_params() : mixed
Return values
mixed —get_section()
Get section for the addons screen.
public
static get_section(string $section_id) : object|bool
Parameters
- $section_id : string
-
Required section ID.
Return values
object|bool —get_section_data()
Get section content for the addons screen.
public
static get_section_data(string $section_id) : array<string|int, mixed>
Parameters
- $section_id : string
-
Required section ID.
Tags
Return values
array<string|int, mixed> —get_sections()
Get sections for the addons screen
public
static get_sections() : array<string|int, mixed>
Return values
array<string|int, mixed> — of objectsget_star_class()
Determine which class should be used for a rating star: - golden - half-filled (50/50 golden and gray) - gray
public
static get_star_class(float $rating, int $index) : string
Consider ratings from 3.0 to 4.0 as an example 3.0 will produce 3 stars 3.1 to 3.5 will produce 3 stars and a half star 3.6 to 4.0 will product 4 stars
Parameters
- $rating : float
-
Rating of a product.
- $index : int
-
Index of a star in a row.
Return values
string — CSS class to use.install_woocommerce_payments_addon()
Install WooCommerce Payments from the Extensions screens.
public
static install_woocommerce_payments_addon([string $section = '_featured' ]) : void
Parameters
- $section : string = '_featured'
-
Optional. Extensions tab.
Return values
void —install_woocommerce_services_addon()
Install WooCommerce Services from Extensions screens.
public
static install_woocommerce_services_addon() : mixed
Return values
mixed —is_ssl_error()
Check if the error is due to an SSL error
public
static is_ssl_error(string $error_message) : bool
Parameters
- $error_message : string
-
Error message.
Return values
bool — True if SSL error, false otherwisemap_product_card_data()
Map data from different endpoints to a universal format
public
static map_product_card_data(mixed $data) : object
Search and featured products has a slightly different products' field names. Mapping converts different data structures into a universal one for further processing.
Parameters
- $data : mixed
-
Product Card Data.
Return values
object — Converted data.output()
Handles output of the addons page in admin.
public
static output() : mixed
Return values
mixed —output_banner_block()
Handles the outputting of a banner block.
public
static output_banner_block(object $block) : mixed
Parameters
- $block : object
-
Banner data.
Tags
Return values
mixed —output_button()
Outputs a button.
public
static output_button(string $url, string $text, string $style[, string $plugin = '' ]) : mixed
Parameters
- $url : string
-
Destination URL.
- $text : string
-
Button label text.
- $style : string
-
Button style class.
- $plugin : string = ''
-
The plugin the button is promoting.
Return values
mixed —output_column()
Handles the outputting of a column.
public
static output_column(object $block) : mixed
Parameters
- $block : object
-
Column data.
Tags
Return values
mixed —output_column_block()
Handles the outputting of a column block.
public
static output_column_block(object $block) : mixed
Parameters
- $block : object
-
Column block data.
Tags
Return values
mixed —output_empty()
Output HTML for a promotion action if data couldn't be fetched.
public
static output_empty([string $message = '' ]) : void
Parameters
- $message : string = ''
-
Error message.
Return values
void —output_featured_sections()
Handles the outputting of featured sections
public
static output_featured_sections(array<string|int, mixed> $sections) : mixed
Parameters
- $sections : array<string|int, mixed>
-
Section data.
Return values
mixed —output_promotion_action()
Output HTML for a promotion action.
public
static output_promotion_action(array<string|int, mixed> $action) : void
Parameters
- $action : array<string|int, mixed>
-
Array of action properties.
Return values
void —output_promotion_block()
Handles the output of a full-width block.
public
static output_promotion_block(array<string|int, mixed> $section) : mixed
Parameters
- $section : array<string|int, mixed>
-
Section data.
Tags
Return values
mixed —output_search_promotion_block()
Output the HTML for the promotion block.
public
static output_search_promotion_block(array<string|int, mixed> $promotion) : void
Parameters
- $promotion : array<string|int, mixed>
-
Array of promotion block data.
Return values
void —output_small_dark_block()
Handles the outputting of a small dark block.
public
static output_small_dark_block(object $block) : mixed
Parameters
- $block : object
-
Block data.
Tags
Return values
mixed —output_small_light_block()
Handles the outputting of a small light block.
public
static output_small_light_block(object $block) : mixed
Parameters
- $block : object
-
Block data.
Tags
Return values
mixed —output_storefront_button()
Handles the outputting of a contextually aware Storefront link (points to child themes if Storefront is already active).
public
static output_storefront_button() : mixed
Tags
Return values
mixed —output_wcpay_banner_block()
Handles the outputting of the WooCommerce Pay banner block.
public
static output_wcpay_banner_block([object $block = array() ]) : mixed
Parameters
- $block : object = array()
-
Block data.
Tags
Return values
mixed —output_wcs_banner_block()
Handles the outputting of the WooCommerce Services banner block.
public
static output_wcs_banner_block([object $block = array() ]) : mixed
Parameters
- $block : object = array()
-
Block data.
Tags
Return values
mixed —render_featured()
Render featured products and banners using WCCOM's the Featured 2.0 Endpoint
public
static render_featured() : void
Return values
void —render_product_card()
Render a product card
public
static render_product_card(mixed $data[, string $block_type = null ]) : void
There's difference in data structure (e.g. field names) between endpoints such as search and featured. Inner mapping helps to use universal field names for further work.
Parameters
- $data : mixed
-
Product data.
- $block_type : string = null
-
Block type that's different from the default product card, e.g. a banner.
Return values
void —get_locale_data_from_transient()
Retrieves the locale data from a transient.
private
static get_locale_data_from_transient(string $transient, string $locale) : mixed
Transient value is an array of locale data in the following format: array( 'en_US' => ..., 'fr_FR' => ..., )
If the transient does not exist, does not have a value, or has expired, then the return value will be false.
Parameters
- $transient : string
-
Transient name. Expected to not be SQL-escaped.
- $locale : string
-
Locale to retrieve.
Return values
mixed — Value of transient.output_banner()
Render a banner contains a product
private
static output_banner(mixed $block) : void
Parameters
- $block : mixed
-
Block of the page for rendering.
Return values
void —output_featured()
Handles the outputting of featured page
private
static output_featured(array<string|int, mixed> $blocks) : mixed
Parameters
- $blocks : array<string|int, mixed>
-
Featured page's blocks.
Return values
mixed —output_group()
Render a group block including products
private
static output_group(mixed $block) : void
Parameters
- $block : mixed
-
Block of the page for rendering.
Return values
void —set_locale_data_in_transient()
Sets the locale data in a transient.
private
static set_locale_data_in_transient(string $transient, mixed $value, string $locale, int $expiration) : bool
Transient value is an array of locale data in the following format: array( 'en_US' => ..., 'fr_FR' => ..., )
Parameters
- $transient : string
-
Transient name. Expected to not be SQL-escaped. Must be 172 characters or fewer in length.
- $value : mixed
-
Transient value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
- $locale : string
-
Locale to set.
- $expiration : int
-
Optional. Time until expiration in seconds. Default 0 (no expiration).