Product_Collection implements Standard_Service, Registerable
Handles product collection filtering functionality.
This service is used to filter the products in a product collection block powered by WooCommerce.
Tags
Interfaces, Classes and Traits
- Standard_Service
- Registerable
Table of Contents
- $processing_wcf_query : bool
- Flag to prevent recursive calls during WCF query processing.
- $query_store : array<string|int, mixed>|null
- The captured query array.
- capture_collection_query() : WP_Query
- Capture the collection query.
- enqueue_scripts() : void
- Enqueue the necessary scripts.
- get_captured_query() : WP_Query
- Get the captured query.
- init() : void
- Initialize the WCF product filter.
- modify_posts_clauses() : array<string|int, mixed>
- Modify the posts clauses to filter by WCF product IDs.
- modify_product_collection_class() : string
- Modify the product collection block content to add custom class.
- register() : void
- Register the service.
- requires_rendering() : bool
- Check if the search requires rendering.
- set_query_args() : void
- Set query arguments for product collection requests.
- has_product_collection() : bool
- Check if the current page has a product collection.
- is_product_collection_request() : bool
- Check if the request is a product collection request.
Properties
$processing_wcf_query
Flag to prevent recursive calls during WCF query processing.
private
static bool
$processing_wcf_query
= false
$query_store
The captured query array.
private
static array<string|int, mixed>|null
$query_store
= null
Methods
capture_collection_query()
Capture the collection query.
public
capture_collection_query(WP_Query $query, WP_Block $block, int $page) : WP_Query
Parameters
- $query : WP_Query
-
The query object.
- $block : WP_Block
-
The block object.
- $page : int
-
The page number.
Return values
WP_Query —The modified query object.
enqueue_scripts()
Enqueue the necessary scripts.
public
enqueue_scripts() : void
Return values
void —get_captured_query()
Get the captured query.
public
static get_captured_query() : WP_Query
Return values
WP_Query —The captured query.
init()
Initialize the WCF product filter.
public
init() : void
Return values
void —modify_posts_clauses()
Modify the posts clauses to filter by WCF product IDs.
public
modify_posts_clauses(array<string|int, mixed> $clauses, WP_Query $query) : array<string|int, mixed>
Parameters
- $clauses : array<string|int, mixed>
-
The posts clauses.
- $query : WP_Query
-
The query object.
Return values
array<string|int, mixed> —The modified clauses.
modify_product_collection_class()
Modify the product collection block content to add custom class.
public
modify_product_collection_class(string $block_content, array<string|int, mixed> $block) : string
Parameters
- $block_content : string
-
The block content.
- $block : array<string|int, mixed>
-
The block data.
Return values
string —The modified block content.
register()
Register the service.
public
register() : void
Return values
void —requires_rendering()
Check if the search requires rendering.
public
requires_rendering(bool $requires_rendering, WP_REST_Request $request) : bool
Parameters
- $requires_rendering : bool
-
Whether the search requires rendering.
- $request : WP_REST_Request
-
The REST request object.
Return values
bool —Whether the search requires rendering.
set_query_args()
Set query arguments for product collection requests.
public
set_query_args(WP_REST_Request $request, Search_Api $search_api) : void
This is used to pass the query arguments from the product collection block to the search API. So that filters have the same context as the product collection block.
Parameters
- $request : WP_REST_Request
-
The REST request object.
- $search_api : Search_Api
-
The search API object.
Return values
void —has_product_collection()
Check if the current page has a product collection.
private
has_product_collection() : bool
Return values
bool —True if the page has a product collection.
is_product_collection_request()
Check if the request is a product collection request.
private
is_product_collection_request(WP_REST_Request $request) : bool
Parameters
- $request : WP_REST_Request
-
The REST request object.
Return values
bool —True if it's a product collection request.