Coming up with a function $f:X^n \rightarrow \mathbb{R}$ where $X$ is a finite set of whole numbers such that lexicographic order is preserved is straightforward:
$$f(x_1, x_2, \ldots ,x_{n-1}, x_n)=\sum_{i=1}^{n}{x_i (\max(X))^{n-i}}$$
Is it possible to come up with an similar function, but one that maps real coordinate space to hyperreal numbers while preserving "lexicographic order" ($g:\mathbb{R}^n \rightarrow {}^*\mathbb{R}$)? I ask about hyperreal numbers because it is not possible in the case of real numbers (Debreu, G. (1954). Representation of a preference ordering by a numerical function. Decision processes, 3, 159-165.) Also, I say "lexicographic order" with quotes because lexicographic order (based on my understanding) technically is an ordering of sequences of elements of a finite set, but it doesn't seem unreasonable to extend the concept to include sequences of elements of an infinite set, i.e. $$(x_1, x_2, \dots ,x_{n-1}, x_n) \leq(y_1, y_2, \ldots ,y_{n-1}, y_n) \iff (x_1<y_1) \lor ((x_1=y_1) \land ((x_2<y_2) \lor \ldots ))$$
Would something like the following work?
$$g(x_1, x_2, \ldots ,x_{n-1}, x_n)=\sum_{i=1}^{n}{x_i \omega^{n-i}}$$
Your understanding is correct; given any two partially ordered sets $(A, <_A)$ and $(B, <_B)$ we can always define the lexicographic ordering on the cartesian product $A \times B$ by $$(a_1, b_1) \leq_{\text{lex}} (a_2, b_2) \iff a_1 <_A a_2 \text{ or } (a_1 = a_2 \text{ and } b_1 <_B b_2);$$ this extends naturally to finite and infinite products of partially ordered sets, although in the case of infinite products $\leq_{\text{lex}}$ behaves slightly differently (namely, it is not a well-order).
The function $g: \mathbb R^n \to {}^*\mathbb R$ that you define indeed does the job; here are the details.
Let $\mathcal U$ be a non-principal ultrafilter on $\mathbb N$, so that ${}^* \mathbb R = \mathbb R^{\mathbb N} / \mathcal U$; note also that since $\mathcal U$ is non-principal, it contains the Fréchet filter, so all cofinite sets of $\mathbb N$ are in $\mathcal U$. Throughout, if $(a_n) \in \mathbb R^{\mathbb N}$ we denote its equivalence class in ${}^* \mathbb R$ by $[(a_n)]$. Moreover, recall that a standard number $r$ in ${}^*\mathbb R$ is given by the equivalence class of the constant sequence $(r, r, r, \dots)$, and that if $[(a_n)], [(b_n)] \in {}^*\mathbb R$, then $$[(a_n)] < [(b_n)] \iff \{n \in \mathbb N: a_n < b_n \} \in \mathcal U. \tag {$\dagger$}$$
We prove now that for all $n \in \mathbb N$ if $(x_1,x_2, \dots, x_n) \leq_{\text{lex}} (y_1, y_2, \dots, y_n)$ in $\mathbb R^n$, then $g(x_1, x_2, \dots, x_n) \leq g(y_1, y_2, \dots, y_n)$ in ${}^*\mathbb R$. We do this by strong induction on $n$; the case $n=1$ is trivial, so assume that there is $ k \in \mathbb N^{>1}$ such that the result holds for all $n \leq k$ and suppose that $(x_1, x_2 \dots, x_{k}, x_{k+1}) \leq_{\text{lex}} (y_1, y_2, \dots, y_k, y_{k+1})$. We have two main cases:
The other cases (say $x_1 = y_1$, $x_2= y_2$ and $x_3 < y_3$) follow the same argument as in the point above using the strong induction assumption.