• Resolved callachic

    (@callachic)


    Hi, thanks for this great plugin!

    I’m trying to use your plugin for my new website. However I need to display Custom Product Attribute that I’ve set in each product (These can normally be seen under “Additional Information” tabs) in the Invoice. I see that the invoice already includes the product weight, which is great. But I need it to be able to display the custom attributes that I’ve also set..

    May I know how do I do that? Preferably without using the pro version of the plugin ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @callachic

    In fact with the Premium Templates extension is very easy and doesn’t require additional code, but you should be able to achieve that with an action hook too. Please try this:

    add_action('wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_custom_attribute', 10, 3);
    function wpo_wcpdf_show_custom_attribute($document_type, $item, $order)
    {
    	if( !empty($order) && $document_type == 'invoice' ) {
    		$product = wc_get_product($item['product_id']);
    		$attributes = $product->get_attributes();
    		foreach( $attributes as $type => $attribute ) {
    			if( $type == 'my-custom-attribute' ) { // attribute type
    				echo '<dl class="meta">';
    				echo '<dt class="my-custom-attribute">'.$attribute['name'].':</dt><dd">'.$attribute['options'][0].'</dd>';
    				echo '</dl>';
    			}
    		}
    	}
    }

    If you never used filters/actions, please read this documentation page: How to use filters

    Thread Starter callachic

    (@callachic)

    Hi @alexmigf

    Thanks for your reply. I’m really a noob at this. I’ve added that code to my custom plugin but it’s still not showing anything.

    My product setup:
    I added custom attribute at the product (using the default one provided by WooCommerce), I set it to be like this:
    Kadar = 700
    Panjang = 17cm
    (These 2 are to be displayed in the invoice as well)

    In case you want to see, the product is at the following link, and the details are in “Additional Information” tab:
    https://www.tokomasmulia.com/product/gelang-bola-bola-3-warna/

    So do I modify it to be like the below? It’s still not showing anything..

    add_action(‘wpo_wcpdf_after_item_meta’, ‘wpo_wcpdf_show_custom_attribute’, 10, 3);
    function wpo_wcpdf_show_custom_attribute($document_type, $item, $order)
    {
    if( !empty($order) && $document_type == ‘invoice’ ) {
    $product = wc_get_product($item[‘product_id’]);
    $attributes = $product->get_attributes();
    foreach( $attributes as $type => $attribute ) {
    if( $type == ‘my-custom-attribute’ ) { // attribute type
    echo ‘<dl class=”meta”>’;
    echo ‘<dt class=”my-custom-attribute”>’.$attribute[‘Kadar’].’:</dt><dd”>’.$attribute[‘options’][0].'</dd>’;
    echo ‘</dl>’;
    }
    }
    }
    }

    Your kind help is very much appreciated..

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @callachic

    You have to replace my-custom-attribute with your attribute key.

    Thread Starter callachic

    (@callachic)

    OOOHHH i managed to make it work with your code!! THANK YOU SO MUCH FOR YOUR HELP! Really appreciate it!

    Plugin Contributor alexmigf

    (@alexmigf)

    You’re welcome @callachic ??

    We really appreciate if you could spare a minute to review our plugin.

    Have a great day!

    Can we show a custom field of product in invoice pdf?

    For example: I created a custom field using ACF field name hsn_code.

    I want to display that into invoice pdf.

    Please help.

    Thanks,

    Vijay

    Plugin Contributor Ewout

    (@pomegranate)

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Displaying Additional Information (Custom Product Attribute) to Invoice’ is closed to new replies.