• Resolved bradleo

    (@bradleo)


    I got this error all of a sudden
    Uncaught Error: Call to a member function get_description() on bool in /home/customer/www/coinhodlerclub.com/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()'d code:12

    this is the code I wrote

    
    function display_product_description( $atts ){
       try { $atts = shortcode_atts( array(
            'id' => get_the_id(),
        ), $atts, 'product_description' );
    
        global $product;
    
        if ( ! is_a( $product, 'WC_Product') )
            $product = wc_get_product($atts['id']);
    		
    		return $product->get_description();
    	  } catch(\Exception $e) {
    	 echo $e->getMessage();
       }
    
        
    }
    add_shortcode( 'product_description', 'display_product_description' );
    

    I’m new to developing on woocommerce and would like some examples of how to write a try catch to handle this or if else that would pass a string that says “no description” so if we have products with no descriptions it won’t throw an Uncaught Error

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Uncaught Error: Call to a member function get_description()’ is closed to new replies.