0
WooCommerceではオプション「Visibility in在庫切れ」をチェックしましたが、そのオプションがチェックされていても、一部の商品カテゴリが表示されている必要があります。カテゴリの在庫切れ商品を表示する
一方、メインストアではそのカテゴリは表示されません。私はこのコードを使用しました:
add_action('pre_get_posts', 'custom_pre_get_posts_query');
function custom_pre_get_posts_query($q) {
if (! $q->is_main_query()) return;
if (! $q->is_post_type_archive()) return;
if (! is_admin() && is_shop()) {
$q->set('tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array('MYCATEGORY'), // Don't show this category.
'operator' => 'NOT IN'
)));
}
remove_action('pre_get_posts', 'custom_pre_get_posts_query');
}
これは可能でしょうか?
ありがとうございました!
これはループで使用するのですか? –
post-> IDを削除することで、関数ファイルの関数でこれを使用できるはずです。 次に、$ terms = wp_get_post_terms($ taxonomy = 'product_cat')を使用できます。 もしcontent-product.phpのようなループでそれを使ってみると、そのファイルに既に含まれているのでグローバル製品を削除することができます – assemblr
これは私に 'Warning:in_array()この行は次のようになります: '' if_in_array($ category_to_show、$ categories)&&!$ product-> is_in_stock()) ''どこがエラーですか?私はこれを見つけることができません... –