wc_handle_product_start_scheduled_sale()
Handle scheduled sale start for a product.
This is the Action Scheduler callback that fires at the exact sale start time.
Хуков нет.
Возвращает
void. Ничего (null).
Использование
wc_handle_product_start_scheduled_sale( $product_id ): void;
- $product_id(int) (обязательный)
- Product ID.
Список изменений
| С версии 10.5.0 | Введена. |
Код wc_handle_product_start_scheduled_sale() wc handle product start scheduled sale WC 11.2.2
function wc_handle_product_start_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;
}
// Verify sale should still start (dates/price might have changed since scheduling).
if ( ! $product->get_sale_price( 'edit' ) ) {
return;
}
$now = time();
$date_from = $product->get_date_on_sale_from( 'edit' );
$date_to = $product->get_date_on_sale_to( 'edit' );
if ( $date_from && $date_from->getTimestamp() > $now ) {
return;
}
if ( $date_to && $date_to->getTimestamp() < $now ) {
return;
}
if ( (float) $product->get_price( 'edit' ) === (float) $product->get_sale_price( 'edit' ) ) {
return;
}
wc_apply_sale_state_for_product( $product, 'start' );
}