fbpx

Description

[wcj_order_items_table] shortcode displays WooCommerce order items table. Usually this shortcode is the main part of invoice template in PDF Invoices module.

Args

columns
(required) List of predefined table columns you need to display. Columns identifiers must be separated by vertical bar ( | ). Possible column identifiers are:

  • item_key
  • item_meta
  • item_name
  • item_number
  • item_product_addons
  • item_product_id
  • item_product_input_fields
  • item_product_input_fields_with_titles
  • item_quantity_excl_refunded
  • item_quantity_refunded
  • item_quantity
  • item_subtotal_tax_excl
  • item_subtotal_tax_incl
  • item_tax_class
  • item_tax_percent
  • item_tax
  • item_total_refunded
  • item_total_tax_excl
  • item_total_tax_incl
  • item_variation
  • item_debug
  • product_attribute
  • product_categories
  • product_cost
  • product_excerpt
  • product_height
  • product_id
  • product_length
  • product_meta
  • product_post_meta
  • product_profit
  • product_purchase_note
  • product_regular_price_multiply_qty
  • product_regular_price
  • product_sale_price_multiply_qty
  • product_sale_price
  • product_short_description
  • product_sku
  • product_thumbnail
  • product_weight
  • product_weight_multiply_qty
  • product_width
  • product_barcode
  • line_cost
  • line_profit
  • line_subtax
  • line_subtotal_tax_excl
  • line_subtotal_tax_incl
  • line_tax
  • line_total_tax_excl
  • line_total_tax_incl

Default: None

columns_titles
(optional) List of vertical bar ( | ) separated column titles.
Default: None

columns_styles
(optional) List of vertical bar ( | ) separated column styles.
Default: None

hide_currency
(optional) Hide currency symbol (yes).
Default: no

table_class
(optional) HTML class for the resulting table.
Default: None

shipping_as_item
(optional) If not empty, shipping will be added to order items list as line item. It is possible to add shipping method name to the item's name, by adding `%shipping_method_name%` to the attribute value.
Default: None

discount_as_item
(optional) If not empty, discount will be added to order items list as line item.
Default: None

tax_percent_format
(optional) Format for outputting percent data in table.
Default: `%.2f %%`

product_image_width
(optional) Attribute used only if `product_thumbnail` column is enabled.
Default: None

product_image_height
(optional) Attribute used only if `product_thumbnail` column is enabled.
Default: None


price_prefix
(optional) Prefix all prices in table. For example you can add minus `-` sign to all prices.
Default: None

quantity_prefix
(optional) Prefix quantity in `item_quantity` column.
Default: None

style_item_name_variation
(optional) Used in `item_name` column.
Default: `font-size:smaller;`

variation_as_metadata
(optional) Used in `item_name` and `item_variation` columns.
Default: `yes`


order_user_roles
(optional) Display table only for certain user roles. Can be comma separated list.
Default: None

exclude_by_categories
(optional) Exclude some items from the table by product category. Can be comma separated list.
Default: None

exclude_by_tags
(optional) Exclude some items from the table by product tag. Can be comma separated list.
Default: None



add_variation_info_to_item_name
(optional) Used in `item_name` column.
Default: `yes`

insert_page_break
(optional) Sets number of items after which page break should inserted. Can be list of numbers separated by vertical bars ( | ). E.g. `10|20`.
Default: None

multiply_cost
(optional) Used in `product_cost` and `line_cost` columns.
Default: `1`

multiply_profit
(optional) Used in `product_profit` and `line_profit` columns.
Default: `1`

refunded_items_table
(optional) If set to `yes`, will display order refunded items instead.
Default: `no`

hide_zero_prices
(optional) If set to `yes`, will hide all zero prices in table.
Default: `no`

product_barcode_width
(optional) Used in `product_barcode` column.
Default: `60`

product_barcode_height
(optional) Used in `product_barcode` column.
Default: `60`

Examples

This will create invoice with 3 columns: item counter, item name and price, setting column titles and styles accordingly:

[wcj_order_items_table<br />
    table_class="pdf_invoice_items_table"<br />
    columns="item_number|item_name|line_total_tax_incl"<br />
    columns_titles="|Product|Total"<br />
    columns_styles="width:5%;|width:65%;|width:30%;text-align:right;"]

Example with products images (i.e. thumbnails):

[wcj_order_items_table<br />
    table_class="pdf_invoice_items_table"<br />
    product_image_width="50"<br />
    product_image_height="50"<br />
    columns="item_number|product_thumbnail|item_name|item_product_input_fields|line_total_tax_incl"<br />
    columns_titles="#|Image|Product|Input Fields|Total"<br />
    columns_styles="width:5%;|width:30%;|width:35%;|width:20%;|width:10%;text-align:right;"]

Example for adding products meta (replace `_your_meta_key` with your key):

[wcj_order_items_table<br />
    table_class="pdf_invoice_items_table"<br />
    columns="item_number|item_name|product_post_meta=_your_meta_key|item_quantity|line_total_tax_excl"<br />
    columns_titles="#|Product|Meta|Qty|Total"<br />
    columns_styles="width:5%;|width:45%;|width:30%;|width:5%;|width:15%;text-align:right;"]

Example for adding products barcodes. You can replace `product_barcode=%sku%` with `product_barcode=%id%`, `product_barcode=%url%` or `product_barcode=_your_meta_key` (replace `_your_meta_key` with your key). Product barcodes in PDF will always be: `PDF417` type, 2 dimensional (`2D`) and `black` color:

[wcj_order_items_table<br />
    table_class="pdf_invoice_items_table"<br />
    columns="product_barcode=%sku%|item_name|item_quantity|line_total_tax_excl"<br />
    columns_titles="Barcode|Product|Qty|Total"<br />
    columns_styles="width:40%;|width:40%;|width:5%;|width:15%;text-align:right;"]

Developers

If you wish to modify final cell content, there is `wcj_pdf_invoicing_cell_data` filter available. Filter params are:

$cell_data
Filtered value.
$args
Passed arguments array:

  • column
  • column_param
  • item
  • item_id
  • item_counter
  • product
  • order

For example, you can format `item_number` column values:

if ( ! function_exists( ‘alg_format_item_number_in_pdf_invoice’ ) ) {<br />
	/*<br />
	 * alg_format_item_number_in_pdf_invoice.<br />
	 */<br />
	function alg_format_item_number_in_pdf_invoice( $cell_data, $args ) {<br />
		if ( ‘item_number’ === $args[‘column’] ) {<br />
			$cell_data = sprintf( “%02d”, $cell_data );<br />
		}<br />
		return $cell_data;<br />
	}<br />
	add_filter( ‘wcj_pdf_invoicing_cell_data’, ‘alg_format_item_number_in_pdf_invoice’, PHP_INT_MAX, 2 );<br />
}

Another example shows how to remove everything after the last space in an item name:

if ( ! function_exists( ‘alg_remove_all_after_last_space_in_pdf_invoice_item_name’ ) ) {<br />
    /*<br />
     * alg_remove_all_after_last_space_in_pdf_invoice_item_name.<br />
     */<br />
    function alg_remove_all_after_last_space_in_pdf_invoice_item_name( $cell_data, $args ) {<br />
        if ( ‘item_name’ === $args[‘column’] ) {<br />
            if ( false !== ( $last_space_pos = strrpos( $cell_data, ‘ ‘ ) ) ) {<br />
                $cell_data = substr( $cell_data, 0, $last_space_pos );<br />
            }<br />
        }<br />
        return $cell_data;<br />
    }<br />
    add_filter( ‘wcj_pdf_invoicing_cell_data’, ‘alg_remove_all_after_last_space_in_pdf_invoice_item_name’, PHP_INT_MAX, 2 );<br />
}

Another example shows how to modify cells for items with total equals zero (e.g. bundled products):

if ( ! function_exists( ‘alg_modify_bundle_products_in_pdf_invoice’ ) ) {<br />
	/*<br />
	 * alg_modify_bundle_products_in_pdf_invoice.<br />
	 */<br />
	function alg_modify_bundle_products_in_pdf_invoice( $cell_data, $args ) {<br />
		$item_total_tax_incl = $args[‘order’]->get_item_total( $args[‘item’], true, true );<br />
		if ( 0 == $item_total_tax_incl ) {<br />
			$cell_data = ‘<span style="font-size:small;">‘ . $cell_data . ‘</span>‘;<br />
			switch ( $args[‘column’] ) {<br />
				case ‘item_number’:<br />
					return ”;<br />
				case ‘item_name’:<br />
					return ‘-‘ . $cell_data;<br />
			}<br />
		}<br />
		return $cell_data;<br />
	}<br />
	add_filter( ‘wcj_pdf_invoicing_cell_data’, ‘alg_modify_bundle_products_in_pdf_invoice’, PHP_INT_MAX, 2 );<br />
}
Accessible through:
  • [wcj_order_items_table]
Tested on WooCommerce 4.5.2 and WordPress 5.5.1
Plugin can be downloaded here. If there are any locked fields in the module, you will need to get Booster Plus to unlock them.