1

Question:
The following php code sends an email and the email result shows the following result.
Would you please let me know how to remove < p >< /p > or replace p to span?

Why I need to remove it:
I tried the css below,
but inline / inline-block only work with Gmail, not work with Outlook

Existing php code (plugin created - quote-table.php):

<div class="subtitle">
    <?php
    if ( $im ) {
    $im->display();
    } else {
    wc_display_item_meta( $item );
    }
    ?>
</div>

Email shows:

<div>
    <ul style="font-size:small;margin:0;padding:0;list-style:none">
    <li style="margin:0;padding:0">
    <strong>Type:</strong> 
    <p style="margin:0;display:inline-block;color:#8d8d8d;">Blog</p>
    </li>
    </ul>
</div>

CSS I tried (added it to the quote-table.php):
.subtitle p {
  display: inline-block;
}

Thank you.
Ruvee
  • 8,611
  • 4
  • 18
  • 44
namari
  • 129
  • 1
  • 9

1 Answers1

1

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);
Ruvee
  • 8,611
  • 4
  • 18
  • 44
  • 1
    Hi Ruvee: Thank you for your help. I tried it and it works well with all tags (eg, it changes ul, li, strong to div) , but it just doesn't change the p tag. Email still shows P tag. Would you please let me know what else can I try? Thank you. – namari Sep 04 '21 at 00:20
  • 1
    Hi Ruvee: Thanks again. I tried it, but unfortunately, result is the smae, it still shows p tag. I think $value part automatically creates p tag. I also tried both 'autop' => false / true, and both still show the p tag... wanna cry... – namari Sep 04 '21 at 01:43
  • 1
    Hi Ruvee: I got an idea from you. I change $value_text = str_replace(['

    ', '

    '], '', $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
  • 1
    Hi Ruvee: Do you remember the question about refreshing a parent page on closing a lightbox? Your code worked eventually, so I was going to select your answer but my account got closed (as I deleted my published questions for several times), so I couldn't select your answer... The only thing I could do was vote up on your asnwer... I'm sorry and I really thank you for your supportive hlep again. You are really a lifesaver : ) Have a nice weekend Ruvee : ) – namari Sep 04 '21 at 23:41