Products extends Abstract_Field

Abstract field class.

Tags

Table of Contents

$button_width  : mixed
$choice_char  : array<string|int, mixed>
The choice character setting.
$choice_qty  : array<string|int, mixed>
The choice quantity setting.
$display_label  : mixed
$dynamic_products  : mixed
$equal_pricing  : bool
Whether all choices have equal pricing.
$has_conditional_logic  : bool
Whether the field has conditional logic.
$has_user_value  : bool
Whether the field has a user-defined value.
$is_display_field  : bool
Whether the field is for display only.
$label_position  : mixed
$manual_products  : mixed
$option  : mixed
$product  : mixed
$product_display_style  : mixed
$product_selection  : mixed
$show_in_product_gallery  : mixed
$stores_multiple_values  : bool
Whether the field can store multiple value selections (e.g checkboxes).
$supports_multiple_values  : bool
Whether the field supports multiple values (e.g checkboxes, radios, select).
$type  : mixed
$used_settings  : array<string|int, mixed>
An array of settings being used by the field.
$default_width  : mixed
$products  : mixed
__construct()  : mixed
Constructor.
__set()  : void
The set magic method.
add_button_width_css_variable()  : void
Add a style element with the CSS variable for the button width right after the field.
get_cart_item_data()  : array<string|int, mixed>
Retrieves the cart item data for the selected value(s) of the field.
get_choice_formula_value()  : string
Get the formula value associated with a choice of the field.
get_conditional_logic_config()  : object|null
Get the field conditional logic config.
get_id()  : string
Get the field id.
get_manually_selected_product_variations()  : array<string|int, mixed>
Get product variations that were manually selected in the backend options
get_product()  : WC_Product
Get the product for the field.
get_product_order_arg_value()  : string
Get product orderby arg value
get_product_orderby_arg_value()  : string
Get product orderby arg value
get_product_type_args()  : array<string|int, mixed>
Build product query args for product option type
get_setting()  : string|array<string|int, mixed>|null
Get the value of a specific field setting.
get_settings()  : array<string|int, mixed>|null
Get the array with the field settings.
get_type()  : string
Get the field type.
get_variable_product_style_checkbox()  : string
Return the variation products as checkboxes and allow them to add to cart from the product page
get_variable_product_style_image()  : string
Return the variation products as image buttons and allow them to add to cart from the product page
get_variable_product_style_product()  : string
Display variations as indidivual products and allow them to directly add to cart
get_variable_product_style_radio()  : string
Return the variation products as radio buttons and allow them to add to cart from the product page
has_conditional_logic()  : bool
Whether the field has conditional logic.
has_user_value()  : bool
Whether the field has a user inputted value.
is_required()  : bool
Whether the field is required.
render()  : void
Render the HTML for the field.
sanitize()  : mixed
Sanitize the field input value.
stores_multiple_values()  : bool
Whether the field stores multiple values.
validate()  : bool|WP_Error
Validate the product options and add to cart
get_attachment_image_sizes()  : string
Get the `sizes` attribute for the image element.
get_choice_for_value()  : array<string|int, mixed>|null
Retrieves the choice from the option DB based on the user value provided.
get_choice_image()  : string
get_choice_image_html()  : string
Get the choice image HTML markup
get_choice_pricing_attributes()  : string
Gets the data attributes to handle JS pricing calculation.
get_choice_pricing_string()  : string
Retrieves the pricing string for a choice
get_field_attributes()  : string
Gets the data attributes to handle conditional logic visibilities.
get_field_class()  : string
Gets the CSS class for the field.
get_image_data()  : string
Return the `data-image` attribute of the image button.
get_image_srcset()  : string
Get the srcset attribute for the image.
get_input_id()  : string
Gets the id attribute for the field input.
get_input_name()  : string
Gets the name attribute for the field input.
get_label()  : string
Get the label for the field or its choices.
get_pricing_attributes()  : array<string|int, mixed>
Retrieves top level pricing attributes for the field.
get_required_symbol()  : mixed
has_choice_images()  : bool
has_display_prerequisites()  : bool
Determines whether the option has enough data to display.
is_update_main_image_enable()  : bool
Whether the option has the "Update main image" setting enabled.
render_checkboxes_style_html()  : mixed
Render products in checkbox styles
render_choice_character_limits_label()  : void
Gets the label for choice character limits if applicable.
render_choice_quantity_limits_label()  : void
Gets the label for choice quantity limits if applicable.
render_description()  : void
Render the HTML for the field description.
render_dropdowns_style_html()  : mixed
Render products in dropdown styles
render_field_wrap_close()  : void
Renders the field wrap closing tag.
render_field_wrap_open()  : void
Renders the field wrap.
render_image_buttons_style_html()  : mixed
Render products in image buttons styles
render_option_name()  : void
Render the HTML for the field label.
render_product_style_html()  : mixed
Render the HTML for the product style.
render_products_html_based_on_style()  : mixed
Render the HTML for products based on the style.
render_radios_style_html()  : mixed
Render products in radio styles
get_button_width()  : string
Get the width of the image buttons.
get_deselect_svg()  : string
SVG for deselecting an image button.
get_edit_option_link()  : mixed
get_figcaption()  : mixed
get_image_wrap_class()  : string
Get the class for the image wrap.
init_conditional_logic()  : mixed
Determine whether the field has conditional logic.
is_update_main_image_enabled()  : bool
Whether the option has the "Update main image" setting enabled.
render_products()  : mixed
Render the HTML for the field input.

