Automattic\WooCommerce\Blocks\BlockTypes
ProductCollection::initialize()
Initialize this block type.
- Hook into WP lifecycle.
- Register the block with WordPress.
- Hook into pre_render_block to update the query.
Метод класса: ProductCollection{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->initialize();
Код ProductCollection::initialize() ProductCollection::initialize WC 9.5.1
protected function initialize() { parent::initialize(); // Update query for frontend rendering. add_filter( 'query_loop_block_query_vars', array( $this, 'build_frontend_query' ), 10, 3 ); add_filter( 'pre_render_block', array( $this, 'add_support_for_filter_blocks' ), 10, 2 ); // Update the query for Editor. add_filter( 'rest_product_query', array( $this, 'update_rest_query_in_editor' ), 10, 2 ); // Extend allowed `collection_params` for the REST API. add_filter( 'rest_product_collection_params', array( $this, 'extend_rest_query_allowed_params' ), 10, 1 ); // Provide location context into block's context. add_filter( 'render_block_context', array( $this, 'provide_location_context_for_inner_blocks' ), 11, 1 ); // Disable block render if the ProductTemplate block is empty. add_filter( 'render_block_woocommerce/product-template', function ( $html ) { $this->render_state['has_results'] = ! empty( $html ); return $html; }, 100, 1 ); // Enable block render if the ProductCollectionNoResults block is rendered. add_filter( 'render_block_woocommerce/product-collection-no-results', function ( $html ) { $this->render_state['has_no_results_block'] = ! empty( $html ); return $html; }, 100, 1 ); // Interactivity API: Add navigation directives to the product collection block. add_filter( 'render_block_woocommerce/product-collection', array( $this, 'handle_rendering' ), 10, 2 ); add_filter( 'render_block_core/query-pagination', array( $this, 'add_navigation_link_directives' ), 10, 3 ); add_filter( 'render_block_core/post-title', array( $this, 'add_product_title_click_event_directives' ), 10, 3 ); add_filter( 'posts_clauses', array( $this, 'add_price_range_filter_posts_clauses' ), 10, 2 ); // Disable client-side-navigation if incompatible blocks are detected. add_filter( 'render_block_data', array( $this, 'disable_enhanced_pagination' ), 10, 1 ); $this->register_core_collections(); }