Advertisement
palsushobhan

wcfm-hide-offline-disable-vendor-archived-products

Dec 14th, 2022
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. add_action('pre_get_posts', function($q) {
  2.     if(!$q->is_main_query()) return;
  3.     if( is_shop() || is_product_category() || is_product_taxonomy() || is_product_tag() ) {
  4.         $args = array(
  5.             'fields' => 'ID',
  6.             'meta_query' => array(
  7.                 'relation' => 'OR',
  8.                 array(
  9.                     'key' => '_disable_vendor',
  10.                     'compare'=>'EXISTS',
  11.                 ),
  12.                 array(
  13.                     'key' => '_wcfm_store_offline',
  14.                     'compare'=>'EXISTS',
  15.                 ),
  16.             ),
  17.         );
  18.         $vendors = get_users($args);
  19.         $q->set('author__not_in', $vendors);
  20.         $product_args = array(
  21.             'limit'            => -1,
  22.             'status'           => array('archived'),  
  23.             'return'           => 'ids',
  24.         );
  25.         $product_ids = wc_get_products($product_args);
  26.         $q->set('post__not_in', $product_ids);
  27.     }
  28.     return $args;
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement