HUSKY - Product Filter for WooCommerce

woof_products_query

只在 [ 中使用 1 次woof_products] shortcode。需要进行任何自定义操作。


用于分类操作,请使用 https://products-filter.com/hook/woof_main_query_tax_relations/

参数

$query_args (array) — WP_Query 参数

源文件

index.php

代码示例


add_filter('woof_products_query', function($query_args) {
    // Exclude products with specific meta key
    $query_args['meta_query'][] = array(
        'key'     => '_exclude_from_filter',
        'compare' => 'NOT EXISTS'
    );
    
    // Only show products from specific categories
    // $query_args['tax_query'][] = array(
    //     'taxonomy' => 'product_cat',
    //     'field'    => 'slug',
    //     'terms'    => array('featured'),
    //     'operator' => 'IN'
    // );
    
    return $query_args;
});

使用说明

  • 将此代码添加到您的主题的 functions.php 文件或自定义插件中。
  • 此 hook 在过滤过程中应用——更改会立即生效。
  • 始终从回调函数返回预期的值类型。