wc_get_featured_product_ids

Function that returns an array containing the IDs of the featured products.

Description

(array) wc_get_featured_product_ids(); 

Returns (array)


Usage

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

Defined (1)

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

/includes/wc-product-functions.php  
  1. function wc_get_featured_product_ids() { 
  2. // Load from cache 
  3. $featured_product_ids = get_transient( 'wc_featured_products' ); 
  4.  
  5. // Valid cache found 
  6. if ( false !== $featured_product_ids ) 
  7. return $featured_product_ids; 
  8.  
  9. $data_store = WC_Data_Store::load( 'product' ); 
  10. $featured = $data_store->get_featured_product_ids(); 
  11. $product_ids = array_keys( $featured ); 
  12. $parent_ids = array_values( array_filter( $featured ) ); 
  13. $featured_product_ids = array_unique( array_merge( $product_ids, $parent_ids ) ); 
  14.  
  15. set_transient( 'wc_featured_products', $featured_product_ids, DAY_IN_SECONDS * 30 ); 
  16.  
  17. return $featured_product_ids;