yith_wcwl_get_hidden_products

Retrieves a list of hidden products, whatever WC version is running.

Description

(array) yith_wcwl_get_hidden_products(); 

WC switched from meta _visibility to product_visibility taxonomy since version 3.0.0, forcing a split handling (Thank you, WC!)

Returns (array)

List of hidden product ids


Usage

  1. if ( !function_exists( 'yith_wcwl_get_hidden_products' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yith-woocommerce-wishlist/includes/functions.yith-wcwl.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = yith_wcwl_get_hidden_products(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/functions.yith-wcwl.php  
  1. function yith_wcwl_get_hidden_products() { 
  2. global $wpdb; 
  3. $hidden_products = array(); 
  4.  
  5. if( version_compare( WC()->version, '3.0.0', '<' ) ) { 
  6. $query = "SELECT p.ID 
  7. FROM {$wpdb->posts} AS p 
  8. LEFT JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id 
  9. WHERE meta_key = %s AND meta_value <> %s"; 
  10. $query_args = array( 
  11. '_visibility',  
  12. 'visible' 
  13. ); 
  14. else{ 
  15. $product_visibility_term_ids = wc_get_product_visibility_term_ids(); 
  16. $query = "SELECT tr.object_id  
  17. FROM {$wpdb->term_relationships} AS tr 
  18. LEFT JOIN {$wpdb->term_taxonomy} AS tt USING( term_taxonomy_id )  
  19. WHERE tt.taxonomy = %s AND tr.term_taxonomy_id = %d"; 
  20. $query_args = array( 
  21. 'product_visibility',  
  22. $product_visibility_term_ids['exclude-from-catalog']  
  23. ); 
  24.  
  25. $hidden_products = $wpdb->get_col( $wpdb->prepare( $query, $query_args ) ); 
  26. return $hidden_products;