How do I use php to add custom properties to docx

I am trying to prepare a docx template file with pre-inserted custom properties (Quick Part -> Fields) from a database. The file starts as an empty docx file created in MS Word.

I reviewed this question

But it does not answer my question.

My code is as follows:

$blank_DOCX_template = DATAPATH."formletter_blank_templates/blank.docx";
        
$zip = new ZipArchive;

if ($zip->open($blank_DOCX_template) == true) {
    $updatedXmlContent = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">';
    $id_num = 2;
    foreach($properties as $prop_name=>$prop_val){
         $updatedXmlContent .= '<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="'.$id_num.'" name="'.$prop_name.'"><vt:lpwstr>'.$prop_val.'</vt:lpwstr></property>';
         $id_num++;
    }
    $updatedXmlContent .= '</Properties>';

    $zip->addFromString('docProps/custom.xml', $updatedXmlContent);
    $zip->close();

}else{
    echo "could not open file";
}

Once the code has run (it produces no errors), I can look into the zip file ‘docProps/custom.xml’ and every thing looks right. The xml file exists and has the same content as a file with the same properties manually inserted through the MS Word interface, but when I open the file in MS Word the custom properties inserted from my php code do not appear.

What am I missing?