The CoRoT and Kepler missions have provided high-quality measurements of the frequency spectra of solar-like pulsators, enabling us to probe stellar interiors with a very high degree of accuracy by comparing the observed and modeled frequencies. However, the frequencies computed with 1D models suffer from systematic errors related to the poor modeling of the uppermost layers of stars. These biases are what is commonly named the near surface effect. The dominant effect is related to the turbulent pressure that modifies the hydrostatic equilibrium and thus the frequencies. This has already been investigated using grids of 3D RMHD simulations, which also were used to constrain the parameters of the empirical correction models. However, the effect of metallicity has not been considered so far. We study the impact of metallicity on the surface effect across the HR diagram, and provide a method for accounting for it when using the empirical correction models. We computed a grid of patched 1D stellar models with the stellar evolution code CESTAM in which poorly modeled surface layers have been replaced by averaged stratification computed with the 3D RMHD code CO5BOLD. We found that metallicity has a strong impact on the surface effect: keeping T_eff and log g constant, the frequency residuals can vary by up to a factor two. Therefore, the influence of metallicity cannot be neglected. We found that a correct way of accounting for it is to consider the surface Rosseland mean opacity. It allowed us to give a physically-grounded justification as well as a scaling relation for the frequency differences at nu_max as a function of T_eff, log g and kappa. Finally, we provide prescriptions for the fitting parameters of the correction functions. We show that the impact of metallicity through the Rosseland mean opacity must be taken into account when studying and correcting the surface effect.