Last active
April 9, 2023 13:14
-
-
Save hedqvist/37c44991983e80ff1f181cebcf9730dd to your computer and use it in GitHub Desktop.
Add Company name to Fortnox Order/Customer
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 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']['CustomerName'] .= $order->get_billing_first_name()." "; | |
| $orderData['Order']['CustomerName'] .= $order->get_billing_last_name(); | |
| } | |
| if(!empty($order->get_shipping_company())){ | |
| $orderData['Order']['DeliveryName'] = $order->get_shipping_company().": "; | |
| $orderData['Order']['DeliveryName'] .= $order->get_shipping_first_name()." "; | |
| $orderData['Order']['DeliveryName'] .= $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(isset($billing_company)){ | |
| $customer['Customer']['Name'] = $billing_company . ": ".$billing_first_name." ".$billing_last_name; | |
| } | |
| if(isset($shipping_company)){ | |
| $customer['Customer']['DeliveryName'] = $shipping_company . ": ".$shipping_first_name." ".$shipping_last_name; | |
| } | |
| 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']['Name'] .= $order->get_billing_first_name()." "; | |
| $customer['Customer']['Name'] .= $order->get_billing_last_name(); | |
| } | |
| if(!empty($order->get_shipping_company())){ | |
| $customer['Customer']['DeliveryName'] = $order->get_shipping_company().": "; | |
| $customer['Customer']['DeliveryName'] .= $order->get_shipping_first_name()." "; | |
| $customer['Customer']['DeliveryName'] .= $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