woof_dynamic_count_attr
動的な製品再カウントクエリが実行される前に、WP_Query 引数をフィルタリングします。このフックは、動的再カウント機能が有効な場合に WOOF_HELPER::dynamic_count メソッド内で実行され、各フィルター用語に一致する製品数を決定するクエリパラメーターを変更できます。
パラメーター
$args (array) — WP_QueryWoofCounter に渡されるクエリ引数。tax_query、meta_query、post_type、およびカスタムキー wc_query と woof_query を含みます。
$custom_type (string) — 再カウントメソッドに渡されるカスタムタイプ識別子(例:タクソノミー名)。
ソースファイル
index.php, line 1902
コード例
add_filter("woof_dynamic_count_attr", function ($args, $custom_type) {
// Exclude a specific product category from counts
if (!isset($args["tax_query"])) {
$args["tax_query"] = array();
}
$args["tax_query"][] = array(
"taxonomy" => "product_cat",
"field" => "slug",
"terms" => "uncategorized",
"operator" => "NOT IN"
);
return $args;
}, 10, 2);
使用上の注意
- このコードをテーマの
functions.phpファイルまたはカスタムプラグインに追加してください。 - クエリには、すでにカタログの可視性 tax_query と
WOOF_REQUESTからの現在のフィルター tax_query/meta_query が含まれています。 - 2つのパラメーターを受け入れます — 関数シグネチャで
$a, $bを宣言することを忘れないでください。