Let $U$ be a nonempty open subset of $\mathbb{R}^n$. Suppose $f\in L^p(U)$ for some $p$ with $1\leq p<\infty$. By extending $f$ to be identically zero outside $U$, one has $f\in L^p(\mathbb{R}^n)$.
My question is: if one replaces $L^p$ with $W^{k,p}$ ($k\geq 1$), is the statement above still true?
You can't just choose the function to be identically zero outside $U$ in general, because this can cause the weak derivative to fail to be $L^p$ because of "bad regularity" at the boundary. For instance when $n=1$, all $W^{k,p}$ functions are actually continuous, so extending $f(x)=1$ on $(0,1)$ to be identically zero elsewhere certainly does not give a $W^{k,p}$ function. In this case the weak derivative is a delta function, which is not an $L^p$ function.
That said, a $W^{k,p}$ extension exists for certain "nice" $U$. For instance cf. Theorem 4.3 in the notes https://www.math.psu.edu/bressan/PSPDF/sobolev-notes.pdf