Automattic\WooCommerce\Internal\Admin\Orders

EditLock::get_lock()publicWC 1.0

Obtains lock information for a given order. If the lock has expired or it's assigned to an invalid user, the order is no longer considered locked.

Метод класса: EditLock{}

Хуки из метода

Возвращает

true|false|Массив.

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

$EditLock = new EditLock();
$EditLock->get_lock( $order );
$order(\WC_Order) (обязательный)
Order to check.

Код EditLock::get_lock() WC 8.1.1

public function get_lock( \WC_Order $order ) {
	$lock = $order->get_meta( self::META_KEY_NAME, true, 'edit' );
	if ( ! $lock ) {
		return false;
	}

	$lock = explode( ':', $lock );
	if ( 2 !== count( $lock ) ) {
		return false;
	}

	$time    = absint( $lock[0] );
	$user_id = isset( $lock[1] ) ? absint( $lock[1] ) : 0;

	if ( ! $time || ! get_user_by( 'id', $user_id ) ) {
		return false;
	}

	/** This filter is documented in WP's wp-admin/includes/ajax-actions.php */
	$time_window = apply_filters( 'wp_check_post_lock_window', 150 ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment
	if ( time() >= ( $time + $time_window ) ) {
		return false;
	}

	return compact( 'time', 'user_id' );
}