wc_handle_product_end_scheduled_sale()
Handle scheduled sale end for a product.
This is the Action Scheduler callback that fires at the exact sale end time.
No Hooks.
Returns
null. Nothing (null).
Usage
wc_handle_product_end_scheduled_sale( $product_id ): void;
- $product_id(int) (required)
- Product ID.
Changelog
| Since 10.5.0 | Introduced. |
wc_handle_product_end_scheduled_sale() wc handle product end scheduled sale code WC 10.7.0
function wc_handle_product_end_scheduled_sale( $product_id ): void {
$product = wc_get_product( $product_id );
if ( ! $product ) {
return;
}
// Skip product types with derived prices.
if ( $product->is_type( array( 'variable', 'grouped' ) ) ) {
return;
}
$now = time();
$date_to = $product->get_date_on_sale_to( 'edit' );
if ( $date_to && $date_to->getTimestamp() > $now ) {
return;
}
if ( (float) $product->get_price( 'edit' ) === (float) $product->get_regular_price( 'edit' ) ) {
return;
}
wc_apply_sale_state_for_product( $product, 'end' );
}