Skip to content

Instantly share code, notes, and snippets.

@amirhp-com
Created April 1, 2022 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirhp-com/37f64ae0aff71d9337900f1ec2f57d30 to your computer and use it in GitHub Desktop.
Save amirhp-com/37f64ae0aff71d9337900f1ec2f57d30 to your computer and use it in GitHub Desktop.
<?php
add_filter( "puiw_printinvoice_create_html_item_row_metas", "my_custom_lineitems_macros", 10, 5);
/* add the macro: {{{remaining-qty}}} */
function my_custom_lineitems_macros ($macros, $item_id, $item, $product_id, $order){
$product = $item->get_product();
$current_qty = $product->get_stock_quantity();
$bought_qty = $item->get_quantity();
$remaining_qty = (int) $current_qty - (int) $bought_qty;
$macros["remaining-qty"] = $remaining_qty;
return $macros;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment