• Resolved amc11

    (@amc11)


    Hi,

    Is it possible to adjust the template file to include
    extra information for column description?

    In our case we would like to add selected variation attribute
    like 100 grams.

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Bas Elbers

    (@baaaaas)

    The minimal template should show the variation attributes by default. If not read the Readme first! topic and let me know as much information as possible so we can try and reproduce the issue.

    Thread Starter amc11

    (@amc11)

    Hi,

    Bumping this thread ?? Ive looked through the read me, but I cannot see any way to add another column (product attribute) in the pdf with values for each of the purchased products.

    Grams(attribut name)

    Like so:

    Description___________Grams(attribut name)___________Items___________Total
    Cheddar-200g________400g (attribute value*2)_________2________________400

    Thanks!

    • This reply was modified 4 years, 5 months ago by amc11.
    • This reply was modified 4 years, 5 months ago by amc11.
    • This reply was modified 4 years, 5 months ago by amc11.
    • This reply was modified 4 years, 5 months ago by amc11.
    • This reply was modified 4 years, 5 months ago by amc11.
    Plugin Author Bas Elbers

    (@baaaaas)

    Adding a column would probably mess up the CSS.

    You can have a look at below article which adds the SKU below the product description. You could use it to add the weight instead of the SKU.

    How to display the parent product SKU below the product description?

    Check below article on how to get the weight from a product.
    https://docs.woocommerce.com/document/display-product-weight-archive-pages/

    Thread Starter amc11

    (@amc11)

    Thanks!

    But its the PDF that is sent with the order that needs the changes.
    Not the archive pages.

    Adding one column for the table within the PDF, is that really that
    difficult?

    Really thankful for the support.

    • This reply was modified 4 years, 5 months ago by amc11.
    Thread Starter amc11

    (@amc11)

    Hi again,

    Ive been trying to adjust the template to include another column with attribute grams.

    The problem I’m facing is this call $invoice->get_columns_data() within abstract-invoice.php.

    Because no product id (SKU) is included within that return, I cannot match and retrieve attribute data and create another column with that information for the template file.

    Is there any way to get around this, without modifying the core plugin files?
    Im seing $order, can this be used?

    Thanks!

    Plugin Author Bas Elbers

    (@baaaaas)

    I’ve created below examples to add columns to the invoice by using filters. Not tested, but should work totally fine.

    
    function add_sku_column( $columns, $invoice ) {
    	$columns = array_merge( array( 'sku' => __( 'SKU', 'woocommerce-pdf-invoices' ) ), $columns );
    	return $columns;
    }
    add_filter( 'wpi_get_invoice_columns', 'add_sku_column', 10, 2 );
    
    function add_sku_column_data( $row, $item_id, $item, $invoice ) {
    	/** @var WC_Product $product */
    	$product = $item->get_product();
    	$row = array_merge( array( 'sku' =>  $product ? $product->get_sku() : '-' ), $row );
    	
    	return $row;
    }
    add_filter( 'wpi_get_invoice_columns_data_row', 'add_sku_column_data', 10, 4 );
    
    function add_unit_of_measure_column( $columns, $invoice ) {
    	// Splice columns at 'quantity' column, add column and merge with last part.
    	$offset  = array_search( 'quantity', array_keys( $columns ), true );
    	$columns = array_merge(
    		array_splice( $columns, 0, $offset ),
    		array(
    			'unit_of_measure' => __( 'Unitate de masura', 'woocommerce-pdf-invoices' ),
    		),
    		$columns
    	);
    
    	return $columns;
    }
    add_filter( 'wpi_get_invoice_columns', 'add_unit_of_measure_column', 20, 2 );
    
    function add_unit_of_measure_column_data( $row, $item_id, $item, $invoice ) {
    	/** @var WC_Product $product */
    
    	$product         = $item->get_product();
    	$attribute_value = $product ? $product->get_attribute( 'Unitate de masura' ) : '';
    
    	$offset = array_search( 'quantity', array_keys( $row ), true );
    	$row    = array_merge(
    		array_splice( $row, 0, $offset ),
    		array(
    			'unit_of_measure' => $attribute_value,
    		),
    		$row
    	);
    
    	return $row;
    }
    add_filter( 'wpi_get_invoice_columns_data_row', 'add_unit_of_measure_column_data', 20, 4 );
    
    Thread Starter amc11

    (@amc11)

    This is just amazing thank you so much!!

    Thread Starter amc11

    (@amc11)

    Hi,

    This script really helped me a lot!
    Thank you.

    I have two more questions.

    1. Is it possible to remove the product name from description?
    2. How can I change the filename for the pdf?

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Include text for row’ is closed to new replies.