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).
Method of the class: AddToCartWithOptions{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->enqueue_assets( $attributes, $content, $block );
- $attributes(array) (required)
- Block attributes.
- $content(string) (required)
- Block content.
- $block(WP_Block) (required)
- Block instance.
AddToCartWithOptions::enqueue_assets() AddToCartWithOptions::enqueue assets code WC 10.5.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 ) {
$template_part_path = $this->get_template_part_path( $rendered_product->get_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 );
}