ProductPrice
extends AbstractBlock
in package
Uses
EnableBlockJsonAssetsTrait, BlocksSharedState
ProductPrice class.
Table of Contents
- $api_version : string
- API version name.
- $asset_api : Api
- Instance of the asset API.
- $asset_data_registry : AssetDataRegistry
- Instance of the asset data registry.
- $block_name : string
- Block name.
- $enqueued_assets : bool
- Tracks if assets have been enqueued.
- $integration_registry : IntegrationRegistry
- Instance of the integration registry.
- $namespace : string
- Block namespace.
- $blocks_shared_cart_state : mixed
- Cart state.
- $consent_statement : string
- The consent statement for using private APIs of this class.
- $core_config_registered : bool
- Whether the core config has been registered.
- $settings_namespace : string
- The namespace for the config.
- __construct() : mixed
- Constructor.
- enqueue_editor_assets() : mixed
- Enqueue assets used for rendering the block in editor context.
- initialize_shared_config() : mixed
- Initialize the shared core config.
- register_cart_interactivity() : void
- Initialize interactivity state for cart that is needed by multiple blocks.
- 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_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() : 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>
- Register the context.
- get_chunks_paths() : array<string|int, string>
- Generate an array of chunks paths for loading translation.
- get_full_block_name() : string
- Get the interactivity namespace. Only used when utilizing the interactivity API.
- get_routes_from_namespace() : array<string|int, mixed>
- Get routes from a REST API namespace.
- initialize() : mixed
- Initialize this block type.
- is_block_editor() : mixed
- Are we currently on the admin block editor screen?
- parse_render_callback_attributes() : array<string|int, mixed>
- Parses block attributes from the render_callback.
- register_block_type() : array<string|int, string>
- Registers the block type with WordPress.
- register_block_type_assets() : mixed
- Overwrite parent method to prevent script registration.
- register_chunk_translations() : mixed
- Injects Chunk Translations into the page so translations work for lazy loaded components.
- render() : string
- Include and render the block.
- check_consent() : true
- Check that the consent statement was passed.
- get_core_data() : array<string|int, mixed>
- Get core data to include in settings.
- get_currency_data() : array<string|int, mixed>
- Get currency data to include in settings.
- get_locale_data() : array<string|int, mixed>
- Get locale data to include in settings.
- prevent_cache() : mixed
- Prevent caching on certain pages
Properties
$api_version
API version name.
protected
string
$api_version
= '3'
$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
$block_name
Block name.
protected
string
$block_name
= 'product-price'
$enqueued_assets
Tracks if assets have been enqueued.
protected
bool
$enqueued_assets
= false
$integration_registry
Instance of the integration registry.
protected
IntegrationRegistry
$integration_registry
$namespace
Block namespace.
protected
string
$namespace
= 'woocommerce'
$blocks_shared_cart_state
Cart state.
private
static mixed
$blocks_shared_cart_state
$consent_statement
The consent statement for using private APIs of this class.
private
static string
$consent_statement
= 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WooCommerce'
$core_config_registered
Whether the core config has been registered.
private
static bool
$core_config_registered
= false
$settings_namespace
The namespace for the config.
private
static string
$settings_namespace
= 'woocommerce'
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 —initialize_shared_config()
Initialize the shared core config.
public
initialize_shared_config(string $consent_statement) : mixed
Parameters
- $consent_statement : string
-
- The consent statement string.
Return values
mixed —register_cart_interactivity()
Initialize interactivity state for cart that is needed by multiple blocks.
public
register_cart_interactivity(string $consent_statement) : void
Parameters
- $consent_statement : string
-
- The consent statement string.
Return values
void —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_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() : null
Return values
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()
Register the context.
protected
get_block_type_uses_context() : array<string|int, mixed>
Return values
array<string|int, mixed> —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_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_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> —initialize()
Initialize this block type.
protected
initialize() : mixed
- Hook into WP lifecycle.
- Register the block with WordPress.
Return values
mixed —is_block_editor()
Are we currently on the admin block editor screen?
protected
is_block_editor() : mixed
Return values
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> —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()
Overwrite parent method to prevent script registration.
protected
register_block_type_assets() : mixed
It is necessary to register and enqueues assets during the render phase because we want to load assets only if the block has the content.
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()
Include and render the block.
protected
render(array<string|int, mixed> $attributes, string $content, WP_Block $block) : string
Parameters
- $attributes : array<string|int, mixed>
-
Block attributes. Default empty array.
- $content : string
-
Block content. Default empty string.
- $block : WP_Block
-
Block instance.
Return values
string — Rendered block type output.check_consent()
Check that the consent statement was passed.
private
static check_consent(string $consent_statement) : true
Parameters
- $consent_statement : string
-
- The consent statement string.
Tags
Return values
true —get_core_data()
Get core data to include in settings.
private
static get_core_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_currency_data()
Get currency data to include in settings.
private
static get_currency_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_locale_data()
Get locale data to include in settings.
private
static get_locale_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —prevent_cache()
Prevent caching on certain pages
private
static prevent_cache() : mixed