📄 原始资料 | 展开查看原始 JSON(bricks-woocommerce-products_filters-options.json){ “name”: “bricks/woocommerce/products_filters/options”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-woocommerce-products_filters-options/”, “scraped_at”: “2026-08-29”, “ho…
📄 原始资料 | 展开查看原始 JSON(bricks-woocommerce-products_filters-options.json)
{
"name": "bricks/woocommerce/products_filters/options",
"kind": "filter",
"url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-woocommerce-products_filters-options/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/woocommerce/products_filters/options",
"description": {
"en": "Allows you to modify the options available in the WooCommerce Products Filter element.",
"zh": "允许你修改 WooCommerce Products Filter 元素中可用的选项。"
},
"parameters": [
{
"name": "options",
"type": "array",
"type_zh": null,
"description": {
"en": "An array of options, where each option is an associative array with id and name .",
"zh": "选项数组,每个选项是包含 id 和 name 的关联数组。"
}
},
{
"name": "settings",
"type": "array",
"type_zh": null,
"description": {
"en": "The element settings.",
"zh": "元素设置。"
}
}
],
"example_usage": "add_filter( 'bricks/woocommerce/products_filters/options', function( $options, $settings ) {\n // Add a custom \"All\" option to the beginning\n array_unshift( $options, [\n 'id' => 'all',\n 'name' => 'All Products',\n ] );\n\n\n return $options;\n}, 10, 2 );"
}
前言
允许你修改 WooCommerce Products Filter 元素中可用的选项。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/woocommerce/products_filters/options', function( $options, $settings ) {
// Add a custom "All" option to the beginning
array_unshift( $options, [
'id' => 'all',
'name' => 'All Products',
] );
return $options;
}, 10, 2 );
参数
$options (array):选项数组,每个选项是包含 id 和 name 的关联数组。
$settings (array):元素设置。
示例代码
筛选返回值
add_filter( 'bricks/woocommerce/products_filters/options', function( $options, $settings ) {
// Add a custom "All" option to the beginning
array_unshift( $options, [
'id' => 'all',
'name' => 'All Products',
] );
return $options;
}, 10, 2 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/woocommerce/products_filters/options', function( $value, $options ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。