Advertisement
palsushobhan

no-vacation-products-on-shop-page

Jun 10th, 2022
1,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. add_action( 'pre_get_posts', function( $query ) {
  2.     if(!$query->is_main_query()) return;
  3.  
  4.     if( is_shop() ) {
  5.         $vacation_args = array(
  6.             'role__in'   => apply_filters( 'wcfmmp_allwoed_vendor_user_roles', array( 'wcfm_vendor' ) ),
  7.             'meta_query' => array(
  8.                 array(
  9.                     'key'     => 'wcfmmp_profile_settings',
  10.                     'value'   => ';s:18:"wcfm_vacation_mode";s:3:"yes";',
  11.                     'compare' => 'LIKE',
  12.                 )
  13.             ),
  14.             'fields' => 'ID'
  15.         );
  16.         $on_vacation = get_users( $vacation_args );
  17.         $vacation_posts = new WP_Query( array(
  18.             'post_type' => 'product',
  19.             'author__in' => $on_vacation,
  20.             'posts_per_page' => -1,
  21.             'fields' => 'ids'
  22.         ) );
  23.         $post_ids = array();
  24.         if ( $vacation_posts->have_posts() ) {
  25.             $post_ids = $vacation_posts->posts;
  26.         }
  27.         wp_reset_postdata();
  28.         $query->set( 'post__not_in', $post_ids );
  29.     }
  30. }, 100 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement