woocommerce_products_will_display

Check if we will be showing products or not (and not sub-categories only).

Description

woocommerce_products_will_display(); 

Usage

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

Defined (1)

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

/includes/wc-template-functions.php  
  1. function woocommerce_products_will_display() { 
  2. global $wpdb; 
  3.  
  4. if ( is_shop() ) { 
  5. return 'subcategories' !== get_option( 'woocommerce_shop_page_display' ) || is_search(); 
  6.  
  7. if ( ! is_product_taxonomy() ) { 
  8. return false; 
  9.  
  10. if ( is_search() || is_filtered() || is_paged() ) { 
  11. return true; 
  12.  
  13. $term = get_queried_object(); 
  14.  
  15. if ( is_product_category() ) { 
  16. switch ( get_woocommerce_term_meta( $term->term_id, 'display_type', true ) ) { 
  17. case 'subcategories' : 
  18. // Nothing - we want to continue to see if there are products/subcats 
  19. break; 
  20. case 'products' : 
  21. case 'both' : 
  22. return true; 
  23. break; 
  24. default : 
  25. // Default - no setting 
  26. if ( get_option( 'woocommerce_category_archive_display' ) != 'subcategories' ) { 
  27. return true; 
  28. break; 
  29.  
  30. // Begin subcategory logic 
  31. if ( empty( $term->term_id ) || empty( $term->taxonomy ) ) { 
  32. return true; 
  33.  
  34. $transient_name = 'wc_products_will_display_' . $term->term_id . '_' . WC_Cache_Helper::get_transient_version( 'product_query' ); 
  35.  
  36. if ( false === ( $products_will_display = get_transient( $transient_name ) ) ) { 
  37. $has_children = $wpdb->get_col( $wpdb->prepare( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = %d AND taxonomy = %s", $term->term_id, $term->taxonomy ) ); 
  38.  
  39. if ( $has_children ) { 
  40. // Check terms have products inside - parents first. If products are found inside, subcats will be shown instead of products so we can return false. 
  41. if ( sizeof( get_objects_in_term( $has_children, $term->taxonomy ) ) > 0 ) { 
  42. $products_will_display = false; 
  43. } else { 
  44. // If we get here, the parents were empty so we're forced to check children 
  45. foreach ( $has_children as $term_id ) { 
  46. $children = get_term_children( $term_id, $term->taxonomy ); 
  47.  
  48. if ( sizeof( get_objects_in_term( $children, $term->taxonomy ) ) > 0 ) { 
  49. $products_will_display = false; 
  50. break; 
  51. } else { 
  52. $products_will_display = true; 
  53.  
  54. set_transient( $transient_name, $products_will_display, DAY_IN_SECONDS * 30 ); 
  55.  
  56. return $products_will_display;