• Resolved ptencate

    (@ptencate)


    Hi there.
    I want to display the basic native woocommerce (non-custom) product info on the pdf invoice. it concerns the size dimensions of the product. Length/width/height

    changing the weight to for instance length doesn’t work:

    <?php echo $item[‘weight’]; ?>

    to

    <?php echo $item[‘length’]; ?>

    its a variable product.

    Any quick tip that will help me ? Im looking to echo the length of a specific variant on the invoice.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    WooCommerce has a shorthand product function for getting all the dimensions, $product->get_dimensions(). This returns an array of lenght, width & height. You can also get the length separately, $product->get_length(). Note that a product may be deleted which would mean it can no longer be queried for the length, so it is advised that you check for its existence first. Here’s an example:

    
    <?php
    if (!empty($item['product'])) {
    	echo $product->get_length();
    }
    ?>
    
    Thread Starter ptencate

    (@ptencate)

    Hi

    tnx for your quick response. When i replace the following section on line 111 in the custom template it doesn’t really work out:

    <?php if( !empty( $item['weight'] ) ) : ?><dt class="weight"><?php _e( 'Weight:', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="weight"><?php echo $item['weight']; ?><?php echo get_option('woocommerce_weight_unit'); ?></dd><?php endif; ?>

    to

    <?php if( !empty( $item['product'] ) ) : ?><dt class="dimensions">DIMENSIONS: </dt><dd class="dimensions"><?php echo $product->get_dimensions(); ?></dd><?php endif; ?>

    Any tips on the exact code I can use for this?

    (sorry not code wizz)

    Plugin Contributor kluver

    (@kluver)

    Hi @ptencate,

    This should do the trick:

    <?php if( $product = $item['product'] ) : ?><dt class="dimensions">DIMENSIONS: </dt><dd class="dimensions"><?php echo $product->get_dimensions(); ?></dd><?php endif; ?>

    Let me know if this works for you. ??

    Plugin Contributor kluver

    (@kluver)

    Hi @ptencate,

    Quick follow-up. My colleague pointed out that the above code does work but is deprecated. This is the correct version:

    <?php if( $product = $item['product'] ) : ?><dt class="dimensions">DIMENSIONS: </dt><dd class="dimensions"><?php echo wc_format_dimensions( $product->get_dimensions( false ) ); ?></dd><?php endif; ?>

    Sorry for the possible confusion!

    Thread Starter ptencate

    (@ptencate)

    Perfect! Exactly how i wanted it, and even working if one or more are missing.

    Thanks a million!

    Great support.

    • This reply was modified 6 years, 4 months ago by ptencate.
    Thread Starter ptencate

    (@ptencate)

    Tnx for the edit!

    Additionally could you hint me into the direction of the code that will display:

    – Shipping Class
    – Variation Description

    Ty in advance!

    Plugin Contributor kluver

    (@kluver)

    Hi @ptencate,

    Check for a shipping class and then print it:

    if ( $term = get_term_by( 'id', $product->get_shipping_class_id(), 'product_shipping_class' ) ) {
            printf("<p class='shipping-class'>%s</p>", $term->name);
    }

    Variation description:

    $product->get_description();

    Thread Starter ptencate

    (@ptencate)

    Hiya. super tnx. Variation description working.

    if ( $term = get_term_by( 'id', $product->get_shipping_class_id(), 'product_shipping_class' ) ) {
            printf("<p class='shipping-class'>%s</p>", $term->name);
    }

    however i dont understand. Im just trying to echo it on the invoice. not a printer function. just like :

    <?php if( $product = $item['product'] ) : ?><dt class="dimensions">DIMENSIONS: </dt><dd class="dimensions"><?php echo wc_format_dimensions( $product->get_dimensions( false ) ); ?></dd><?php endif; ?>

    How would you do that?

    Plugin Contributor Ewout

    (@pomegranate)

    Exactly like Michael put it ?? (printf doesn’t send anything to the printer but it writes it to the output buffer just like echo. So you can include it in that snippet as well:

    
    <?php if( $product = $item['product'] ) : ?>
    <dt class="dimensions">DIMENSIONS: </dt><dd class="dimensions"><?php echo wc_format_dimensions( $product->get_dimensions( false ) ); ?></dd>
    <?php
    if ( $term = get_term_by( 'id', $product->get_shipping_class_id(), 'product_shipping_class' ) ) {
            printf("<p class='shipping-class'>%s</p>", $term->name);
    }
    ?>
    <?php endif; ?>
    

    or separately if you want:

    
    <?php 
    if( $product = $item['product'] ) {
        if ( $term = get_term_by( 'id', $product->get_shipping_class_id(), 'product_shipping_class' ) ) {
            printf("<p class='shipping-class'>%s</p>", $term->name);
        }
    }
    ?>
    
    Plugin Contributor kluver

    (@kluver)

    • This reply was modified 6 years, 4 months ago by kluver. Reason: duplicate
    • This reply was modified 6 years, 4 months ago by kluver.
    • This reply was modified 6 years, 4 months ago by kluver. Reason: Duplicate
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Display Product dimensions Height x Length x height’ is closed to new replies.