Hint: Try to solve first $$y_1''+ w^2 y_1 =0$$ Then try to substitute $y_2(x)=A\cos(w_0 x)+B\sin(w_0 x)$ to the original equation, and try to find $A$ and $B$. Then the complete solution will be $$y(x)=y_1(x)+y_2(x)$$ because the linearity: $$y''+w^2y=(y_1''+w^2y_1)+(y_2''+w^2y_2)=(0)+(\cos(w_0 x))=\cos(w_0 x)$$
Substituting $y_2$ into the equation we get that $$-Aw_0^2\cos(w_0 x)-Bw_0^2\sin(w_0 x)+w^2(A\cos(w_0 x)+B\sin(w_0 x))=\cos(wx)$$ $$(-Aw_0^2+Aw^2)\cos(w_0x)+(-Bw_0^2+Bw^2)\sin(w_0x)=\cos(w_0 x)$$ So we need that $$-A w_0^2+Aw^2=1$$ And $$-Bw_0^2+Bw^2=0$$
But of course, you can also use Laplace or Fourier transform, or maybe Green's method, but I think that would be an overkill.