前言
修改 Bricks 中已注册的图标库。默认情况下,Bricks 提供 SVGFluent 和 Thumbs 库。你可通过此筛选器注册你自己的图标库。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/filter_element/data_source_wcField', function( $data_source, $element ) {
// Example: Add a custom option to a WooCommerce filter
// Note: You might need to check $element->settings to target specific WC fields
if ( isset( $element->settings['sourceFieldType'] ) && $element->settings['sourceFieldType'] === 'stock_status' ) {
// Modify stock status options
}
return $data_source;
}, 10, 2 );
参数
$data_source(array):筛选选项数组。$element(object):筛选元素实例。
示例代码
筛选返回值
add_filter( 'bricks/filter_element/data_source_wcField', function( $data_source, $element ) {
// Example: Add a custom option to a WooCommerce filter
// Note: You might need to check $element->settings to target specific WC fields
if ( isset( $element->settings['sourceFieldType'] ) && $element->settings['sourceFieldType'] === 'stock_status' ) {
// Modify stock status options
}
return $data_source;
}, 10, 2 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/filter_element/data_source_wcField', function( $value, $data_source ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。