WooCommerce cart adding extra

tags

2019-09-16 00:04发布

问题:

I'm setting up a demo shop using WooCommerce. Everything seems fine except the cart page is adding several empty paragraph tags within the form when using the shortcode "[woocommerce_cart]".

The code generated from the shortcode looks like this in HTML when inspected:

<form method="post" action="http://organicthemes.com/demo/photographer/shopping-cart/">
<p></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<table class="shop_table cart" cellspacing="0">
</form>

You can view the page here, http://organicthemes.com/demo/photographer/shopping-cart/

I can only assume WordPress autop is screwing this up. I can't find any reason for the theme or plugin to be causing this issue. Any help would be appreciated.

Currently, I've targeted the paragraph tags as accurately as I can using CSS, but it's a sloppy fix.

回答1:

I'm not seeing the empty paragraph tags in the example page you linked to, but I can certainly vouch for seeing plenty of empty paragraph tags in my own current Woocommerce project. I've definitely noticed the issue occur in the cart forms (form-shipping.php and form-billing.php), but I know I've also seen the issue arise in other sections/facets of the shop (recent_products shortcode, for one). It seems like wp_autop() is getting applied to the whitespace in the template files themselves.

It's also kind of an undesirable fix, but removing whitespace from the template files seems to remove the empty paragraph tags. You don't have to minimize whole files, though. So far that I can tell, it seems the issue is triggered by whitespace before the closing tags of parent elements of the empty paragraph tags. But not blank lines... It's tabs or normal spaces that seem to be the catalysts.

TL;DR ::

Try removing any tabs or normal spaces that are present before the closing tags of the parent elements of the empty paragraphs.