diff --git a/wcpdf-mpdf.php b/wcpdf-mpdf.php index f944294..8b11f4d 100644 --- a/wcpdf-mpdf.php +++ b/wcpdf-mpdf.php @@ -184,13 +184,39 @@ function wpo_wcpdf_mpdf_modify_html( $html, $document ) { $div = $ul->ownerDocument->createElement( 'div' ); $div->setAttribute( 'class', 'wc-item-meta' ); - foreach ( $ul->getElementsByTagName( 'li' ) as $li ) { - $p = $ul->ownerDocument->createElement( 'p' ); - while ( $li->firstChild ) { - $p->appendChild( $li->firstChild ); + foreach ( $ul->childNodes as $li ) { + if ( $li->nodeType === XML_ELEMENT_NODE && 'li' === strtolower( $li->nodeName ) ) { + $p = $ul->ownerDocument->createElement( 'p' ); + + foreach ( $li->childNodes as $child ) { + // Replace with + if ( $child->nodeType === XML_ELEMENT_NODE && 'strong' === strtolower( $child->nodeName ) ) { + $span = $ul->ownerDocument->createElement( 'span', $child->textContent ); + $span->setAttribute( 'class', 'label' ); + $p->appendChild( $span ); + } + + // Append content of
or

to the

element + elseif ( $child->nodeType === XML_ELEMENT_NODE && in_array( strtolower( $child->nodeName ), array( 'dd', 'p' ) ) ) { + foreach ( $child->childNodes as $grandchild ) { + $clonedNode = $grandchild->cloneNode( true ); + $p->appendChild( $clonedNode ); + } + } + + // Handle all other nodes (including text nodes) + else { + $clonedNode = $child->cloneNode( true ); + $p->appendChild( $clonedNode ); + } + } + + // Append the

to the

+ $div->appendChild( $p ); } - $div->appendChild( $p ); } + + // Replace the
    with the new
    $ul->parentNode->replaceChild( $div, $ul ); } } );