• Resolved Royah Marie

    (@hautecreations)


    Hello,
    A while ago, someone here was kind enough to provide me with a snippet that allowed for my products short description to be displayed on my packing slips. The issue is the snippet does not seem to have an affect on my packing slips anymore. Here is the snippet:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Display the product short description after the item meta (if not empty)
     */
    add_action( 'wpo_wcpdf_after_item_meta', function( $document_type, $item, $order ) {
    	if( ( $product = $item['product'] ) && method_exists( $product, 'get_short_description' ) && ( $description = $product->get_short_description() ) ) {
    		echo "<div class=\"product-description\"><small>Description: {$description}</small></div>";
    	}
    }, 10, 3 );

    Thank you in advance!

    The page I need help with: [log in to see the link]

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

    (@dpeyou)

    Hello @hautecreations,

    Is it missing on all Packing Slips or not all? This could tell us whether or not we need to update the code snippet to check for the parent ID of the product.

    • This reply was modified 2 years, 3 months ago by Darren Peyou. Reason: missing phrase
    Thread Starter Royah Marie

    (@hautecreations)

    Yes, it is missing on all packing slips.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @hautecreations,

    I do not see any document limitation on that code snippet: It should work in both the PDF invoice and packing slip.

    Maybe you have applied a CSS rule to hide it on your packing slips? If not, make sure that this code snippet is still activated on your site.

    Thread Starter Royah Marie

    (@hautecreations)

    Ok, great. Thank you for checking that the code is correct. I definitely did not add CSS to hide it but I think I identified the problem. It only seems to be a sudden issue on certain imported (third-party) orders into WooCommerce. I really appreciate your time!

    Thread Starter Royah Marie

    (@hautecreations)

    Ok so it seems that the issue is only with products with variations (nearly all my products are now this way). Should the snippet be different for product variations to grab the description from the parent products? I am now seeing that on the invoices I am seeing values from the Custom Fields in my order page (where I manage the orders). The invoices did not grab this before. Thoughts?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @hautecreations,

    You’re right, the code snippet above only works with parent products. However, I have improved the code, so the description for variations will also be displayed:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Display the product short description after the item meta (if not empty)
     * Works with parent products and their variations
     */
    add_action( 'wpo_wcpdf_after_item_meta', function( $document_type, $item, $order ) {
    	if ( $product = $item['product'] ) {
    		$product = ( $item_parent_id = $product->get_parent_id() ) ? wc_get_product( $item_parent_id ) : $product; 
    		if( method_exists( $product, 'get_short_description' ) && ( $description = $product->get_short_description() ) ) {
    			echo "<div class=\"product-description\"><small>Description: {$description}</small></div>";
    		}
    	}
    }, 10, 3 );

    Let us know if it worked!

    Thread Starter Royah Marie

    (@hautecreations)

    The good news is, I’m not crazy! Bad news is, here is the error:

    Snippet automatically deactivated due to an error on line 6:

    Syntax error, unexpected token “;”.

    So rationally, there was only one “;” so I tried deleting it. Then it told me the error was now in Line 7 with “if.” I stopped there.

    • This reply was modified 2 years, 3 months ago by Royah Marie.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Do you maybe tried to copy the code snippet from the email notification? If so, please click here to return to the WordPress.org forum and copy the code snippet from here instead.

    Unfortunately, the email notifications sent by WordPress.org does not format the code snippets correctly, therefore, can produce these kinds of errors.

    Thread Starter Royah Marie

    (@hautecreations)

    Yup, that was the problem! I copied from the email. THANK YOU!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Thanks for confirming that it is working now, @hautecreations!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

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

The topic ‘Display Product Short Description on Packing Slip’ is closed to new replies.