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.
- is_not_purchasable_simple_product() : bool
- Check if a product is a simple product that 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
string — The 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
string — Quantity input HTML with increment and decrement buttons.get_product_from_context()
Get product from block context.
public
static get_product_from_context(WP_Block $block, WC_Product|null $previous_product) : WC_Product|null
Parameters
- $block : WP_Block
-
The block instance.
- $previous_product : WC_Product|null
-
The previous product (usually from global scope).
Return values
WC_Product|null — The product instance or null if not found.is_not_purchasable_simple_product()
Check if a product is a simple product that is not purchasable or not in stock.
public
static is_not_purchasable_simple_product(WC_Product $product) : bool
Parameters
- $product : WC_Product
-
The product to check.
Return values
bool — True if the product is a simple product that is not purchasable or not in stock.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 = '' ]) : string
Parameters
- $quantity_html : string
-
The quantity HTML.
- $wrapper_attributes : string = ''
-
Optional wrapper attributes.
Return values
string — The 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.