Yes, you can certainly do that. This is a very common issue, well except for the dog part (maybe). I usually have to replace some on machinery monthly, and it doesn't hurt to have a few spare laying around.
Replacing these is fairly simple and straight forward, for a simple item such as a heater, something common in a household, you really only need to focus normally on whether this is polarized or not, as previously mentioned. If it has a ground, then you need a plug with a ground. However, if you're using this replacement on something that requires more amps, you'll need to be a little more picky with what you're getting, to make sure you get the correct plug rated for the amount of amps required.
Looking at the picture you posted, you probably need something like this:
Link at amazon
You can view a brief explanation of the steps to take on this "guide" by the Home Depot: https://www.homedepot.com/c/five_steps_to_replace_a_plug_on_a_power_cord_in_25_minutes_HT_PG_EL
Although this does not show a polarized plug, you'll see how straight forward the process is: