Guest User

Untitled

a guest
Aug 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. <?php
  2. /**
  3. * @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Company Name to Fortnox order Name
  4. * @author Redlight Media AB / Christopher Hedqvist
  5. * @compatible WooCommerce 3.3.5
  6. */
  7. function redlight_fortnox_order_companyname( $orderData, $order_id) {
  8. $order = new WC_Order($order_id);
  9. if(!empty($order->get_billing_company())){
  10. $orderData['Order']['CustomerName'] = $order->get_billing_company();
  11. $orderData['Order']['YourReference'] = $order->get_billing_first_name()." ";
  12. $orderData['Order']['YourReference'] .= $order->get_billing_last_name();
  13. }
  14. if(!empty($order->get_shipping_company())){
  15. $orderData['Order']['DeliveryName'] = $order->get_shipping_company();
  16. $orderData['Order']['YourReference'] = $order->get_shipping_first_name()." ";
  17. $orderData['Order']['YourReference'] .= $order->get_shipping_last_name();
  18. }
  19. return $orderData;
  20. }
  21. add_filter('obj_fortnox_order_data', 'redlight_fortnox_order_companyname', 100, 2 );
  22. /**
  23. * @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Company Name to Fortnox customer Name (Registrered users)
  24. * @author Redlight Media AB / Christopher Hedqvist
  25. * @compatible WooCommerce 3.3.5
  26. */
  27. function redlight_custom_customerdata_companyname( $customer) {
  28. $billing_company = (!empty($_POST['billing_company'])) ? $_POST['billing_company'] : "";
  29. $billing_first_name = (!empty($_POST['billing_first_name'])) ? $_POST['billing_first_name'] : "";
  30. $billing_last_name = (!empty($_POST['billing_last_name'])) ? $_POST['billing_last_name'] : "";
  31. $shipping_company = (!empty($_POST['shipping_company'])) ? $_POST['shipping_company'] : "";
  32. $shipping_first_name = (!empty($_POST['shipping_first_name'])) ? $_POST['shipping_first_name'] : "";
  33. $shipping_last_name = (!empty($_POST['shipping_last_name'])) ? $_POST['shipping_last_name'] : "";
  34. if(isset($billing_company)){
  35. $customer['Customer']['Name'] = $billing_company;
  36. }
  37. if(isset($shipping_company)){
  38. $customer['Customer']['DeliveryName'] = $shipping_company;
  39. }
  40. $customer['Customer']['YourReference'] = $billing_first_name." ".$billing_last_name;
  41.  
  42. return $customer;
  43. }
  44. add_filter( 'obj_fortnox_customer_data', 'redlight_custom_customerdata_companyname');
  45. /**
  46. * @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Company Name to Fortnox customer Name (Guest users)
  47. * @author Redlight Media AB / Christopher Hedqvist
  48. * @compatible WooCommerce 3.3.5
  49. */
  50. function custom_fortnox_guest_customer_data_companyname( $customer, $order_id ) {
  51.  
  52. $order = new WC_Order($order_id);
  53. if(!empty($order->get_billing_company())){
  54. $customer['Customer']['Name'] = $order->get_billing_company();
  55. $customer['Customer']['YourReference'] = $order->get_billing_first_name()." ";
  56. $customer['Customer']['YourReference'] .= $order->get_billing_last_name();
  57. }
  58. if(!empty($order->get_shipping_company())){
  59. $customer['Customer']['DeliveryName'] = $order->get_shipping_company();
  60. $customer['Customer']['YourReference'] = $order->get_shipping_first_name()." ";
  61. $customer['Customer']['YourReference'] .= $order->get_shipping_last_name();
  62. }
  63. return $customer;
  64. }
  65. add_filter( 'obj_fortnox_guest_customer_data', 'custom_fortnox_guest_customer_data_companyname', 10, 2 );
Add Comment
Please, Sign In to add comment