Search code examples
wordpresswoocommercehook-woocommerce

Woocommerce: Remove the product description depending on specific content


I am looking for a way(hook) to hide a complete product description in woocommerce if it contains a specific text like "no description available".


Solution

  • It sounds to me like what you're looking for is something along these lines:

    add_filter( 'woocommerce_short_description', function( $description ){
       if( false !== strpos( $description, 'no description available' ) ){
          return '';
       }
       return $description;
    });
    

    In other words - anytime the short description is displayed - check if it contains your string, and if so - return an empty string. Does that capture what you needed?