  The evolution of protoplanetary discs embedded in stellar clusters depends on
the age and the stellar density in which they are embedded. Stellar clusters of
young age and high stellar surface density destroy protoplanetary discs by
external photoevaporation and stellar encounters. Here we consider the effect
of background heating from newly formed stellar clusters on the structure of
protoplanetary discs and how it affects the formation of planets in these
discs. Our planet formation model is build on the core accretion scenario
including pebble accretion. We synthesize planet populations that we compare to
observations. The giant planets in our simulations migrate over large distances
due to the fast type-II migration regime induced by a high disc viscosity
($\alpha=5.4 \times 10^{-3}$). Cold Jupiters (r>1 AU) originate preferably from
the outer disc, while hot Jupiters (r<0.1 AU) preferably form in the inner
disc. We find that the formation of gas giants via pebble accretion is in
agreement with the metallicity correlation, meaning that more gas giants are
formed at larger metallicity. However, our synthetic population of isolated
stars host a significant amount of giant planets even at low metallicity, in
contradiction to observations where giant planets are preferably found around
high metallicity stars, indicating that pebble accretion is very efficient in
the standard pebble accretion framework. On the other hand, discs around stars
embedded in cluster environments hardly form any giant planets at low
metallicity in agreement with observations, where these changes originate from
the increased temperature in the outer parts of the disc, which prolongs the
core accretion time-scale of the planet. We therefore conclude that the outer
disc structure and the planet's formation location determines the giant planet
occurrence rate and the formation efficiency of cold and hot Jupiters.
