`). * * @param array $item Selectable item from context. * @return string */ private function get_option_text( array $item ): string { if ( isset( $item['label'] ) && is_string( $item['label'] ) ) { return $item['label']; } if ( ! empty( $item['ariaLabel'] ) && is_string( $item['ariaLabel'] ) ) { return $item['ariaLabel']; } return ''; } /** * Render the block. * * @param array $attributes Block attributes. * @param string $content Block content. * @param \WP_Block $block Block instance. * @return string Rendered block type output. */ protected function render( $attributes, $content, $block ) { if ( empty( $block->context['woocommerce/selectableItems'] ) ) { return ''; } $selectable_items = $block->context['woocommerce/selectableItems']; $items = is_array( $selectable_items['items'] ?? null ) ? $selectable_items['items'] : array(); $store_namespace = is_string( $selectable_items['storeNamespace'] ?? null ) ? $selectable_items['storeNamespace'] : 'woocommerce/add-to-cart-with-options'; if ( empty( $items ) ) { return ''; } $attribute_id = $block->context['woocommerce/attributeId'] ?? ''; $has_external_label = is_string( $attribute_id ) && '' !== $attribute_id; $select_id = $has_external_label ? $attribute_id : wp_unique_id( 'wc-block-dropdown-' ); $wrapper_attributes = array( 'class' => 'wc-block-dropdown', 'data-wp-interactive' => 'woocommerce/dropdown', 'data-wp-context' => (string) wp_json_encode( array( 'storeNamespace' => $store_namespace, ), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ), ); $aria_label = isset( $selectable_items['groupLabel'] ) && is_string( $selectable_items['groupLabel'] ) ? $selectable_items['groupLabel'] : __( 'Choose an option', 'woocommerce' ); ob_start(); ?>
>