Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: style issue on WC item meta when using dd #29

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions wcpdf-mpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,37 @@ 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 <strong> with <span class="label">
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 <dd> or <p> to the <p> element
elseif ( $child->nodeType === XML_ELEMENT_NODE && in_array( strtolower( $child->nodeName ), array( 'dd', 'p' ) ) ) {
foreach ( $child->childNodes as $grandchild ) {
$importedNode = $ul->ownerDocument->importNode( $grandchild, true );
$p->appendChild( $importedNode );
}
}
// Handle all other nodes (including text nodes)
else {
$importedNode = $ul->ownerDocument->importNode( $child, true );
$p->appendChild( $importedNode );
}
}

// Append the <p> to the <div>
$div->appendChild( $p );
}
$div->appendChild( $p );
}

// Replace the <ul> with the new <div>
$ul->parentNode->replaceChild( $div, $ul );
}
} );
Expand Down