Getting vaccinated while you're pregnant, ideally from 16 weeks up to 32 weeks, is highly effective in protecting your baby from developing whooping cough in the first few weeks of their life.
The immunity you get from the vaccine will pass to your baby through the placenta and provide passive protection for them until they are old enough to be routinely vaccinated against whooping cough at eight weeks old.
If for any reason you miss having the vaccine, you can still have it up until you go into labour. However, this is not ideal, as your baby is likely to get less protection from the vaccine. At this stage of pregnancy, having the vaccination may not directly protect your baby, but would help protect you from whooping cough and from passing it on to your baby.