HUSKY - Product Filter for WooCommerce

woof_products_query

[woof_products] ショートコード内で1回のみ使用します。カスタム操作のために必要です。


タクソノミーの操作については、https://products-filter.com/hook/woof_main_query_tax_relations/ をご利用ください。

パラメータ

$query_args (array) — the WP_Query arguments

ソースファイル

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 ファイルまたはカスタムプラグインに追加してください。
  • フックはフィルタリング処理中に適用され、変更は即座に反映されます。
  • コールバック関数からは常に期待される値の型を返してください。