Last active
July 12, 2018 14:44
-
-
Save hedqvist/5e649035aa4bf18aa9077703ba65e407 to your computer and use it in GitHub Desktop.
Shipping Fee to OrderRow in Fortnox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Shipping charges as OrderItem instead of Shipping fee in Fortnox via functions.php | |
* @author Redlight Media AB / Christopher Hedqvist | |
* @compatible WooCommerce 3.2.5 | |
*/ | |
function redlight_fortnox_shipping_as_orderLine($orderData, $order_id) { | |
$order = new WC_Order($order_id); | |
// Remove fee from orderData | |
if(isset($orderData['Order']['Freight'])){ | |
unset($orderData['Order']['Freight']) ; | |
} | |
if($order->get_shipping_total() > 0){ | |
$shipping_vat = (floatval($order->get_shipping_tax()) / floatval($order->get_shipping_total()))*100; | |
$orderItem = array( | |
'AccountNumber' => 3520, | |
'DeliveredQuantity' => 1, | |
'Description' => 'Fraktavgift - '.$order->get_shipping_method(), | |
'OrderedQuantity' => 1, | |
'Price' => floatval($order->get_shipping_total()), | |
'VAT' => $shipping_vat | |
); | |
array_push($orderData['Order']['OrderRows'],$orderItem); | |
} | |
return $orderData; | |
} | |
add_filter('obj_fortnox_order_data', 'redlight_fortnox_shipping_as_orderLine', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment