Util
Utility functions for WooCommerce Product Table.
Tags
Table of Contents
- $attribute_labels : mixed
- $tables_on_page : mixed
- array_diff_assoc() : array<string|int, mixed>
- Similar to <code>array_diff_assoc</code>, but does a loose type comparison on array values (== not ===).
- array_filter_layered_nav_params() : mixed
- array_pad_and_slice() : array<string|int, mixed>
- Combination of array_pad and array_slice.
- convert_to_term_ids() : mixed
- doing_lazy_load() : mixed
- empty_if_false() : mixed
- extract_attributes() : array<string|int, mixed>
- Pull the attributes from the specified array, which may contain a mix of different data.
- format_loop_add_to_cart_link() : mixed
- format_product_link() : mixed
- get_acf_field_object() : mixed
- get_all_term_children() : mixed
- get_asset_url() : mixed
- get_attribute_label() : mixed
- get_attribute_name() : mixed
- get_available_variations() : array<string|int, mixed>
- Similar to WC_Product_Variable->get_available_variations() but returns an array of WC_Product_Variation objects rather than arrays.
- get_button_class() : mixed
- get_content_table() : mixed
- get_custom_product_taxonomies() : mixed
- get_image_size_width() : mixed
- get_layered_nav_params() : mixed
- get_parent() : WC_Product|false
- Gets the parent product for the given product, or false if there is no parent.
- get_post() : WP_Post|null
- Get the WP_Post object from a WC_Product.
- get_product_name() : string
- Get the name for a product.
- get_shop_messages() : mixed
- get_shop_templates_tables() : array<string|int, mixed>
- Gets all the tables ids or titles set in the table builder.
- get_tables_on_page() : mixed
- get_template_path() : mixed
- get_terms() : mixed
- get_wc_asset_url() : mixed
- get_wrapper_class() : mixed
- is_european_date_format() : mixed
- is_purchasable_from_table() : bool
- Is the product purchasable from the product table?
- is_table_on_page() : mixed
- is_unix_epoch_time() : bool
- Is the value passed a valid UNIX epoch time (i.e. seconds elapsed since 1st January 1970)?
- is_valid_search_term() : mixed
- jquery_to_php_date_format() : string
- Convert a jQuery date format to a PHP one. E.g. 'dd-mm-yy' becomes 'd-m-Y'.
- list_pluck_array() : array<string|int, mixed>
- Similar to <code>wp_list_pluck</code> or <code>array_column</code> but plucks several keys from the source array.
- maybe_get_parent() : WC_Product
- Return the parent for the given product, if there is one, otherwise it returns the original product.
- maybe_parse_bool() : mixed
- sanitize_enum() : mixed
- sanitize_enum_or_bool() : mixed
- sanitize_image_size() : mixed
- sanitize_list() : mixed
- sanitize_list_and_space() : mixed
- sanitize_list_or_bool() : mixed
- sanitize_numeric_list() : mixed
- sanitize_search_term() : string
- Sanitize a search term.
- set_object_vars() : mixed
- string_list_to_array() : mixed
- strtotime() : int|bool
- Convert a date string to a timestamp. A wrapper around strtotime which accounts for dates already formatted as a timestamp.
- get_table_shortcodes_in_post_content() : mixed
- get_variation_attribute_labels() : mixed
Properties
$attribute_labels
private
static mixed
$attribute_labels
= []
$tables_on_page
private
static mixed
$tables_on_page
= null
Methods
array_diff_assoc()
Similar to <code>array_diff_assoc</code>, but does a loose type comparison on array values (== not ===).
public
static array_diff_assoc(array<string|int, mixed> $array1, array<string|int, mixed> $array2) : array<string|int, mixed>
Supports multi-dimensional arrays, but doesn't support passing more than two arrays.
Parameters
- $array1 : array<string|int, mixed>
-
The main array to compare against
- $array2 : array<string|int, mixed>
-
The array to compare with
Return values
array<string|int, mixed> —All entries in $array1 which are not present in $array2 (including key check)
array_filter_layered_nav_params()
public
static array_filter_layered_nav_params(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —array_pad_and_slice()
Combination of array_pad and array_slice.
public
static array_pad_and_slice(array<string|int, mixed> $array, int $size, mixed $pad) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
-
Input array
- $size : int
-
The size of the array to return
- $pad : mixed
-
What to pad with
Return values
array<string|int, mixed> —The result
convert_to_term_ids()
public
static convert_to_term_ids(mixed $terms, mixed $taxonomy) : mixed
Parameters
- $terms : mixed
- $taxonomy : mixed
Return values
mixed —doing_lazy_load()
public
static doing_lazy_load() : mixed
Return values
mixed —empty_if_false()
public
static empty_if_false(mixed $var) : mixed
Parameters
- $var : mixed
Return values
mixed —extract_attributes()
Pull the attributes from the specified array, which may contain a mix of different data.
public
static extract_attributes(array<string|int, mixed> $array) : array<string|int, mixed>
E.g. extract_attributes( array( 'name' => 'product1', 'id' => '123' 'attribute_pa_size' => 'medium', 'attribute_pa_color' => 'red' ) );
would return an array with the two attributes - attribute_pa_size and attribute_pa_color.
Parameters
- $array : array<string|int, mixed>
-
The array to extract from
Return values
array<string|int, mixed> —Just the attributes, or an empty array if there are none.
format_loop_add_to_cart_link()
public
static format_loop_add_to_cart_link(mixed $link) : mixed
Parameters
- $link : mixed
Return values
mixed —format_product_link()
public
static format_product_link(mixed $product[, mixed $link_text = '' ][, mixed $link_class = [] ]) : mixed
Parameters
- $product : mixed
- $link_text : mixed = ''
- $link_class : mixed = []
Return values
mixed —get_acf_field_object()
public
static get_acf_field_object(mixed $field[, mixed $post_id = false ]) : mixed
Parameters
- $field : mixed
- $post_id : mixed = false
Return values
mixed —get_all_term_children()
public
static get_all_term_children(mixed $term_ids, mixed $taxonomy[, mixed $include_parents = false ]) : mixed
Parameters
- $term_ids : mixed
- $taxonomy : mixed
- $include_parents : mixed = false
Return values
mixed —get_asset_url()
public
static get_asset_url([mixed $path = '' ]) : mixed
Parameters
- $path : mixed = ''
Return values
mixed —get_attribute_label()
public
static get_attribute_label(mixed $name[, mixed $product = '' ]) : mixed
Parameters
- $name : mixed
- $product : mixed = ''
Return values
mixed —get_attribute_name()
public
static get_attribute_name(mixed $attribute_name) : mixed
Parameters
- $attribute_name : mixed
Return values
mixed —get_available_variations()
Similar to WC_Product_Variable->get_available_variations() but returns an array of WC_Product_Variation objects rather than arrays.
public
static get_available_variations(WC_Product_Variable $product) : array<string|int, mixed>
Parameters
- $product : WC_Product_Variable
-
The product to get variations for
Tags
Return values
array<string|int, mixed> —An array of WC_Product_Variation objects
get_button_class()
public
static get_button_class() : mixed
Return values
mixed —get_content_table()
public
static get_content_table(mixed $table_id[, mixed $database_prefix = 'wpt' ]) : mixed
Parameters
- $table_id : mixed
- $database_prefix : mixed = 'wpt'
Return values
mixed —get_custom_product_taxonomies()
public
static get_custom_product_taxonomies([mixed $keysufix = '' ]) : mixed
Parameters
- $keysufix : mixed = ''
Return values
mixed —get_image_size_width()
public
static get_image_size_width(mixed $size) : mixed
Parameters
- $size : mixed
Return values
mixed —get_layered_nav_params()
public
static get_layered_nav_params([mixed $lazy_load = false ]) : mixed
Parameters
- $lazy_load : mixed = false
Return values
mixed —get_parent()
Gets the parent product for the given product, or false if there is no parent.
public
static get_parent(WC_Product $product) : WC_Product|false
Parameters
- $product : WC_Product
-
The product.
Return values
WC_Product|false —The parent product or false.
get_post()
Get the WP_Post object from a WC_Product.
public
static get_post(WC_Product $product) : WP_Post|null
Parameters
- $product : WC_Product
-
The product object.
Return values
WP_Post|null —The post object or null of not found.
get_product_name()
Get the name for a product.
public
static get_product_name(WC_Product|null $product[, string $variation_format = 'full' ]) : string
For all products other than WC_Product_Variation, it returns the result of $product->get_name(). For variation products, it will return the name in the format specified in $variation_format.
Parameters
- $product : WC_Product|null
-
The product object.
- $variation_format : string = 'full'
-
The format to use if the product is a variation - full, parent, or attributes.
Return values
string —The product name
get_shop_messages()
public
static get_shop_messages() : mixed
Return values
mixed —get_shop_templates_tables()
Gets all the tables ids or titles set in the table builder.
public
static get_shop_templates_tables([string $database_prefix = 'wpt' ]) : array<string|int, mixed>
Parameters
- $database_prefix : string = 'wpt'
Return values
array<string|int, mixed> —get_tables_on_page()
public
static get_tables_on_page() : mixed
Return values
mixed —get_template_path()
public
static get_template_path() : mixed
Return values
mixed —get_terms()
public
static get_terms([mixed $args = [] ]) : mixed
Parameters
- $args : mixed = []
Return values
mixed —get_wc_asset_url()
public
static get_wc_asset_url([mixed $path = '' ]) : mixed
Parameters
- $path : mixed = ''
Return values
mixed —get_wrapper_class()
public
static get_wrapper_class() : mixed
Return values
mixed —is_european_date_format()
public
static is_european_date_format(mixed $format) : mixed
Parameters
- $format : mixed
Return values
mixed —is_purchasable_from_table()
Is the product purchasable from the product table?
public
static is_purchasable_from_table(WC_Product $product, string $variation_display) : bool
Parameters
- $product : WC_Product
-
The product object.
- $variation_display : string
-
The method for displaying variations - dropdown, separate or false.
Return values
bool —true if purchasable.
is_table_on_page()
public
static is_table_on_page() : mixed
Return values
mixed —is_unix_epoch_time()
Is the value passed a valid UNIX epoch time (i.e. seconds elapsed since 1st January 1970)?
public
static is_unix_epoch_time(mixed $value) : bool
Not a perfect implementation as it will return false for valid timestamps representing dates between 31st October 1966 and 3rd March 1973, but this is needed to prevent valid dates held in numeric formats (e.g. 20171201) being wrongly interpreted as timestamps.
Parameters
- $value : mixed
-
The value to check
Return values
bool —True if $value is a valid epoch timestamp
is_valid_search_term()
public
static is_valid_search_term(mixed $search_term) : mixed
Parameters
- $search_term : mixed
Return values
mixed —jquery_to_php_date_format()
Convert a jQuery date format to a PHP one. E.g. 'dd-mm-yy' becomes 'd-m-Y'.
public
static jquery_to_php_date_format(string $jquery_format) : string
See http://api.jqueryui.com/datepicker/ for jQuery formats.
Parameters
- $jquery_format : string
-
The jQuery date format
Return values
string —The equivalent PHP date format
list_pluck_array()
Similar to <code>wp_list_pluck</code> or <code>array_column</code> but plucks several keys from the source array.
public
static list_pluck_array(array<string|int, mixed> $list[, array<string|int, mixed>|string $keys = [] ]) : array<string|int, mixed>
Parameters
- $list : array<string|int, mixed>
-
The array of arrays to extract the keys from
- $keys : array<string|int, mixed>|string = []
-
The list of keys to pluck
Return values
array<string|int, mixed> —An array returned in the same order as $list, but where each item in the array contains just the specified $keys
maybe_get_parent()
Return the parent for the given product, if there is one, otherwise it returns the original product.
public
static maybe_get_parent(WC_Product $product) : WC_Product
Parameters
- $product : WC_Product
-
The product.
Return values
WC_Product —Either the parent product or the original product.
maybe_parse_bool()
public
static maybe_parse_bool(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —sanitize_enum()
public
static sanitize_enum(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —sanitize_enum_or_bool()
public
static sanitize_enum_or_bool(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —sanitize_image_size()
public
static sanitize_image_size(mixed $image_size) : mixed
Parameters
- $image_size : mixed
Return values
mixed —sanitize_list()
public
static sanitize_list(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —sanitize_list_and_space()
public
static sanitize_list_and_space(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —sanitize_list_or_bool()
public
static sanitize_list_or_bool(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —sanitize_numeric_list()
public
static sanitize_numeric_list(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —sanitize_search_term()
Sanitize a search term.
public
static sanitize_search_term(string $search_term) : string
Parameters
- $search_term : string
-
The search term.
Return values
string —The sanitized search term.
set_object_vars()
public
static set_object_vars(mixed $object, mixed $vars) : mixed
Parameters
- $object : mixed
- $vars : mixed
Return values
mixed —string_list_to_array()
public
static string_list_to_array(mixed $arg) : mixed
Parameters
- $arg : mixed
Return values
mixed —strtotime()
Convert a date string to a timestamp. A wrapper around strtotime which accounts for dates already formatted as a timestamp.
public
static strtotime(string $date) : int|bool
Parameters
- $date : string
-
The date to convert to a timestamp.
Return values
int|bool —The timestamp (number of seconds since the Epoch) for this date, or false on failure.
get_table_shortcodes_in_post_content()
private
static get_table_shortcodes_in_post_content() : mixed
Return values
mixed —get_variation_attribute_labels()
private
static get_variation_attribute_labels(WC_Product_Variation $product) : mixed
Parameters
- $product : WC_Product_Variation