WooCommerce Code Reference

CustomerAccount extends AbstractBlock
in package
Uses BlockHooksTrait, EnableBlockJsonAssetsTrait

CustomerAccount class.

Table of Contents

DISPLAY_ALT  = 'alt'
DISPLAY_LINE  = 'line'
ICON_ONLY  = 'icon_only'
TEXT_ONLY  = 'text_only'
$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.
$hooked_block_placements  : array<string|int, mixed>
Block Hook API placements.
$integration_registry  : IntegrationRegistry
Instance of the integration registry.
$namespace  : string
Block namespace.
__construct()  : mixed
Constructor.
enqueue_editor_assets()  : mixed
Enqueue assets used for rendering the block in editor context.
modify_hooked_block_attributes()  : array<string|int, mixed>|null
Callback for the Block Hooks API to modify the attributes of the hooked block.
register_hooked_block()  : array<string|int, mixed>
Callback for `hooked_block_types` to auto-inject the mini-cart block into headers after navigation.
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()  : 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_chunks_paths()  : array<string|int, string>
Generate an array of chunks paths for loading translation.
get_context_content()  : string
Given a provided context, returns the content of the context.
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.
has_block_in_content()  : bool
Checks if the provided context contains a the block already.
initialize()  : mixed
Initialize this block type.
is_block_editor()  : mixed
Are we currently on the admin block editor screen?
is_target_area()  : bool
Given a provided context, returns whether the context refers to the target area and isn't marked as excluded.
is_template_part_or_pattern()  : bool
Given a provided context, returns whether the context refers to header content.
parse_render_callback_attributes()  : array<string|int, mixed>
Parses block attributes from the render_callback.
pattern_is_excluded()  : bool
Returns whether the pattern is excluded or not
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.
should_unhook_block()  : array<string|int, mixed>
Callback for the Block Hooks API to determine if the block should be auto-inserted.
get_allowed_svg()  : array<string|int, mixed>
Get the allowed SVG tags and attributes for wp_kses.
render_caret_icon()  : string
Render the caret/chevron icon for the dropdown toggle.
render_dropdown()  : string
Render the block as a dropdown navigation.
render_dropdown_menu()  : string
Render the dropdown menu content with three sections.
render_icon()  : string
Gets the icon to render depending on the iconStyle and displayStyle.
render_label()  : string
Gets the label to render depending on the displayStyle.
render_link()  : string
Render the block as a simple link (default behavior).
render_menu_item()  : string
Render a single dropdown menu item.
render_section()  : string
Render a dropdown section wrapping one or more menu items.

Constants

Properties

$hooked_block_placements

Block Hook API placements.

protected array<string|int, mixed> $hooked_block_placements = array(array('position' => 'after', 'anchor' => 'core/navigation', 'area' => 'header', 'callback' => 'should_unhook_block', 'version' => '8.4.0'))

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

modify_hooked_block_attributes()

Callback for the Block Hooks API to modify the attributes of the hooked block.

public modify_hooked_block_attributes(array<string|int, mixed>|null $parsed_hooked_block, string $hooked_block_type, string $relative_position, array<string|int, mixed> $parsed_anchor_block, WP_Block_Template|WP_Post|array<string|int, mixed> $context) : array<string|int, mixed>|null
Parameters
$parsed_hooked_block : array<string|int, mixed>|null

The parsed block array for the given hooked block type, or null to suppress the block.

$hooked_block_type : string

The hooked block type name.

$relative_position : string

The relative position of the hooked block.

$parsed_anchor_block : array<string|int, mixed>

The anchor block, in parsed block array format.

$context : WP_Block_Template|WP_Post|array<string|int, mixed>

The block template, template part, wp_navigation post type, or pattern that the anchor block belongs to.

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

register_hooked_block()

Callback for `hooked_block_types` to auto-inject the mini-cart block into headers after navigation.

public register_hooked_block(array<string|int, mixed> $hooked_blocks, string $position, string $anchor_block, array<string|int, mixed>|WP_Post|WP_Block_Template $context) : array<string|int, mixed>
Parameters
$hooked_blocks : array<string|int, mixed>

An array of block slugs hooked into a given context.

$position : string

Position of the block insertion point.

$anchor_block : string

The block acting as the anchor for the inserted block.

$context : array<string|int, mixed>|WP_Post|WP_Block_Template

Where the block is embedded.

Tags
since
8.5.0
Return values
array<string|int, mixed>An array of block slugs hooked into a given context.

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
stringRendered 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_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
see

$this->register_block_type()

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
see

$this->register_block_type()

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
see

$this->register_block_type()

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
see

$this->register_block_type()

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
see

$this->register_block_type()

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_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_context_content()

Given a provided context, returns the content of the context.

protected get_context_content(array<string|int, mixed>|WP_Post|WP_Block_Template $context) : string
Parameters
$context : array<string|int, mixed>|WP_Post|WP_Block_Template

