wc_display_item_meta
is located in the wc-template-functions.php
file in the includes
folder of the woocommerce plugin and will take two arguments. $item
and $args
. Within the $args
you could pass in an option to disable automatically generated <p>
tags, aka "autop".
$args = array(
'autop' => false
):
if ( $im ) {
$im->display();
} else {
wc_display_item_meta( $item, $args );
}
Also if you need to further fine-tune your $args
, here's the array:
$args = array(
'before' => '<ul class="wc-item-meta"><li>',
'after' => '</li></ul>',
'separator' => '</li><li>',
'echo' => true,
'autop' => false,
'label_before' => '<strong class="wc-item-meta-label">',
'label_after' => ':</strong> ',
)
Alternative way
Still can't get it to work? then try the following function which will remove all of the tags generated for your value: (Code goes to your functions.php
file)
add_filter('woocommerce_display_item_meta', 'your_theme_custom_woocommerce_display_item_meta', 20, 3);
function your_theme_custom_woocommerce_display_item_meta($html, $item, $args)
{
$strings = array();
$html = '';
foreach ($item->get_formatted_meta_data() as $meta_id => $meta) {
$display_value = wp_strip_all_tags($meta->display_value);
$value = trim($display_value);
$strings[] = '<strong class="wc-item-meta-label">' . wp_kses_post($meta->display_key) . ':</strong> ' . $value;
}
if ($strings) {
$html = $args['before'] . implode($args['separator'], $strings) . $args['after'];
}
if ($args['echo']) {
echo $html;
} else {
return $html;
}
}
Then in your template use this:
if ( $im ) {
$im->display();
} else {
wc_display_item_meta( $item );
}
I gave the custom function, that runs on the filter hook, a priority of 20
, this might not work since you're using a plugin which might use a higher priority functions. So if this doesn't work, then try to change the priority from 20
to, let's say, 999
to make sure it runs after your plugin functions.
Another way
Still can't get it to work? Then you can use str_replace
function to remove the p
tag, like so:
$value = trim($display_value);
$value_text = str_replace(['<p>', '</p>'], ['', ''], $value);
', '
'], '', $value); in wc-template-functions.php. It removed the p tag. Thank you a lot for your supporive help. I wanted to vote up but I don't have the permission yet, sorry, and I selected your answer. Thanks again : ) – namari Sep 04 '21 at 02:33