Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Product Query: allow adding more arguments by applying a filter. #6069

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions bin/hook-docs/data/filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,42 @@
},
"args": 3
},
{
"name": "woocommerce_store_api_product_query_args",
"file": "StoreApi/Utilities/ProductQuery.php",
"type": "filter",
"doc": {
"description": "Filters the arguments for the products WP_Query.",
"long_description": "",
"tags": [
{
"name": "param",
"content": "WP_Query args.",
"types": [
"array"
],
"variable": "$args"
},
{
"name": "param",
"content": "Request object.",
"types": [
"\\WP_REST_Request"
],
"variable": "$request"
},
{
"name": "return",
"content": "",
"types": [
"array"
]
}
],
"long_description_html": ""
},
"args": 2
},
{
"name": "woocommerce_variation_option_name",
"file": "StoreApi/Schemas/V1/CartItemSchema.php",
Expand Down
29 changes: 29 additions & 0 deletions docs/extensibility/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [woocommerce_store_api_disable_nonce_check](#woocommerce_store_api_disable_nonce_check)
- [woocommerce_store_api_product_quantity_limit](#woocommerce_store_api_product_quantity_limit)
- [woocommerce_store_api_product_quantity_{$value_type}](#woocommerce_store_api_product_quantity_-value_type)
- [woocommerce_store_api_product_query_args](#woocommerce_store_api_product_query_args)
- [woocommerce_variation_option_name](#woocommerce_variation_option_name)

---
Expand Down Expand Up @@ -808,6 +809,34 @@ apply_filters( 'woocommerce_store_api_product_quantity_{$value_type}', mixed $va

---

## woocommerce_store_api_product_query_args


Filters the arguments for the products WP_Query.

```php
apply_filters( 'woocommerce_store_api_product_query_args', array $args, \WP_REST_Request $request )
```

### Parameters

| Argument | Type | Description |
| -------- | ---- | ----------- |
| $args | array | WP_Query args. |
| $request | \WP_REST_Request | Request object. |

### Returns


`array`

### Source


- [StoreApi/Utilities/ProductQuery.php](../src/StoreApi/Utilities/ProductQuery.php)

---

## woocommerce_variation_option_name


Expand Down
9 changes: 8 additions & 1 deletion src/StoreApi/Utilities/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,14 @@ public function prepare_objects_query( $request ) {
$args['meta_key'] = $ordering_args['meta_key']; // phpcs:ignore
}

return $args;
/**
* Filters the arguments for the products WP_Query.
*
* @param array $args WP_Query args.
* @param \WP_REST_Request $request Request object.
* @return array
*/
return apply_filters( 'woocommerce_store_api_product_query_args', $args, $request );
}

/**
Expand Down