Where the block is embedded.

Tags
since
8.5.0
Return values
string

get_full_block_name()

Get the interactivity namespace. Only used when utilizing the interactivity API.

protected get_full_block_name() : string
Return values
stringThe 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>

has_block_in_content()

Checks if the provided context contains a the block already.

protected has_block_in_content(array<string|int, mixed>|WP_Block_Template $context) : bool
Parameters
$context : array<string|int, mixed>|WP_Block_Template

Where the block is embedded.

Return values
bool

is_target_area()

Given a provided context, returns whether the context refers to the target area and isn't marked as excluded.

protected is_target_area(array<string|int, mixed>|WP_Post|WP_Block_Template $context, string $area) : bool
Parameters
$context : array<string|int, mixed>|WP_Post|WP_Block_Template

the context to check.

$area : string

The area to check against before inserting.

Tags
since
8.5.0
Return values
bool

is_template_part_or_pattern()

Given a provided context, returns whether the context refers to header content.

protected is_template_part_or_pattern(array<string|int, mixed>|WP_Post|WP_Block_Template $context, string $area) : bool
Parameters
$context : array<string|int, mixed>|WP_Post|WP_Block_Template

Where the block is embedded.

$area : string

The area to check against before inserting.

Tags
since
8.5.0
Return values
bool

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>

pattern_is_excluded()

Returns whether the pattern is excluded or not

protected pattern_is_excluded(array<string|int, mixed>|WP_Block_Template $context) : bool
Parameters
$context : array<string|int, mixed>|WP_Block_Template

Where the block is embedded.

Tags
since
8.5.0
Return values
bool

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.

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
stringRendered block output.

should_unhook_block()

Callback for the Block Hooks API to determine if the block should be auto-inserted.

protected should_unhook_block(array<string|int, mixed> $hooked_blocks, string $position, string $anchor_block, array<string|int, mixed>|WP_Post|WP_Block_Template $context) : array<string|int, mixed>
Parameters
$hooked_blocks : array<string|int, mixed>

An array of block slugs hooked into a given context.

$position : string

Position of the block insertion point.

$anchor_block : string

The block acting as the anchor for the inserted block.

$context : array<string|int, mixed>|WP_Post|WP_Block_Template

Where the block is embedded.

Return values
array<string|int, mixed>

get_allowed_svg()

Get the allowed SVG tags and attributes for wp_kses.

private get_allowed_svg() : array<string|int, mixed>
Return values
array<string|int, mixed>Allowed SVG elements and attributes.

render_caret_icon()

Render the caret/chevron icon for the dropdown toggle.

private render_caret_icon() : string
Return values
stringSVG markup for the caret icon.

render_dropdown()

Render the block as a dropdown navigation.

private render_dropdown(array<string|int, mixed> $attributes, array<string|int, mixed> $classes_and_styles, string $aria_label, string $label_markup) : string
Parameters
$attributes : array<string|int, mixed>

Block attributes.

$classes_and_styles : array<string|int, mixed>

Classes and styles from block attributes.

$aria_label : string

Pre-computed aria-label attribute string.

$label_markup : string

Pre-computed label HTML markup.

Return values
stringRendered block output.

render_dropdown_menu()

Render the dropdown menu content with three sections.

private render_dropdown_menu(array<string|int, mixed> $menu_items) : string
Parameters
$menu_items : array<string|int, mixed>

Account menu items from wc_get_account_menu_items().

Return values
stringRendered dropdown menu HTML.

render_icon()

Gets the icon to render depending on the iconStyle and displayStyle.

private render_icon(array<string|int, mixed> $attributes) : string
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
stringLabel to render on the block

render_label()

Gets the label to render depending on the displayStyle.

private render_label() : string
Return values
stringLabel to render on the block.

Render the block as a simple link (default behavior).

private render_link(array<string|int, mixed> $attributes, array<string|int, mixed> $classes_and_styles, string $account_link, string $aria_label, string $label_markup) : string
Parameters
$attributes : array<string|int, mixed>

Block attributes.

$classes_and_styles : array<string|int, mixed>

Classes and styles from block attributes.

$account_link : string

URL to link to.

$aria_label : string

Pre-computed aria-label attribute string.

$label_markup : string

Pre-computed label HTML markup.

Return values
stringRendered block output.

render_menu_item()

Render a single dropdown menu item.

private render_menu_item(string $endpoint, string $label) : string
Parameters
$endpoint : string

The account endpoint key.

$label : string

The menu item label.

Return values
stringRendered menu item HTML.

render_section()

Render a dropdown section wrapping one or more menu items.

private render_section(array<string|int, mixed> $items) : string
Parameters
$items : array<string|int, mixed>

Associative array of endpoint => label pairs.

Return values
stringRendered section HTML.