What I've described in my previous post was how those official foreign tours the British royals take on as representatives of the Queen. Its not up to the royals themselves to pick and choose. A government of country will request a visit to the government of the UK's Foreign Office and then the request given to the Queen, herself, and from there, they decide who fits the bill the best to do the visit. The Queen no longer does any foreign travel or tours so she sends a representative(s).
A lot of times, things will be planned to include more than the "official" representative roles. For example, Harry and Meghan's recent tour of Down Under. Harry was slated to be in Australia even before they announced an engagement because of his involvement with the Invictus Games (which is under the umbrella of the Royal Foundation of the Duke and Duchess of Cambridge and The Duke and Duchess of Sussex). This wasn't part of the "official" tour and in fact, the "official" tour part came about as it made sense if Harry and Meghan were going to be Down Under, why not make the most of it.
In the case you presented of William attending a wedding and also meeting with a president, I think that its more of grabbing an opportunity rather than cheating the system. William is going to (for example) Tasmania for a friend's wedding. Like with Harry and Meghan, it provides an opportunity to also have a "soft diplomacy" meeting with the president of Tasmania. Making the best of the time allowed.
This happens all the time. The finances of it all is worked out. One thing though is that all the British royals consider what they do for the Queen or for their charities and organizations as "work" and are funded as such. They, also, are not above for paying their own way for their own private travels. Everything though that is "work" is itemized and accounted for and made public each year.
One thing too that needs to be remembered is that with these British royals being full time working for the "Firm" and their charities, they do *not* get a paycheck at all from anywhere. They work for free. That's why the Queen has the Sovereign Grant and why The Prince of Wales subsidizes the work the Cambridges and the Sussexes do (along with their office and staff) from his income from the Duchy of Cornwall.
And.....the Queen and The Prince of Wales pay income tax on their private income (the Queen's is the Duchy of Lancaster).
I'm no expert at all of this and there are many here on these forums that know much more than I do and will correct me if I'm wrong on anything. I depend on that. Its how I check off my "learn something new everyday" box.
So... ask yourself a question. How many people do you know that would do the kind of things these royals do without a paycheck? Most people still believe that the British royal family gets money from a Civil List (or in other countries it would be called an apanage). Wouldn't it make sense that they do take advantage of what works to allow them to do what they do? At the end of the day, they work a lot for crown and country and its people but don't charge them a dime.