Super easy fix for this one! Go to your “Customizer”, click in the top menu to “Collections”, then in the left sidebar click on “Product grid” and then change the aspect ratio!
Go to your Online store > Themes > Customize > Collections > Default collection > Product grid > Product card > Image ratio > Adapt to image > click Save
Then simply make sure all your images have the same aspect ratio. I would recommend 1:1 so an image of 2000x2000 pixels for example. The “code issue” you’re encountering is not a code issue, its a asset issue.