Properties

$button_width

protected mixed $button_width
Tags

$choice_char

The choice character setting.

protected array<string|int, mixed> $choice_char
Tags

$choice_qty

The choice quantity setting.

protected array<string|int, mixed> $choice_qty
Tags

$display_label

protected mixed $display_label
Tags

$dynamic_products

protected mixed $dynamic_products
Tags

$equal_pricing

Whether all choices have equal pricing.

protected bool $equal_pricing
Tags

$has_conditional_logic

Whether the field has conditional logic.

protected bool $has_conditional_logic = false
Tags

$has_user_value

Whether the field has a user-defined value.

protected bool $has_user_value = false
Tags

$is_display_field

Whether the field is for display only.

protected bool $is_display_field = false
Tags

$label_position

protected mixed $label_position
Tags

$manual_products

protected mixed $manual_products
Tags

$product_display_style

protected mixed $product_display_style = 'product'
Tags

$product_selection

protected mixed $product_selection
Tags
protected mixed $show_in_product_gallery
Tags

$stores_multiple_values

Whether the field can store multiple value selections (e.g checkboxes).

protected bool $stores_multiple_values = false
Tags

$supports_multiple_values

Whether the field supports multiple values (e.g checkboxes, radios, select).

protected bool $supports_multiple_values = true
Tags

$type

protected mixed $type = 'product'
Tags

$used_settings

An array of settings being used by the field.

protected array<string|int, mixed> $used_settings = ['product_display_style', 'display_label', 'product_selection', 'dynamic_products', 'manual_products', 'label_position', 'button_width', 'show_in_product_gallery']
Tags

$default_width

private mixed $default_width = 118
Tags

$products

private mixed $products = []
Tags

Methods

__construct()

Constructor.

public __construct(mixed $option, WC_Product $product) : mixed
Parameters
$option : mixed
$product : WC_Product
Tags
Return values
mixed

add_button_width_css_variable()

Add a style element with the CSS variable for the button width right after the field.

public add_button_width_css_variable() : void
Tags
Return values
void

get_cart_item_data()

Retrieves the cart item data for the selected value(s) of the field.

