Hello,
What version and license of phpdocx are you using?
The easiest approach to accomplish this task is working with sections. You can add a header or footer to the last section using addHeaderSection or addFooterSection.
You could also use fields in headers and footers: https://wordribbon.tips.net/T008712_Using_Last-page_Headers_and_Footers.html.
Regards.