wc_get_product_ids_on_sale()
Function that returns an array containing the IDs of the products that are on sale.
No Hooks.
Return
Array
.
Usage
wc_get_product_ids_on_sale();
Changelog
Since 2.0 | Introduced. |
wc_get_product_ids_on_sale() wc get product ids on sale code WC 9.7.1
function wc_get_product_ids_on_sale() { // Load from cache. $product_ids_on_sale = get_transient( 'wc_products_onsale' ); // Valid cache found. if ( false !== $product_ids_on_sale ) { return $product_ids_on_sale; } $data_store = WC_Data_Store::load( 'product' ); $on_sale_products = $data_store->get_on_sale_products(); $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 ) ) ) ); set_transient( 'wc_products_onsale', $product_ids_on_sale, DAY_IN_SECONDS * 30 ); return $product_ids_on_sale; }