wc_maybe_schedule_product_sale_events()WC 10.5.0

Schedule sale events when a product is saved with sale dates.

Хуков нет.

Возвращает

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

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

wc_maybe_schedule_product_sale_events( $product_id, $product ): void;
$product_id(int) (обязательный)
Product ID.
$product(WC_Product|null)
Product object (optional).
По умолчанию: null

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

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

Код wc_maybe_schedule_product_sale_events() WC 10.8.1

function wc_maybe_schedule_product_sale_events( $product_id, $product = null ): void {
	if ( ! $product ) {
		$product = wc_get_product( $product_id );
		if ( ! $product ) {
			return;
		}
	}

	$product_id = $product->get_id();

	// Always clear existing events first.
	as_unschedule_all_actions( 'wc_product_start_scheduled_sale', array( 'product_id' => $product_id ), 'woocommerce-sales' );
	as_unschedule_all_actions( 'wc_product_end_scheduled_sale', array( 'product_id' => $product_id ), 'woocommerce-sales' );

	$date_from = $product->get_date_on_sale_from( 'edit' );
	$date_to   = $product->get_date_on_sale_to( 'edit' );

	if ( $date_from || $date_to ) {
		wc_schedule_product_sale_events( $product );
	}
}