How to hide or replace <dl> html tag from WooCommerce related template

Viewed 329

I've been researching how to remove/replace <dl> html tags from my Woocommerce web site for a long time, like:

<dl class = "Variation"> Starts: July 17, 2020 </dl>

I would just like to have instead (without html <dl> tags):

Starts: July 17, 2020

I have a function that redirects me to WhatsApp with the items in my cart. Everything is going well, except for this blessed <dl> tag that is displayed on WhatsApp message.

is there a way to hide it / remove it?

I'm doing this within /wp-content/plugins/woocommerce/templates/order/order-details.php

My code sends a message to Whatsapp listing the products, however I would like to hide this htlm tag <dl class… > of the message that is sent to whatsapp.

$Produtos .= "*".$item->get_quantity()."x* ".$item->get_name()."%0a%0a";
    $Produtos .= "*".$item->get_quantity()."x* ".$item->get_name()."%0a%0a - "  .wc_display_item_meta( $item, 'echo' );


I have little knowledge in php, please help me.
1 Answers

You need to make changes in a WooCommerce template file.

First read: How to override WooCommerce templates via your theme, to understand how you can make changes to some template files via your theme.

Now the templates you need to edit where <dl class ="Variation"> is located is:

Now you should be able to copy the template from woocommerce plugin to your active child theme (or active theme) folder on a woocommerce folder > cart subfolder > cart-item-data.php file

You need to respect the path (folder and subfolders hierarchy):

<?php
/**
 * Cart item data (when outputting non-flat)
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-item-data.php.
 *

Then open / edit the freshly copied template file:
You should able to change the html structure for <dl>, <dt> and <dt> html tags the desired ones (you could replace them by <ul> <li> tags, making some changes to your CSS related styles).

So basically you can replace (from line 20 to 26):

?>
<dl class="variation">
    <?php foreach ( $item_data as $data ) : ?>
        <dt class="<?php echo sanitize_html_class( 'variation-' . $data['key'] ); ?>"><?php echo wp_kses_post( $data['key'] ); ?>:</dt>
        <dd class="<?php echo sanitize_html_class( 'variation-' . $data['key'] ); ?>"><?php echo wp_kses_post( wpautop( $data['display'] ) ); ?></dd>
    <?php endforeach; ?>
</dl>

with the following:

?>
<ul class="variation">
    <?php foreach ( $item_data as $data ) : ?>
        <li class="<?php echo sanitize_html_class( 'variation-' . $data['key'] ); ?>"><?php 
             echo wp_kses_post( $data['key'] ). ': ';
             echo wp_kses_post( wpautop( $data['display'] ) ); 
        ?></li>
    <?php endforeach; ?>
</ul>

It should work… You will need to make some changes to your CSS related styles.

Related