WooCommerce Code Reference

Utils
in package

Utility methods used for the Add to Cart + Options block.

Table of Contents

add_quantity_stepper_classes()  : string
Add classes to the Quantity Selector needed for the stepper style.
add_quantity_steppers()  : string
Add increment and decrement buttons to the quantity input field.
get_product_from_context()  : WC_Product|null
Get product from block context.
get_quantity_input_args()  : array<string|int, mixed>
Get standardized quantity input arguments for WooCommerce quantity input.
is_min_max_quantity_same()  : bool
Check if min and max purchase quantity are the same for a product.
is_not_purchasable_product()  : bool
Check if a product is not purchasable or not in stock.
make_quantity_input_interactive()  : string
Make the quantity input interactive by wrapping it with the necessary data attribute and adding an input event listener.
render_block_with_context()  : string
Renders a new block with custom context

Methods

add_quantity_stepper_classes()

Add classes to the Quantity Selector needed for the stepper style.

public static add_quantity_stepper_classes(string $quantity_html) : string
Parameters
$quantity_html : string

The Quantity Selector HTML.

Return values
stringThe Quantity Selector HTML with classes added.

add_quantity_steppers()

Add increment and decrement buttons to the quantity input field.

public static add_quantity_steppers(string $quantity_html, string $product_name) : string
Parameters
$quantity_html : string

Quantity input HTML.

$product_name : string

Product name.

Return values
stringQuantity input HTML with increment and decrement buttons.

get_quantity_input_args()

Get standardized quantity input arguments for WooCommerce quantity input.

public static get_quantity_input_args(WC_Product $product) : array<string|int, mixed>
Parameters
$product : WC_Product

The product object.

Return values
array<string|int, mixed>Arguments for woocommerce_quantity_input().

is_min_max_quantity_same()

Check if min and max purchase quantity are the same for a product.

public static is_min_max_quantity_same(WC_Product $product) : bool
Parameters
$product : WC_Product

The product to check.

Return values
boolTrue if min and max purchase quantity are the same, false otherwise.

make_quantity_input_interactive()

Make the quantity input interactive by wrapping it with the necessary data attribute and adding an input event listener.

public static make_quantity_input_interactive(string $quantity_html[, string $wrapper_attributes = '' ][, int|null $child_product_id = null ]) : string
Parameters
$quantity_html : string

The quantity HTML.

$wrapper_attributes : string = ''

Optional wrapper attributes.

$child_product_id : int|null = null

Optional child product ID.

Return values
stringThe quantity HTML with interactive wrapper.

render_block_with_context()

Renders a new block with custom context

public static render_block_with_context(WP_Block $block, array<string|int, mixed> $context) : string
Parameters
$block : WP_Block

The block instance.

$context : array<string|int, mixed>

The context for the new block.

Return values
stringRendered block content