ProductOnSale
extends AbstractProductGrid
in package
ProductOnSale class.
Table of Contents
- $asset_api : Api
- Instance of the asset API.
- $asset_data_registry : AssetDataRegistry
- Instance of the asset data registry.
- $attributes : array<string|int, mixed>
- Attributes.
- $block_name : string
- Block name.
- $content : string
- InnerBlocks content.
- $enqueued_assets : bool
- Tracks if assets have been enqueued.
- $integration_registry : IntegrationRegistry
- Instance of the integration registry.
- $meta_query : array<string|int, mixed>
- Meta query args.
- $namespace : string
- Block namespace.
- $query_args : array<string|int, mixed>
- Query args.
- __construct() : mixed
- Constructor.
- enqueue_editor_assets() : mixed
- Enqueue assets used for rendering the block in editor context.
- render_callback() : string
- The default render_callback for all blocks. This will ensure assets are enqueued just in time, then render the block (if applicable).
- enqueue_data() : mixed
- Data passed through from server to client for block.
- enqueue_scripts() : mixed
- Register/enqueue scripts used for this block on the frontend, during render.
- get_add_to_cart() : string
- Get the "add to cart" button.
- get_block_type() : string
- Get the block type.
- get_block_type_attributes() : array<string|int, mixed>
- Get block attributes.
- get_block_type_editor_script() : array<string|int, mixed>|string
- Get the editor script data for this block type.
- get_block_type_editor_style() : string|null
- Get the editor style handle for this block type.
- get_block_type_render_callback() : callable|null
- Get the render callback for this block type.
- get_block_type_script() : array<string|int, mixed>|string|null
- Get the frontend script handle for this block type.
- get_block_type_style() : array<string|int, string>|null
- Get the frontend style handle for this block type.
- get_block_type_supports() : string
- Get the supports array for this block type.
- get_block_type_uses_context() : array<string|int, mixed>
- Get block usesContext.
- get_button_html() : string
- Get the button.
- get_chunks_paths() : array<string|int, string>
- Generate an array of chunks paths for loading translation.
- get_container_classes() : string
- Get the list of classes to apply to this block.
- get_full_block_name() : string
- Get the interactivity namespace. Only used when utilizing the interactivity API.
- get_image_html() : string
- Get the product image.
- get_non_cached_ids() : array<string|int, int>
- Retrieve IDs that are not already present in the cache.
- get_price_html() : string
- Get the price.
- get_products() : array<string|int, mixed>
- Run the query and return an array of product IDs
- get_products_limit() : int
- Works out the item limit based on rows and columns, or returns default.
- get_rating_html() : string
- Render the rating icons.
- get_routes_from_namespace() : array<string|int, mixed>
- Get routes from a REST API namespace.
- get_sale_badge_html() : string
- Get the sale badge.
- get_schema_align() : array<string|int, mixed>
- Get the schema for the alignment property.
- get_schema_boolean() : array<string|int, mixed>
- Get the schema for a boolean value.
- get_schema_content_visibility() : array<string|int, mixed>
- Get the schema for the contentVisibility attribute
- get_schema_list_ids() : array<string|int, mixed>
- Get the schema for a list of IDs.
- get_schema_number() : array<string|int, mixed>
- Get the schema for a numeric value.
- get_schema_orderby() : array<string|int, mixed>
- Get the schema for the orderby attribute.
- get_schema_string() : array<string|int, mixed>
- Get the schema for a string value.
- get_title_html() : string
- Get the product title.
- initialize() : mixed
- Initialize this block type.
- parse_attributes() : array<string|int, mixed>
- Get the block's attributes.
- parse_query_args() : array<string|int, mixed>
- Parse query args.
- parse_render_callback_attributes() : array<string|int, mixed>
- Parses block attributes from the render_callback.
- prime_product_variations() : mixed
- Prime query cache of product variation meta data.
- register_block_type() : array<string|int, string>
- Registers the block type with WordPress.
- register_block_type_assets() : mixed
- Register script and style assets for the block type before it is registered.
- register_chunk_translations() : mixed
- Injects Chunk Translations into the page so translations work for lazy loaded components.
- render() : string
- Render the block. Extended by children.
- render_product() : string
- Render a single products.
- set_block_query_args() : mixed
- Set args specific to this block
- set_categories_query_args() : mixed
- Set categories query args.
- set_ordering_query_args() : mixed
- Parse query args.
- set_stock_status_query_args() : void
- Set which stock status to use when displaying products.
- set_visibility_query_args() : mixed
- Set visibility query args.
Properties
$asset_api
Instance of the asset API.
protected
Api
$asset_api
$asset_data_registry
Instance of the asset data registry.
protected
AssetDataRegistry
$asset_data_registry
$attributes
Attributes.
protected
array<string|int, mixed>
$attributes
= array()
$block_name
Block name.
protected
string
$block_name
= 'product-on-sale'
$content
InnerBlocks content.
protected
string
$content
= ''
$enqueued_assets
Tracks if assets have been enqueued.
protected
bool
$enqueued_assets
= false
$integration_registry
Instance of the integration registry.
protected
IntegrationRegistry
$integration_registry
$meta_query
Meta query args.
protected
array<string|int, mixed>
$meta_query
= array()
$namespace
Block namespace.
protected
string
$namespace
= 'woocommerce'
$query_args
Query args.
protected
array<string|int, mixed>
$query_args
= array()
Methods
__construct()
Constructor.
public
__construct(Api $asset_api, AssetDataRegistry $asset_data_registry, IntegrationRegistry $integration_registry[, string $block_name = '' ]) : mixed
Parameters
- $asset_api : Api
-
Instance of the asset API.
- $asset_data_registry : AssetDataRegistry
-
Instance of the asset data registry.
- $integration_registry : IntegrationRegistry
-
Instance of the integration registry.
- $block_name : string = ''
-
Optionally set block name during construct.
Return values
mixed —enqueue_editor_assets()
Enqueue assets used for rendering the block in editor context.
public
enqueue_editor_assets() : mixed
This is needed if a block is not yet within the post content--render
and enqueue_assets
may not have ran.
Return values
mixed —render_callback()
The default render_callback for all blocks. This will ensure assets are enqueued just in time, then render the block (if applicable).
public
render_callback([array<string|int, mixed>|WP_Block $attributes = [] ][, string $content = '' ][, WP_Block|null $block = null ]) : string
Parameters
- $attributes : array<string|int, mixed>|WP_Block = []
-
Block attributes, or an instance of a WP_Block. Defaults to an empty array.
- $content : string = ''
-
Block content. Default empty string.
- $block : WP_Block|null = null
-
Block instance.
Return values
string — Rendered block type output.enqueue_data()
Data passed through from server to client for block.
protected
enqueue_data([array<string|int, mixed> $attributes = [] ]) : mixed
Parameters
- $attributes : array<string|int, mixed> = []
-
Any attributes that currently are available from the block. Note, this will be empty in the editor context when the block is not in the post content on editor load.
Return values
mixed —enqueue_scripts()
Register/enqueue scripts used for this block on the frontend, during render.
protected
enqueue_scripts([array<string|int, mixed> $attributes = [] ]) : mixed
Parameters
- $attributes : array<string|int, mixed> = []
-
Any attributes that currently are available from the block.
Return values
mixed —get_add_to_cart()
Get the "add to cart" button.
protected
get_add_to_cart(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product.
Return values
string — Rendered product output.get_block_type()
Get the block type.
protected
get_block_type() : string
Return values
string —get_block_type_attributes()
Get block attributes.
protected
get_block_type_attributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_block_type_editor_script()
Get the editor script data for this block type.
protected
get_block_type_editor_script([string $key = null ]) : array<string|int, mixed>|string
Parameters
- $key : string = null
-
Data to get, or default to everything.
Tags
Return values
array<string|int, mixed>|string —get_block_type_editor_style()
Get the editor style handle for this block type.
protected
get_block_type_editor_style() : string|null
Tags
Return values
string|null —get_block_type_render_callback()
Get the render callback for this block type.
protected
get_block_type_render_callback() : callable|null
Dynamic blocks should return a callback, for example, return [ $this, 'render' ];
Tags
Return values
callable|null —get_block_type_script()
Get the frontend script handle for this block type.
protected
get_block_type_script([string $key = null ]) : array<string|int, mixed>|string|null
Parameters
- $key : string = null
-
Data to get, or default to everything.
Tags
Return values
array<string|int, mixed>|string|null —get_block_type_style()
Get the frontend style handle for this block type.
protected
get_block_type_style() : array<string|int, string>|null
Return values
array<string|int, string>|null —get_block_type_supports()
Get the supports array for this block type.
protected
get_block_type_supports() : string
Tags
Return values
string —get_block_type_uses_context()
Get block usesContext.
protected
get_block_type_uses_context() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_button_html()
Get the button.
protected
get_button_html(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product.
Return values
string — Rendered product output.get_chunks_paths()
Generate an array of chunks paths for loading translation.
protected
get_chunks_paths(string $chunks_folder) : array<string|int, string>
Parameters
- $chunks_folder : string
-
The folder to iterate over.
Return values
array<string|int, string> — $chunks list of chunks to load.get_container_classes()
Get the list of classes to apply to this block.
protected
get_container_classes() : string
Return values
string — space-separated list of classes.get_full_block_name()
Get the interactivity namespace. Only used when utilizing the interactivity API.
protected
get_full_block_name() : string
Return values
string — The interactivity namespace, used to namespace interactivity API actions and state.get_image_html()
Get the product image.
protected
get_image_html(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product.
Return values
string —get_non_cached_ids()
Retrieve IDs that are not already present in the cache.
protected
get_non_cached_ids(array<string|int, int> $product_ids, string $cache_key) : array<string|int, int>
Based on WordPress function: _get_non_cached_ids
Parameters
- $product_ids : array<string|int, int>
-
Array of IDs.
- $cache_key : string
-
The cache bucket to check against.
Return values
array<string|int, int> — Array of IDs not present in the cache.get_price_html()
Get the price.
protected
get_price_html(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product.
Return values
string — Rendered product output.get_products()
Run the query and return an array of product IDs
protected
get_products() : array<string|int, mixed>
Return values
array<string|int, mixed> — List of product IDsget_products_limit()
Works out the item limit based on rows and columns, or returns default.
protected
get_products_limit() : int
Return values
int —get_rating_html()
Render the rating icons.
protected
get_rating_html(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product.
Return values
string — Rendered product output.get_routes_from_namespace()
Get routes from a REST API namespace.
protected
get_routes_from_namespace(string $namespace) : array<string|int, mixed>
Parameters
- $namespace : string
-
Namespace to retrieve.
Return values
array<string|int, mixed> —get_sale_badge_html()
Get the sale badge.
protected
get_sale_badge_html(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product.
Return values
string — Rendered product output.get_schema_align()
Get the schema for the alignment property.
protected
get_schema_align() : array<string|int, mixed>
Return values
array<string|int, mixed> — Property definition for align.get_schema_boolean()
Get the schema for a boolean value.
protected
get_schema_boolean([string $default = true ]) : array<string|int, mixed>
Parameters
- $default : string = true
-
The default value.
Return values
array<string|int, mixed> — Property definition.get_schema_content_visibility()
Get the schema for the contentVisibility attribute
protected
get_schema_content_visibility() : array<string|int, mixed>
Return values
array<string|int, mixed> — List of block attributes with type and defaults.get_schema_list_ids()
Get the schema for a list of IDs.
protected
get_schema_list_ids() : array<string|int, mixed>
Return values
array<string|int, mixed> — Property definition for a list of numeric ids.get_schema_number()
Get the schema for a numeric value.
protected
get_schema_number(string $default) : array<string|int, mixed>
Parameters
- $default : string
-
The default value.
Return values
array<string|int, mixed> — Property definition.get_schema_orderby()
Get the schema for the orderby attribute.
protected
get_schema_orderby() : array<string|int, mixed>
Return values
array<string|int, mixed> — Property definition of `orderby` attribute.get_schema_string()
Get the schema for a string value.
protected
get_schema_string([string $default = '' ]) : array<string|int, mixed>
Parameters
- $default : string = ''
-
The default value.
Return values
array<string|int, mixed> — Property definition.get_title_html()
Get the product title.
protected
get_title_html(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product.
Return values
string —initialize()
Initialize this block type.
protected
initialize() : mixed
- Hook into WP lifecycle.
- Register the block with WordPress.
Return values
mixed —parse_attributes()
Get the block's attributes.
protected
parse_attributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
-
Block attributes. Default empty array.
Return values
array<string|int, mixed> — Block attributes merged with defaults.parse_query_args()
Parse query args.
protected
parse_query_args() : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_render_callback_attributes()
Parses block attributes from the render_callback.
protected
parse_render_callback_attributes(array<string|int, mixed>|WP_Block $attributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>|WP_Block
-
Block attributes, or an instance of a WP_Block. Defaults to an empty array.
Return values
array<string|int, mixed> —prime_product_variations()
Prime query cache of product variation meta data.
protected
prime_product_variations(array<string|int, int> $product_ids) : mixed
Prepares values in the product_ID_variation_meta_data cache for later use in the ProductSchema::get_variations() method. Doing so here reduces the total number of queries needed.
Parameters
- $product_ids : array<string|int, int>
-
Product ids to prime variation cache for.
Return values
mixed —register_block_type()
Registers the block type with WordPress.
protected
register_block_type() : array<string|int, string>
Return values
array<string|int, string> — Chunks paths.register_block_type_assets()
Register script and style assets for the block type before it is registered.
protected
register_block_type_assets() : mixed
This registers the scripts; it does not enqueue them.
Return values
mixed —register_chunk_translations()
Injects Chunk Translations into the page so translations work for lazy loaded components.
protected
register_chunk_translations(array<string|int, string> $chunks) : mixed
The chunk names are defined when creating lazy loaded components using webpackChunkName.
Parameters
- $chunks : array<string|int, string>
-
Array of chunk names.
Return values
mixed —render()
Render the block. Extended by children.
protected
render(array<string|int, mixed> $attributes, string $content, WP_Block $block) : string
Parameters
- $attributes : array<string|int, mixed>
-
Block attributes.
- $content : string
-
Block content.
- $block : WP_Block
-
Block instance.
Return values
string — Rendered block type output.render_product()
Render a single products.
protected
render_product(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product object.
Return values
string — Rendered product output.set_block_query_args()
Set args specific to this block
protected
set_block_query_args(array<string|int, mixed> &$query_args) : mixed
Parameters
- $query_args : array<string|int, mixed>
-
Query args.
Return values
mixed —set_categories_query_args()
Set categories query args.
protected
set_categories_query_args(array<string|int, mixed> &$query_args) : mixed
Parameters
- $query_args : array<string|int, mixed>
-
Query args.
Return values
mixed —set_ordering_query_args()
Parse query args.
protected
set_ordering_query_args(array<string|int, mixed> &$query_args) : mixed
Parameters
- $query_args : array<string|int, mixed>
-
Query args.
Return values
mixed —set_stock_status_query_args()
Set which stock status to use when displaying products.
protected
set_stock_status_query_args(array<string|int, mixed> &$query_args) : void
Parameters
- $query_args : array<string|int, mixed>
-
Query args.
Return values
void —set_visibility_query_args()
Set visibility query args.
protected
set_visibility_query_args(array<string|int, mixed> &$query_args) : mixed
Parameters
- $query_args : array<string|int, mixed>
-
Query args.