Skip to content

Instantly share code, notes, and snippets.

@hedqvist
Created June 2, 2020 09:10
Show Gist options
  • Select an option

  • Save hedqvist/a045a8fdb836100d998420f61d863d05 to your computer and use it in GitHub Desktop.

Select an option

Save hedqvist/a045a8fdb836100d998420f61d863d05 to your computer and use it in GitHub Desktop.
Fortnox - Shipping as OrderItem EU
<?php
/**
* @snippet WooCommerce - Fortnox Add Shipping charges as OrderItem instead of Shipping fee in Fortnox
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.1.0
*/
function redlight_fortnox_shipping_as_order_item($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){
switch($order->get_shipping_country()){
case 'SE':
$account = 3520;
$sku = 8111;
$description = 'Delivery Cost SE';
break;
case 'FI':
case 'DK':
case 'DE':
case 'NL':
case 'GB':
case 'IE':
case 'LU':
case 'BE':
case 'FR':
case 'ES':
case 'PT':
case 'AT':
case 'IT':
case 'PL':
case 'EE':
case 'LV':
case 'LT':
case 'HU':
case 'SK':
case 'CZ':
case 'BG':
case 'CY':
case 'GR':
case 'HR':
case 'MT':
case 'RO':
case 'SI':
$account = 3018;
$sku = 8107;
$description = 'Delivery Cost EU';
break;
default:
$account = 3015;
$sku = 8108;
$description = 'Delivery Cost outside EU';
break;
}
$shipping_vat = (floatval($order->get_shipping_tax()) / floatval($order->get_shipping_total()))*100;
//$shippingname = $order->get_shipping_method();
$orderItem = array(
'ArticleNumber' => $sku,
'AccountNumber' => $account,
'DeliveredQuantity' => 1,
'Description' => $description,
'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_order_item', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment