skip to Main Content

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;
   }
}

2

Answers


  1. 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.

    Login or Signup to reply.
  2. Try this:

    add_action( 'woocommerce_single_product_summary', 'bbloomer_echo_desc_if_empty', 21 );
    
    function bbloomer_echo_desc_if_empty() {
        global $post;
        if ( empty ( $post->post_content  ) ) {
            $post_description = '<p class="default-content">';
            $post_description .= 'This is the default, global, description.<br>It will show if <b>description has been entered!</b>';
            $post_description .= '</p>';
            echo $post_description;
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search