title: How to get WooCommerce product object in a custom shortcode to avoid errors
body: <p>I have a function in which i am trying to get the product short description of the current product using the product id but i keep getting Uncaught Error: Call to a member function get_short_description() on bool in</p>
  <p>I have the following shortcode function where I am trying to get the product short description of the current WooCommerce product using the product id:</p>
  <pre><code>function custom_product_description( $atts ) {
      global $product;
  
      // Shortcode attribute (or argument)
      $atts = shortcode_atts( array(
          'id'    =&gt; ''
      ), $atts, 'custom_product_description' );
  
      // If the &quot;id&quot; argument is not defined, we try to get the post Id
      if ( ! ( ! empty($atts['id']) &amp;&amp; $atts['id'] &gt; 0 ) ) {
         $atts['id'] = get_the_id();
      }
  
      // We check that the &quot;id&quot; argument is a product id
      if ( get_post_type($atts['id']) === 'product' ) {
          $product = wc_get_product($atts['id']);
      }
  
      $product_short_description = $product-&gt;get_short_description();
  
      return  $product_short_description;
  }
  </code></pre>
  <p>but I keep getting the following error: <br>
  Uncaught Error: Call to a member function get_short_description() on bool in …</p>
  <p>Any help is appreciated.</p>