Util

Utility functions for WooCommerce Product Table.

Tags
author

Barn2 Plugins [email protected]

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

$attribute_labels  : mixed
$tables_on_page  : mixed
$variation_attributes  : 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_image_size_width()  : mixed
get_layered_nav_params()  : mixed
get_parent()  : WC_Product
Gets the parent product for the given product, or false if there is no parent.
get_post()  : mixed
get_product_addons()  : mixed
get_product_name()  : mixed
get_shop_messages()  : mixed
get_tables_on_page()  : mixed
get_template_path()  : mixed
get_terms()  : mixed
get_variation_attributes()  : mixed
get_wc_asset_url()  : mixed
get_wrapper_class()  : mixed
is_european_date_format()  : mixed
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_class_name()  : mixed
sanitize_list_arg()  : mixed
sanitize_list_arg_allow_space()  : mixed
sanitize_numeric_list_arg()  : mixed
sanitize_string_or_array_arg()  : mixed
sanitize_string_or_bool_arg()  : mixed
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

Properties

$attribute_labels

private static mixed $attribute_labels = []

$tables_on_page

private static mixed $tables_on_page = null

$variation_attributes

private static mixed $variation_attributes = []

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.

public static format_loop_add_to_cart_link(mixed $link) : mixed
Parameters
$link : mixed
Return values
mixed
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

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_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
Parameters
$product : WC_Product

The product.

Return values
WC_Product

The parent product or false.

get_post()

public static get_post(mixed $product) : mixed
Parameters
$product : mixed
Return values
mixed

get_product_addons()

public static get_product_addons(mixed $product_id) : mixed
Parameters
$product_id : mixed
Return values
mixed

get_product_name()

public static get_product_name(mixed $product) : mixed
Parameters
$product : mixed
Return values
mixed

get_shop_messages()

public static get_shop_messages() : mixed
Return values
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_variation_attributes()

public static get_variation_attributes(mixed $product) : mixed
Parameters
$product : 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_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 $jQueryFormat) : string

See http://api.jqueryui.com/datepicker/ for jQuery formats.

Parameters
$jQueryFormat : 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 $maybe_bool) : mixed
Parameters
$maybe_bool : mixed
Return values
mixed

sanitize_class_name()

public static sanitize_class_name(mixed $class) : mixed
Parameters
$class : mixed
Return values
mixed

sanitize_list_arg()

public static sanitize_list_arg(mixed $arg[, mixed $allow_space = false ]) : mixed
Parameters
$arg : mixed
$allow_space : mixed = false
Return values
mixed

sanitize_list_arg_allow_space()

public static sanitize_list_arg_allow_space(mixed $arg) : mixed
Parameters
$arg : mixed
Return values
mixed

sanitize_numeric_list_arg()

public static sanitize_numeric_list_arg(mixed $arg) : mixed
Parameters
$arg : mixed
Return values
mixed

sanitize_string_or_array_arg()

public static sanitize_string_or_array_arg(mixed $arg) : mixed
Parameters
$arg : mixed
Return values
mixed

sanitize_string_or_bool_arg()

public static sanitize_string_or_bool_arg(mixed $arg) : mixed
Parameters
$arg : mixed
Return values
mixed

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

Search results