Search code examples
phpwordpresswoocommercehook-woocommerce

Show Woocommerce product pages default description for empty descriptions


Is it possible to add Woocommerce Product Default Description for all new added product pages in the backend product description area as a default text for example ( free of charge ) or a default function which will generate a certain action but only for the products who doesn't have a product description value

All that is needed is to get the description have a default added value for the new added products in the description below

enter image description here

Can anyone help in this ?

I found this which do the magic but for the product short description, but i want it to the product description itself

add_action( 'woocommerce_single_product_summary', 'bbloomer_echo_short_desc_if_empty', 21 );

function bbloomer_echo_short_desc_if_empty() {
   global $post;
   if ( empty ( $post->post_excerpt  ) ) {
      $post_excerpt = '<p class="default-short-desc">';
        $post_excerpt .= 'This is the default, global, short description.<br>It will show if <b>no short description has been entered!</b>';
        $post_excerpt .= '</p>';
      echo $post_excerpt;
   }
}

Solution

  • function woocommerce_default_description($content) {
        $empty = empty($content) || trim($content) === '';
        if(is_product() && $empty) {
            $content = 'default text content';
        }
        return $content;
    }
    add_filter( 'the_content', 'woocommerce_default_description' ); 
    
    function rmg_woocommerce_default_product_tabs($tabs) {
        if (empty($tabs['description'])) {
            $tabs['description'] = array(
                'title'    => __( 'Description', 'woocommerce' ),
                'priority' => 10,
                'callback' => 'woocommerce_product_description_tab',
            );
        }
        return $tabs;
    }
    add_filter( 'woocommerce_product_tabs', 'rmg_woocommerce_default_product_tabs' );
    

    something like above should work.