Skip to content

Commit

Permalink
New: Add cac:Price support to UBL
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf authored Dec 31, 2024
1 parent 30c5975 commit d26c826
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ubl/Handlers/Invoice/InvoiceLineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ public function handle( $data, $options = array() ) {
),
),
),
array(
'name' => 'cac:Price',
'value' => array(
array(
'name' => 'cbc:PriceAmount',
'value' => round( $this->get_item_unit_price( $item ), 2 ),
'attributes' => array(
'currencyID' => $this->document->order->get_currency(),
),
),
),
),
),
);

Expand All @@ -152,4 +164,20 @@ public function handle( $data, $options = array() ) {
return $data;
}

/**
* Get the unit price of an item
*
* @param WC_Order_Item $item
* @return int|float
*/
private function get_item_unit_price( $item ) {
if ( is_a( $item, 'WC_Order_Item_Product' ) ) {
return $item->get_subtotal() / $item->get_quantity();
} elseif ( is_a( $item, 'WC_Order_Item_Shipping' ) || is_a( $item, 'WC_Order_Item_Fee' ) ) {
return $item->get_total();
} else {
return 0;
}
}

}

0 comments on commit d26c826

Please sign in to comment.