Check if referenced field exists in commerce product display
If I understood your question correctly, you should check if that element exists; here's how:

if (isset($content[$my_field])) {
  //
}


This way if the field is not set, you won't get the undefined index error.