Skip to content

Instantly share code, notes, and snippets.

@hedqvist
Last active April 9, 2023 13:14
Show Gist options
  • Select an option

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

Select an option

Save hedqvist/e0f45d4c550e093273c8da09cb1729fa to your computer and use it in GitHub Desktop.
Company name as Name and customer name as YourReference
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Company Name to Fortnox order Name
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.3.5
*/
function redlight_fortnox_order_companyname( $orderData, $order_id) {
$order = new WC_Order($order_id);
if(!empty($order->get_billing_company())){
$orderData['Order']['CustomerName'] = $order->get_billing_company();
$orderData['Order']['YourReference'] = $order->get_billing_first_name()." ";
$orderData['Order']['YourReference'] .= $order->get_billing_last_name();
}
if(!empty($order->get_shipping_company())){
$orderData['Order']['DeliveryName'] = $order->get_shipping_company();
$orderData['Order']['YourReference'] = $order->get_shipping_first_name()." ";
$orderData['Order']['YourReference'] .= $order->get_shipping_last_name();
}
return $orderData;
}
add_filter('obj_fortnox_order_data', 'redlight_fortnox_order_companyname', 100, 2 );
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Company Name to Fortnox customer Name (Registrered users)
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.3.5
*/
function redlight_custom_customerdata_companyname( $customer) {
$billing_company = (!empty($_POST['billing_company'])) ? $_POST['billing_company'] : "";
$billing_first_name = (!empty($_POST['billing_first_name'])) ? $_POST['billing_first_name'] : "";
$billing_last_name = (!empty($_POST['billing_last_name'])) ? $_POST['billing_last_name'] : "";
$shipping_company = (!empty($_POST['shipping_company'])) ? $_POST['shipping_company'] : "";
$shipping_first_name = (!empty($_POST['shipping_first_name'])) ? $_POST['shipping_first_name'] : "";
$shipping_last_name = (!empty($_POST['shipping_last_name'])) ? $_POST['shipping_last_name'] : "";
if(!empty($billing_company)){
$customer['Customer']['Name'] = $billing_company;
$customer['Customer']['YourReference'] = $billing_first_name." ".$billing_last_name;
}
if(!empty($shipping_company)){
$customer['Customer']['DeliveryName'] = $shipping_company;
}
return $customer;
}
add_filter( 'obj_fortnox_customer_data', 'redlight_custom_customerdata_companyname');
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Company Name to Fortnox customer Name (Guest users)
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.3.5
*/
function custom_fortnox_guest_customer_data_companyname( $customer, $order_id ) {
$order = new WC_Order($order_id);
if(!empty($order->get_billing_company())){
$customer['Customer']['Name'] = $order->get_billing_company();
$customer['Customer']['YourReference'] = $order->get_billing_first_name()." ";
$customer['Customer']['YourReference'] .= $order->get_billing_last_name();
}
if(!empty($order->get_shipping_company())){
$customer['Customer']['DeliveryName'] = $order->get_shipping_company();
$customer['Customer']['YourReference'] = $order->get_shipping_first_name()." ";
$customer['Customer']['YourReference'] .= $order->get_shipping_last_name();
}
return $customer;
}
add_filter( 'obj_fortnox_guest_customer_data', 'custom_fortnox_guest_customer_data_companyname', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment