Automattic\WooCommerce\Internal\StockNotifications\AsyncTasks

JobManager::schedule_next_batch_for_productpublicWC 1.0

Schedule the next batch for a product.

Method of the class: JobManager{}

Returns

true|false.

Usage

$JobManager = new JobManager();
$JobManager->schedule_next_batch_for_product( $product_id ): bool;
$product_id(int) (required)
The product ID.

JobManager::schedule_next_batch_for_product() code WC 10.3.6

public function schedule_next_batch_for_product( int $product_id ): bool {

	$args = array( 'product_id' => $product_id );

	if ( $this->queue->get_next( self::AS_JOB_SEND_STOCK_NOTIFICATIONS, $args, self::AS_JOB_GROUP ) ) {
		return false;
	}

	/**
	 * Filter: woocommerce_customer_stock_notifications_next_batch_delay
	 *
	 * @since 10.2.0
	 *
	 * @param int   $delay       Delay time in seconds before next batch.
	 * @param int   $product_id  Product ID being scheduled.
	 */
	$delay = (int) apply_filters( 'woocommerce_customer_stock_notifications_next_batch_delay', 0, $product_id );
	$delay = max( 0, $delay );

	if ( 0 === $delay ) {
		$action_id = $this->queue->add(
			self::AS_JOB_SEND_STOCK_NOTIFICATIONS,
			$args,
			self::AS_JOB_GROUP
		);
	} else {
		$action_id = $this->queue->schedule_single(
			time() + $delay,
			self::AS_JOB_SEND_STOCK_NOTIFICATIONS,
			$args,
			self::AS_JOB_GROUP
		);
	}

	return ! empty( $action_id );
}