• Firstly, I don’t code. I’m using Elementor and Woocommerce and I wanted to place product dimensions on a product single template the way I wanted, not the way the editors allowed me to.
    I found this simple code snippet, added it to functions.php, then pasted the function name with the php tags into plugin’s shortcode editor, then added the shortcode to the Elementor shortcode widget and hit update.
    Everything looks great, the dimensions are displayed on the front-end, but when I reload the product single template in Elementor, it gives me an “error 500”. On the debug page it says this:
    Fatal error: Uncaught Error: Call to a member function has_dimensions() on null
    If I use the shortcode in Gutenberg, the same error occurs.

    I’ve used your plugin with a standard Woocommerce function “<?php woocommerce_breadcrumb(); ?>” and it works perfectly, without any errors.

    What am I doing wrong?

    Here’s the code that is used for the shortcode:

    function show_dimensions() {
       global $product;
       $dimensions = $product->get_dimensions();
       if ( ! empty( $dimensions ) ) {
          echo '<div class="dimensions"><b>Height:</b> ' . $product->get_height() . get_option( 'woocommerce_dimension_unit' );
          echo '<br><b>Width:</b> ' . $product->get_width() . get_option( 'woocommerce_dimension_unit' );
          echo '<br><b>Length:</b> ' . $product->get_length() . get_option( 'woocommerce_dimension_unit' );
          echo '</div>';        
       }
    }
    • This topic was modified 2 years, 2 months ago by amikor.
  • The topic ‘Shortcode works on frontend, but gives a 500 error in Elementor’ is closed to new replies.