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
- 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
- Default: None
- Default: None
yes
). - Default:
no
- Default: None
- Default: None
- Default: None
- Default: `%.2f %%`
- Default: None
- Default: None
- Default: None
- Default: None
- Default: `font-size:smaller;`
- Default: `yes`
- Default: None
- Default: None
- Default: None
- Default: `yes`
- Default: None
- Default: `1`
- Default: `1`
- Default: `no`
- Default: `no`
- Default: `60`
- 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:
- 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 /> }
- [wcj_order_items_table]