wc_get_product_ids_on_sale

Function that returns an array containing the IDs of the products that are on sale.

Description

(array) wc_get_product_ids_on_sale(); 

Returns (array)


Usage

  1. if ( !function_exists( 'wc_get_product_ids_on_sale' ) ) { 
  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_product_ids_on_sale(); 
  7.  

Defined (1)

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

/includes/wc-product-functions.php  
  1. function wc_get_product_ids_on_sale() { 
  2. // Load from cache 
  3. $product_ids_on_sale = get_transient( 'wc_products_onsale' ); 
  4.  
  5. // Valid cache found 
  6. if ( false !== $product_ids_on_sale ) { 
  7. return $product_ids_on_sale; 
  8.  
  9. $data_store = WC_Data_Store::load( 'product' ); 
  10. $on_sale_products = $data_store->get_on_sale_products(); 
  11. $product_ids_on_sale = wp_parse_id_list( array_merge( wp_list_pluck( $on_sale_products, 'id' ), array_diff( wp_list_pluck( $on_sale_products, 'parent_id' ), array( 0 ) ) ) ); 
  12.  
  13. set_transient( 'wc_products_onsale', $product_ids_on_sale, DAY_IN_SECONDS * 30 ); 
  14.  
  15. return $product_ids_on_sale;