简体   繁体   English

我想使用 Post Id 从商店页面隐藏 woocommerce 产品

[英]I want to hide woocommerce products from shop page using Post Id's

I am trying to hide the woo-commerce product from the shop page using Post Id's .我正在尝试使用 Post Id 从商店页面隐藏 woo-commerce 产品 There were many different methods to hide from the shop page like product_cat etc.有许多不同的方法可以从商店页面隐藏,例如product_cat等。

I want to hide the specific products from the shop page by passing the specific product id/ post id !!我想通过传递特定的产品 ID/帖子 ID 来隐藏商店页面中的特定产品!!

Try following: using "pre_get_posts" hook尝试以下操作:使用“pre_get_posts”挂钩

<?php

add_action( 'pre_get_posts', 'erginous_exclude_id' );

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( 'post__not_in', array(70, 53) ); // Replace 70 and 53 with your products IDs. Separate each ID with a comma.
  
  }

  remove_action( 'pre_get_posts', 'erginous_exclude_id' );

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM