Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions
VariationSelectorAttribute::replace_legacy_attribute_options_block
Replace legacy Attribute Options block and apply its settings to the parent attributes.
Method of the class: VariationSelectorAttribute{}
No Hooks.
Returns
Array. The replaced inner block.
Usage
// private - for code of main (parent) class only $result = $this->replace_legacy_attribute_options_block( $inner_block, $attributes ): array;
- $inner_block(array) (required)
- The inner block to replace.
- $attributes(array) (required)
- Parent block attributes, updated when attributes in the legacy Attribute Options block are found.
VariationSelectorAttribute::replace_legacy_attribute_options_block() VariationSelectorAttribute::replace legacy attribute options block code WC 10.9.1
private function replace_legacy_attribute_options_block( array $inner_block, array &$attributes ): array {
if ( 'woocommerce/add-to-cart-with-options-variation-selector-attribute-options' === $inner_block['blockName'] ) {
$legacy_attrs = $inner_block['attrs'] ?? array();
if ( array_key_exists( 'autoselect', $legacy_attrs ) && true === $legacy_attrs['autoselect'] ) {
$attributes['autoselect'] = true;
}
if ( array_key_exists( 'disabledAttributesAction', $legacy_attrs ) && 'hide' === $legacy_attrs['disabledAttributesAction'] ) {
$attributes['disabledAttributesAction'] = 'hide';
}
if ( array_key_exists( 'optionStyle', $legacy_attrs ) && 'dropdown' === $legacy_attrs['optionStyle'] ) {
$attributes['displayStyle'] = 'woocommerce/dropdown';
}
return array(
'blockName' => 'woocommerce/dropdown' === $attributes['displayStyle'] ? 'woocommerce/dropdown' : 'woocommerce/product-filter-chips',
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '',
'innerContent' => array(),
);
} elseif ( isset( $inner_block['innerBlocks'] ) && is_array( $inner_block['innerBlocks'] ) && ! empty( $inner_block['innerBlocks'] ) ) {
foreach ( $inner_block['innerBlocks'] as $key => $child_inner_block ) {
$inner_block['innerBlocks'][ $key ] = $this->replace_legacy_attribute_options_block( $child_inner_block, $attributes );
}
}
return $inner_block;
}