Fakturownia - dodanie kolumny z rabatem procentowym
The snippet can be accessed without any authentication.
Authored by
Mateusz Okła
Edited
/**
* This adds the new weight unit to WooCommerce
*/
add_filter( 'fakturownia/invoice/data', 'wpdesk_fakturownia_set_discount', 10, 2 );
function wpdesk_fakturownia_set_discount( array $data, WPDesk\WooCommerceFakturownia\Data\DocumentData $document_data ) {
$order_items = $document_data->getOrder()->get_items();
foreach ( $data['positions'] as $data_item_id => $data_item ) {
foreach ( $order_items as $item_id => $item ) {
if ( $item instanceof WC_Order_Item_Product && $data_item['name'] === $item->get_name() ) {
$discount_price = ( $item->get_subtotal() - $item->get_total() ) / $item->get_quantity();
$discount_percent = 100 - ($item->get_total() / $item->get_subtotal() * 100);
$data['positions'][ $data_item_id ]['discount_percent'] = $discount_percent;
$data['positions'][ $data_item_id ]['total_price_gross'] = $item->get_subtotal();
}
}
}
$data['show_discount'] = 1;
$data['discount_kind'] = 'percent_unit';
return $data;
}
Please register or sign in to comment