Skip to content
Advertisement

How to get WooCommerce product object in a custom shortcode to avoid errors

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

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:

JavaScript

but I keep getting the following error:
Uncaught Error: Call to a member function get_short_description() on bool in …

Any help is appreciated.

Advertisement

Answer

To avoid this error for your custom shortcode, use the following instead:

JavaScript

Code goes in functions.php file of the active child theme (or active theme). It should work now.

USAGE:

  • Without a defined id argument on single product pages: [product_description]
  • With a defined valid product ID as argument: [product_description id="37"]
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement