WC_Product_Data_Store_CPT::get_on_sale_products PHP Method

get_on_sale_products() public method

Returns an array of on sale products, as an array of objects with an ID and parent_id present. Example: $return[0]->id, $return[0]->parent_id.
Since: 2.7.0
public get_on_sale_products ( ) : array
return array
    public function get_on_sale_products()
    {
        global $wpdb;
        return $wpdb->get_results("\n\t\t\tSELECT post.ID as id, post.post_parent as parent_id FROM `{$wpdb->posts}` AS post\n\t\t\tLEFT JOIN `{$wpdb->postmeta}` AS meta ON post.ID = meta.post_id\n\t\t\tLEFT JOIN `{$wpdb->postmeta}` AS meta2 ON post.ID = meta2.post_id\n\t\t\tWHERE post.post_type IN ( 'product', 'product_variation' )\n\t\t\t\tAND post.post_status = 'publish'\n\t\t\t\tAND meta.meta_key = '_sale_price'\n\t\t\t\tAND meta2.meta_key = '_price'\n\t\t\t\tAND CAST( meta.meta_value AS DECIMAL ) >= 0\n\t\t\t\tAND CAST( meta.meta_value AS CHAR ) != ''\n\t\t\t\tAND CAST( meta.meta_value AS DECIMAL ) = CAST( meta2.meta_value AS DECIMAL )\n\t\t\tGROUP BY post.ID;\n\t\t");
    }