WC_Product_Data_Store_CPT::get_ending_sales
Returns an array of IDs of products that have sales which are due to end.
Paired with get_starting_sales(), which excludes on this same _sale_price_dates_to test, so keep the two identical: narrowing this alone strands a product in neither queue, broadening it alone brings the daily churn back. > 0 compares numerically, which is what makes '' and '0000-00-00' read as "no end date"; < %s compares as strings. Do not bind one as %d.
The two do not share a timestamp: each reads the clock when it runs. What makes that safe is the order, not the text. wc_scheduled_sales() runs starting first, so this query's now is the later one, and anything already ended there is still ended here. Reversing that order would strand exactly what the pairing is meant to prevent.
Method of the class: WC_Product_Data_Store_CPT{}
No Hooks.
Returns
array.
Usage
$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT(); $WC_Product_Data_Store_CPT->get_ending_sales();
Changelog
| Since 3.0.0 | Introduced. |
WC_Product_Data_Store_CPT::get_ending_sales() WC Product Data Store CPT::get ending sales code WC 11.2.2
public function get_ending_sales() {
global $wpdb;
// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery
return $wpdb->get_col(
$wpdb->prepare(
"SELECT postmeta.post_id FROM {$wpdb->postmeta} as postmeta
LEFT JOIN {$wpdb->postmeta} as postmeta_2 ON postmeta.post_id = postmeta_2.post_id
LEFT JOIN {$wpdb->postmeta} as postmeta_3 ON postmeta.post_id = postmeta_3.post_id
WHERE postmeta.meta_key = '_sale_price_dates_to'
AND postmeta_2.meta_key = '_price'
AND postmeta_3.meta_key = '_regular_price'
AND postmeta.meta_value > 0
AND postmeta.meta_value < %s
AND postmeta_2.meta_value != postmeta_3.meta_value",
time()
)
);
}