Advertisement
wpgenie

prevent displaying ended auctions if option to show PAST auctions is enabled for shortcodes

Oct 1st, 2020 (edited)
2,373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. /*
  2. - enabled option to show PAST auctions
  3. - prevent showing PAST auctions unless you are on the shop page
  4. - useful for shortcodes or widgets to prevent displaying ended auctions if option to show PAST auctions is enabled
  5. - code snippet should go to your custom plugin or functions.php file
  6.  
  7. code by Magnus
  8. */
  9.  
  10. add_filter( 'woocommerce_product_query_meta_query', 'show_only_products_with_specific_metakey', 10, 2 );
  11. function show_only_products_with_specific_metakey( $meta_query, $query ) {
  12.  
  13.   // Only on shop pages
  14.   if( ! is_shop() ) return $meta_query;
  15.  
  16.   $meta_query[] = array(
  17.     'key'   => '_auction_closed',
  18.     'compare' => 'NOT EXISTS'
  19.   );
  20.  
  21.   return $meta_query;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement