Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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(isset($billing_company)){
- $customer['Customer']['Name'] = $billing_company;
- }
- if(isset($shipping_company)){
- $customer['Customer']['DeliveryName'] = $shipping_company;
- }
- $customer['Customer']['YourReference'] = $billing_first_name." ".$billing_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']['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 );
Add Comment
Please, Sign In to add comment