2

I want to hide the "Description" heading of the WooCommerce product whenever the product's long description field is empty.

enter image description here

I've tried this:

// Remove Empty Tabs
add_filter( 'woocommerce_product_tabs', 'yikes_woo_remove_empty_tabs', 20, 1 );

function yikes_woo_remove_empty_tabs( $tabs ) {

if ( ! empty( $tabs ) ) {
    foreach ( $tabs as $title => $tab ) {
            if ( empty( $tab['content'] ) && strtolower( $tab['title'] ) !== 'description' ) {
                unset( $tabs[ $title ] );
            }
        }
    }
    return $tabs;
}

But that doesn't end up hiding the heading. This heading doesn't appear to be an actual tab.

It looks like this in the rendered source:

<div class="product-description">
    <h3 class="summary-description-title">Description</h3>
</div>
Ruvee
  • 8,611
  • 4
  • 18
  • 44
user3169905
  • 199
  • 3
  • 19
  • Please include your `html template`, or explain which theme you're using, or at least, explain which page it's on. Is it on the `single product` page or on the `shop` page or on the `archive` page? – Ruvee Nov 08 '21 at 21:04
  • Theme is WP Rig. HTML template is just the default WooCommerce for the single product view. – user3169905 Nov 08 '21 at 22:58

1 Answers1

6

That is a "tab" created by woocommerce. So you could check whether it has content or not, if not, then you could unset it. Like this:

add_filter('woocommerce_product_tabs', 'your_them_manipulating_description_tab', 99);

function your_them_manipulating_description_tab($tabs)
{
  global $product;

  $product_description = $product->get_description();

  if (!$product_description) 
  {
    unset($tabs['description']);
  }
  return $tabs;
}

It works on my end, let me know if you could get it to work too!

Ruvee
  • 8,611
  • 4
  • 18
  • 44
  • Thanks. I implemented your code in my theme's functions.php. But it still didn't remove the Description tab. I've disabled all plugins and the same result. When I switch to Storefront, the problem goes away on its own without this code. I'm struggling to know where else to troubleshoot to figure out why. – user3169905 Nov 09 '21 at 14:09
  • Update: I found that a WP Rig Component.php file was controlling this and not WooCommerce templates. I've applied the parts of your code that made sense to add to that Component.php file and the problem is fixed. Thanks! – user3169905 Nov 09 '21 at 14:18