Advertisement
palsushobhan

wcfm_hide_archived_products

May 12th, 2025
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. add_action('pre_get_posts', function ($query) {
  2.     if (!$query->is_main_query()) {
  3.         return;
  4.     }
  5.     if (!is_admin() && (is_shop() || is_product_category() || is_product_taxonomy() || is_product_tag() || function_exists('wcfm_is_store_page') && wcfm_is_store_page())) {
  6.         $tax_query = $query->get('tax_query') ? $query->get('tax_query') : array();
  7.         $tax_query[] = array(
  8.             'taxonomy' => 'product_visibility',
  9.             'field'    => 'slug',
  10.             'terms'    => 'archived',
  11.             'operator' => 'NOT IN',
  12.         );
  13.         $query->set('tax_query', $tax_query);
  14.     }
  15. });
  16.  
  17. add_filter( 'found_posts', function( $found_posts, $query ) {
  18.     if ( ! is_admin() && $query->is_main_query() && ( $query->is_shop() || $query->get('post_type') === 'product' && $query->is_archive() || (function_exists('wcfm_is_store_page') && wcfm_is_store_page()) ) ) {
  19.         $actual_post_count = count( $query->posts );
  20.         return $actual_post_count;
  21.     }
  22.     return $found_posts;
  23. }, 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement