as_has_scheduled_action()WC 3.3.0

Check if there is a scheduled action in the queue but more efficiently than as_next_scheduled_action().

It's recommended to use this function when you need to know whether a specific action is currently scheduled (pending or in-progress).

Хуков нет.

Возвращает

true|false. True if a matching action is pending or in-progress, false otherwise.

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

as_has_scheduled_action( $hook, $args, $group );
$hook(строка) (обязательный)
The hook of the action.
$args(массив)
Args that have been passed to the action. Null will matches any args.
По умолчанию: null
$group(строка)
The group the job is assigned to.
По умолчанию: ''

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

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

Код as_has_scheduled_action() WC 8.7.0

function as_has_scheduled_action( $hook, $args = null, $group = '' ) {
	if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
		return false;
	}

	$query_args = array(
		'hook'    => $hook,
		'status'  => array( ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING ),
		'group'   => $group,
		'orderby' => 'none',
	);

	if ( null !== $args ) {
		$query_args['args'] = $args;
	}

	$action_id = ActionScheduler::store()->query_action( $query_args );

	return null !== $action_id;
}