public get_cart_item_data(mixed $value, WC_Product $product, int $quantity, array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$value : mixed
$product : WC_Product
$quantity : int
$options : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

get_choice_formula_value()

Get the formula value associated with a choice of the field.

public get_choice_formula_value(int $index) : string
Parameters
$index : int

The index of the choice

Tags
Return values
string

get_conditional_logic_config()

Get the field conditional logic config.

public get_conditional_logic_config() : object|null
Tags
Return values
object|null

get_id()

Get the field id.

public get_id() : string
Tags
Return values
string

get_manually_selected_product_variations()

Get product variations that were manually selected in the backend options

public get_manually_selected_product_variations(int $product_id) : array<string|int, mixed>
Parameters
$product_id : int
Tags
Return values
array<string|int, mixed>

get_product()

Get the product for the field.

public get_product() : WC_Product
Tags
Return values
WC_Product

get_product_order_arg_value()

Get product orderby arg value

public get_product_order_arg_value(mixed $sorting) : string
Parameters
$sorting : mixed
Tags
Return values
string

get_product_orderby_arg_value()

Get product orderby arg value

public get_product_orderby_arg_value(string $sorting) : string
Parameters
$sorting : string
Tags
Return values
string

get_product_type_args()

Build product query args for product option type

public get_product_type_args() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

$args

get_setting()

Get the value of a specific field setting.

public get_setting(string $setting_name) : string|array<string|int, mixed>|null
Parameters
$setting_name : string

The key of the setting to retrieve.

Tags
Return values
string|array<string|int, mixed>|null

get_settings()

Get the array with the field settings.

public get_settings() : array<string|int, mixed>|null
Tags
Return values
array<string|int, mixed>|null

get_type()

Get the field type.

public get_type() : string
Tags
Return values
string

get_variable_product_style_checkbox()

Return the variation products as checkboxes and allow them to add to cart from the product page

public get_variable_product_style_checkbox(WC_Product $product, mixed $product_index) : string
Parameters
$product : WC_Product
$product_index : mixed
Tags
Return values
string

get_variable_product_style_image()

Return the variation products as image buttons and allow them to add to cart from the product page

public get_variable_product_style_image(WC_Product $product) : string
Parameters
$product : WC_Product
Tags
Return values
string

get_variable_product_style_product()

Display variations as indidivual products and allow them to directly add to cart

public get_variable_product_style_product(WC_Product $product) : string
Parameters
$product : WC_Product
Tags
Return values
string

get_variable_product_style_radio()

Return the variation products as radio buttons and allow them to add to cart from the product page

public get_variable_product_style_radio(WC_Product $product, int $product_index) : string
Parameters
$product : WC_Product
$product_index : int

The index of the item in the list of radio buttons

Tags
Return values
string

has_conditional_logic()

Whether the field has conditional logic.

public has_conditional_logic() : bool
Return values
bool

has_user_value()

Whether the field has a user inputted value.

public has_user_value() : bool
Return values
bool

is_required()

Whether the field is required.

public is_required() : bool
Tags
Return values
bool

render()

Render the HTML for the field.

public render() : void
Tags
Return values
void

sanitize()

Sanitize the field input value.

public sanitize(mixed $value) : mixed
Parameters
$value : mixed
Tags
Return values
mixed

stores_multiple_values()

Whether the field stores multiple values.

public stores_multiple_values() : bool
Tags
Return values
bool

validate()

Validate the product options and add to cart

public validate(array<string|int, mixed> $value, array<string|int, mixed> $option_data) : bool|WP_Error
Parameters
$value : array<string|int, mixed>
$option_data : array<string|int, mixed>
Tags
Return values
bool|WP_Error

get_attachment_image_sizes()

Get the `sizes` attribute for the image element.

protected get_attachment_image_sizes(string|int $attachment_id, mixed $width) : string
Parameters
$attachment_id : string|int

The ID of the image attachment.

$width : mixed
Tags
since
1.6.4
Return values
string

get_choice_for_value()

Retrieves the choice from the option DB based on the user value provided.

protected get_choice_for_value(mixed $value) : array<string|int, mixed>|null
Parameters
$value : mixed
Tags
Return values
array<string|int, mixed>|null

get_choice_image()

protected get_choice_image(mixed $index) : string
Parameters
$index : mixed
Tags
Return values
string

get_choice_image_html()

Get the choice image HTML markup

protected get_choice_image_html(mixed $index) : string
Parameters
$index : mixed
Tags
Return values
string

get_choice_pricing_attributes()

Gets the data attributes to handle JS pricing calculation.

protected get_choice_pricing_attributes([array<string|int, mixed> $choice = [] ]) : string
Parameters
$choice : array<string|int, mixed> = []
Tags
Return values
string

get_choice_pricing_string()

Retrieves the pricing string for a choice

protected get_choice_pricing_string([array<string|int, mixed> $choice = [] ][, mixed $skip_parenthesis = true ]) : string
Parameters
$choice : array<string|int, mixed> = []
$skip_parenthesis : mixed = true
Tags
Return values
string

get_field_attributes()

Gets the data attributes to handle conditional logic visibilities.

protected get_field_attributes() : string
Tags
Return values
string

get_field_class()

Gets the CSS class for the field.

protected get_field_class() : string
Tags
Return values
string

get_image_data()

Return the `data-image` attribute of the image button.

protected get_image_data(string|int $attachment_id) : string

The attribute contains the image data in JSON format as returned by the wc_get_product_attachment_props function.

Parameters
$attachment_id : string|int

The ID of the image attachment.

Tags
since
1.6.4
Return values
string

get_image_srcset()

Get the srcset attribute for the image.

protected get_image_srcset(int $image_id, mixed $size) : string
Parameters
$image_id : int
$size : mixed
Tags
Return values
string

get_input_id()

Gets the id attribute for the field input.

protected get_input_id() : string
Tags
Return values
string

get_input_name()

Gets the name attribute for the field input.

protected get_input_name() : string
Tags
Return values
string

get_label()

Get the label for the field or its choices.

protected get_label(int $index[, mixed $skip_filters = false ]) : string

The $index parameter is used to get the label for a specific choice. For single-choice fields, the $index can be omitted.

Parameters
$index : int

The index of the choice (or 0 for single-choice fields)

$skip_filters : mixed = false
Tags
Return values
string

get_pricing_attributes()

Retrieves top level pricing attributes for the field.

protected get_pricing_attributes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

get_required_symbol()

protected get_required_symbol() : mixed
Tags
Return values
mixed

has_choice_images()

protected has_choice_images() : bool
Tags
Return values
bool

has_display_prerequisites()

Determines whether the option has enough data to display.

protected has_display_prerequisites() : bool
Tags
Return values
bool

is_update_main_image_enable()

Whether the option has the "Update main image" setting enabled.

protected is_update_main_image_enable() : bool
Tags
since
1.6.4
Return values
bool

render_checkboxes_style_html()

Render products in checkbox styles

protected render_checkboxes_style_html() : mixed
Tags
Return values
mixed

render_choice_character_limits_label()

Gets the label for choice character limits if applicable.

protected render_choice_character_limits_label() : void
Tags
Return values
void

render_choice_quantity_limits_label()

Gets the label for choice quantity limits if applicable.

protected render_choice_quantity_limits_label() : void
Tags
Return values
void

render_description()

Render the HTML for the field description.

protected render_description() : void
Tags
Return values
void

render_dropdowns_style_html()

Render products in dropdown styles

protected render_dropdowns_style_html() : mixed
Tags
Return values
mixed

render_field_wrap_close()

Renders the field wrap closing tag.

protected render_field_wrap_close() : void
Tags
Return values
void

render_field_wrap_open()

Renders the field wrap.

protected render_field_wrap_open() : void
Tags
Return values
void

render_image_buttons_style_html()

Render products in image buttons styles

protected render_image_buttons_style_html() : mixed
Tags
Return values
mixed

render_option_name()

Render the HTML for the field label.

protected render_option_name() : void
Tags
Return values
void

render_product_style_html()

Render the HTML for the product style.

protected render_product_style_html() : mixed
Tags
Return values
mixed

render_products_html_based_on_style()

Render the HTML for products based on the style.

protected render_products_html_based_on_style() : mixed
Tags
Return values
mixed

render_radios_style_html()

Render products in radio styles

protected render_radios_style_html() : mixed
Tags
Return values
mixed

get_button_width()

Get the width of the image buttons.

private get_button_width() : string
Tags
since
1.6.4
Return values
string

get_deselect_svg()

SVG for deselecting an image button.

private get_deselect_svg() : string
Tags
Return values
string
private get_edit_option_link() : mixed
Tags
Return values
mixed

get_figcaption()

private get_figcaption(mixed $product) : mixed
Parameters
$product : mixed
Tags
Return values
mixed

get_image_wrap_class()

Get the class for the image wrap.

private get_image_wrap_class() : string
Tags
Return values
string

The class.

init_conditional_logic()

Determine whether the field has conditional logic.

private init_conditional_logic() : mixed
Tags
Return values
mixed

is_update_main_image_enabled()

Whether the option has the "Update main image" setting enabled.

private is_update_main_image_enabled() : bool
Tags
since
1.6.4
Return values
bool

render_products()

Render the HTML for the field input.

private render_products() : mixed
Tags
Return values
mixed

Search results