Thats right buns. You get a PAC code, take it to any service provider you want (in your case an O2 shop), choose new phone, tell them "Gimme one of these and here's a PAC code so you can transfer my number"
They will give you the phone, and for a little while (maybe upto 7 days) it'll use the new number, then one morning when you turn it on it'll have changed over to the old number.
Whoever you get the new phone from (and gave the PAC code to) does all the work of cancelling of your old contract with O2 Online, etc, you do nothing more than just ask for the PAC code in the first place.
Once your phones changed and is using your old number cancel the direct debit to O2 online immediately.
The network sends a code to the phone to update its number, but this will only happen when you turn the phone off and on so I suggest for the first week turning the new phone off every night whilst you're ZZZzzzzZZZ ing

until the number changes.
PAC codes are olny valid for 30 or so days, after that you'll have to ask for a new one.
For anyone wanting to port their number, NEVER cancel your contract, if you do that you've just lost your old number forever. JUST ask for a PAC code and then go get your new phone/contract and give the PAC code to the place you got new phone from.