Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions
AddToCartWithOptions::enqueue_assets
Enqueue assets specific to this block. We enqueue frontend scripts only if the product type has a block template part (that's WC core product types and extensions that migrated to block templates).
Метод класса: AddToCartWithOptions{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->enqueue_assets( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block) (обязательный)
- Block instance.
Код AddToCartWithOptions::enqueue_assets() AddToCartWithOptions::enqueue assets WC 11.3.0
protected function enqueue_assets( $attributes, $content, $block ) {
$product_id = ( is_object( $block ) && property_exists( $block, 'context' ) && is_array( $block->context ) && array_key_exists( 'postId', $block->context ) ) ? $block->context['postId'] : null;
if ( isset( $product_id ) ) {
$rendered_product = wc_get_product( $product_id );
if ( $rendered_product instanceof \WC_Product ) {
$product_type = $this->get_product_type_for_add_to_cart_template( $rendered_product );
$template_part_path = $this->get_template_part_path( $product_type );
if ( is_string( $template_part_path ) && '' !== $template_part_path && file_exists( $template_part_path ) ) {
wp_enqueue_script_module( 'woocommerce/add-to-cart-with-options' );
}
}
}
parent::enqueue_assets( $attributes, $content, $block );
}