get_results( " SELECT post.ID, post.post_parent FROM `$wpdb->posts` AS post LEFT JOIN `$wpdb->postmeta` AS meta ON post.ID = meta.post_id LEFT JOIN `$wpdb->postmeta` AS meta2 ON post.ID = meta2.post_id WHERE post.post_type IN ( 'product' ) AND post.post_status = 'publish' AND meta.meta_key = '_sale_price' AND meta2.meta_key = '_price' AND CAST( meta.meta_value AS DECIMAL ) >= 0 AND CAST( meta.meta_value AS CHAR ) != '' AND CAST( meta.meta_value AS DECIMAL ) = CAST( meta2.meta_value AS DECIMAL ) GROUP BY post.ID LIMIT 10; " ); $product_ids_on_sale = array_unique( array_map( 'absint', array_merge( wp_list_pluck( $on_sale_posts, 'ID' ), array_diff( wp_list_pluck( $on_sale_posts, 'post_parent' ), array( 0 ) ) ) ) ); set_transient( 'appmaker_wc_products_onsale', $product_ids_on_sale, 60 * 60 * 5 ); return $product_ids_on_sale; } /** * Function that returns an array containing the IDs of the featured products. * * @since 2.1 * @access public * * @param int $limit * * @return array */ static function wc_get_featured_product_ids( $limit = 10 ) { // Load from cache. $featured_product_ids = get_transient( 'appmaker_wc_featured_products_list' ); // Valid cache found. if ( false !== $featured_product_ids ) { return $featured_product_ids; } $featured = get_posts( array( 'post_type' => array( 'product' ), 'posts_per_page' => $limit, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_visibility', 'value' => array( 'catalog', 'visible' ), 'compare' => 'IN', ), array( 'key' => '_featured', 'value' => 'yes', ), ), 'fields' => 'id=>parent', ) ); $product_ids = array_keys( $featured ); $parent_ids = array_values( array_filter( $featured ) ); $featured_product_ids = array_unique( array_merge( $product_ids, $parent_ids ) ); set_transient( 'appmaker_wc_featured_products', $featured_product_ids, 60 * 60 * 5 ); return $featured_product_ids; } /** * Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339. * * Requered WP 4.4 or later. * See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/ * * @since 2.6.0 * * @param string $date * * @return string|null ISO8601/RFC3339 formatted datetime. */ static function wc_rest_prepare_date_response( $date ) { // Check if mysql_to_rfc3339 exists first! if ( ! function_exists( 'mysql_to_rfc3339' ) ) { return null; } // Return null if $date is empty/zeros. if ( '0000-00-00 00:00:00' === $date || empty( $date ) ) { return null; } // Return the formatted datetime. return mysql_to_rfc3339( $date ); } }