Hi,
I think you're right that you can't buy international train tickets on the Portuguese website. But you should be fine with a couple days' advance purchase once you are actually in Portugal. I did a lot of train-riding last year when I was walking different segments of the Camino Portugues from Lisbon and never had a problem getting on at the last minute, even when I wanted to get on the high speed Lisbon-Porto train.
It sounds like you're arriving in Porto, and then going down to Coimbra. The train station in Porto is very centrally located, I'd just go there and buy the Coimbra-Irun ticket at the same time you get the ticket from Porto to Coimbra.
And just one thing about the Coimbra train station. There are actually two of them, and this long distance train leaves from "Coimbra B," which is a few km outside of town. When you buy your ticket, you will be given a time that shows departure from "Coimbra A", which is right in downtown, you'll take whatever local train is leaving around that time and will get off about 3 minutes later at Coimbra B where you wait for your train to Irun. (same thing, of course, when you're coming into Coimbra from Porto -- you should check to see whether your train stops at Coimbra A -- if it doesn't, get off at Coimbra B and hop on the train that is likely to be waiting there for you).
Laurie