wc_handle_product_end_scheduled_sale()WC 10.5.0

Handle scheduled sale end for a product.

This is the Action Scheduler callback that fires at the exact sale end time.

Хуков нет.

Возвращает

null. Ничего (null).

Использование

wc_handle_product_end_scheduled_sale( $product_id ): void;
$product_id(int) (обязательный)
Product ID.

Список изменений

С версии 10.5.0 Введена.

Код wc_handle_product_end_scheduled_sale() WC 10.8.1

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' );
}