• Resolved amikor

    (@amikor)


    Hi,

    I added this code to my functions.php:

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

    Then I added this snippet to the editor of the plugin:
    show_dimensions(); ?>

    And nothing is displaying in the front-end where I’m using the shortcode.
    I tried this with other plugins and they worked on front-end, but gave me a 500 error in the WP editor. Now I can’t even get to the 500 error ??

Viewing 1 replies (of 1 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @amikor,

    You’re likely not getting a 500 error because WPCode is attempting to catch the error. Regarding why the shortcode is not working, my first guess would be that the global $product you are trying to use there is not populated so you’re trying to access an object that doesn’t exist. Are you using this on the single page of a product?

    You can probably add a check there to make sure the $product is a WooCommerce product to clear things up, something like:

    
    	if ( ! $product instanceof WC_Product ) {
    		return;
    	}
    
Viewing 1 replies (of 1 total)
  • The topic ‘Added function to functions.php, called function in snippet, not working’ is closed to new replies.