22
33namespace BitCode \FI \Triggers \WC ;
44
5- use BitCode \FI \Core \Util \Helper ;
6- use BitCode \FI \Flow \Flow ;
75use WC_Booking ;
86use WC_Checkout ;
97use WC_Product_Simple ;
8+ use BitCode \FI \Flow \Flow ;
109use WC_Subscriptions_Product ;
10+ use BitCode \FI \Core \Util \Helper ;
1111
1212final class WCController
1313{
@@ -788,61 +788,59 @@ public static function accessProductData($product)
788788
789789 public static function accessOrderData ($ order )
790790 {
791- // var_dump(get_class($order), 'class');
792- // Automattic\WooCommerce\Admin\Overrides\Order
793- // if (!$order instanceof WC_Product_Factory) {
794- // return [];
795- // }
796791 $ data = [
797- 'id ' => $ order ->get_id (),
798- 'order_key ' => $ order ->get_order_key (),
799- 'card_tax ' => $ order ->get_cart_tax (),
800- 'currency ' => $ order ->get_currency (),
801- 'discount_tax ' => $ order ->get_discount_tax (),
802- 'discount_to_display ' => $ order ->get_discount_to_display (),
803- 'discount_total ' => $ order ->get_discount_total (),
804- 'fees ' => $ order ->get_fees (),
805- 'shipping_tax ' => $ order ->get_shipping_tax (),
806- 'shipping_total ' => $ order ->get_shipping_total (),
807- 'tax_totals ' => $ order ->get_tax_totals (),
808- 'total ' => $ order ->get_total (),
809- 'total_refunded ' => $ order ->get_total_refunded (),
810- 'total_tax_refunded ' => $ order ->get_total_tax_refunded (),
811- 'total_shipping_refunded ' => $ order ->get_total_shipping_refunded (),
812- 'total_qty_refunded ' => $ order ->get_total_qty_refunded (),
813- 'remaining_refund_amount ' => $ order ->get_remaining_refund_amount (),
814- 'shipping_method ' => $ order ->get_shipping_method (),
792+ 'id ' => $ order ->get_id () ?? '' ,
793+ 'order_key ' => $ order ->get_order_key () ?? '' ,
794+ 'card_tax ' => $ order ->get_cart_tax () ?? '' ,
795+ 'currency ' => $ order ->get_currency () ?? '' ,
796+ 'discount_tax ' => $ order ->get_discount_tax () ?? '' ,
797+ 'discount_to_display ' => $ order ->get_discount_to_display () ?? '' ,
798+ 'discount_total ' => $ order ->get_discount_total () ?? '' ,
799+ 'fees ' => $ order ->get_fees () ?? '' ,
800+ 'shipping_tax ' => $ order ->get_shipping_tax () ?? '' ,
801+ 'shipping_total ' => $ order ->get_shipping_total () ?? '' ,
802+ 'tax_totals ' => $ order ->get_tax_totals () ?? '' ,
803+ 'total ' => $ order ->get_total () ?? '' ,
804+ 'total_refunded ' => $ order ->get_total_refunded () ?? '' ,
805+ 'total_tax_refunded ' => $ order ->get_total_tax_refunded () ?? '' ,
806+ 'total_shipping_refunded ' => $ order ->get_total_shipping_refunded () ?? '' ,
807+ 'total_qty_refunded ' => $ order ->get_total_qty_refunded () ?? '' ,
808+ 'remaining_refund_amount ' => $ order ->get_remaining_refund_amount () ?? '' ,
809+ 'shipping_method ' => $ order ->get_shipping_method () ?? '' ,
815810 'date_created ' => \is_null ($ order ->get_date_created ()) ? $ order ->get_date_created () : $ order ->get_date_created ()->format ('Y-m-d H:i:s ' ),
816811 'date_modified ' => \is_null ($ order ->get_date_modified ()) ? $ order ->get_date_modified () : $ order ->get_date_modified ()->format ('Y-m-d H:i:s ' ),
817812 'date_completed ' => \is_null ($ order ->get_date_completed ()) ? $ order ->get_date_completed () : $ order ->get_date_completed ()->format ('Y-m-d H:i:s ' ),
818813 'date_paid ' => \is_null ($ order ->get_date_paid ()) ? $ order ->get_date_paid () : $ order ->get_date_paid ()->format ('Y-m-d H:i:s ' ),
819- 'customer_id ' => $ order ->get_customer_id (),
820- 'created_via ' => $ order ->get_created_via (),
821- 'customer_note ' => $ order ->get_customer_note (),
822- 'billing_first_name ' => $ order ->get_billing_first_name (),
823- 'billing_last_name ' => $ order ->get_billing_last_name (),
824- 'billing_company ' => $ order ->get_billing_company (),
825- 'billing_address_1 ' => $ order ->get_billing_address_1 (),
826- 'billing_address_2 ' => $ order ->get_billing_address_2 (),
827- 'billing_city ' => $ order ->get_billing_city (),
828- 'billing_state ' => $ order ->get_billing_state (),
829- 'billing_postcode ' => $ order ->get_billing_postcode (),
830- 'billing_country ' => $ order ->get_billing_country (),
831- 'billing_email ' => $ order ->get_billing_email (),
832- 'billing_phone ' => $ order ->get_billing_phone (),
833- 'shipping_first_name ' => $ order ->get_shipping_first_name (),
834- 'shipping_last_name ' => $ order ->get_shipping_last_name (),
835- 'shipping_company ' => $ order ->get_shipping_company (),
836- 'shipping_address_1 ' => $ order ->get_shipping_address_1 (),
837- 'shipping_address_2 ' => $ order ->get_shipping_address_2 (),
838- 'shipping_city ' => $ order ->get_shipping_city (),
839- 'shipping_state ' => $ order ->get_shipping_state (),
840- 'shipping_postcode ' => $ order ->get_shipping_postcode (),
841- 'shipping_country ' => $ order ->get_shipping_country (),
842- 'payment_method ' => $ order ->get_payment_method (),
843- 'payment_method_title ' => $ order ->get_payment_method_title (),
844- 'status ' => $ order ->get_status (),
845- 'checkout_order_received_url ' => $ order ->get_checkout_order_received_url (),
814+ 'customer_id ' => $ order ->get_customer_id () ?? '' ,
815+ 'created_via ' => $ order ->get_created_via () ?? '' ,
816+ 'customer_note ' => $ order ->get_customer_note () ?? '' ,
817+ 'billing_first_name ' => $ order ->get_billing_first_name () ?? '' ,
818+ 'billing_last_name ' => $ order ->get_billing_last_name () ?? '' ,
819+ 'billing_company ' => $ order ->get_billing_company () ?? '' ,
820+ 'billing_address_1 ' => $ order ->get_billing_address_1 () ?? '' ,
821+ 'billing_address_2 ' => $ order ->get_billing_address_2 () ?? '' ,
822+ 'billing_city ' => $ order ->get_billing_city () ?? '' ,
823+ 'billing_state ' => $ order ->get_billing_state () ?? '' ,
824+ 'billing_postcode ' => $ order ->get_billing_postcode () ?? '' ,
825+ 'billing_country ' => $ order ->get_billing_country () ?? '' ,
826+ 'billing_email ' => $ order ->get_billing_email () ?? '' ,
827+ 'billing_phone ' => $ order ->get_billing_phone () ?? '' ,
828+ 'shipping_first_name ' => $ order ->get_shipping_first_name () ?? '' ,
829+ 'shipping_last_name ' => $ order ->get_shipping_last_name () ?? '' ,
830+ 'shipping_company ' => $ order ->get_shipping_company () ?? '' ,
831+ 'shipping_address_1 ' => $ order ->get_shipping_address_1 () ?? '' ,
832+ 'shipping_address_2 ' => $ order ->get_shipping_address_2 () ?? '' ,
833+ 'shipping_city ' => $ order ->get_shipping_city () ?? '' ,
834+ 'shipping_state ' => $ order ->get_shipping_state () ?? '' ,
835+ 'shipping_postcode ' => $ order ->get_shipping_postcode () ?? '' ,
836+ 'shipping_country ' => $ order ->get_shipping_country () ?? '' ,
837+ 'payment_method ' => $ order ->get_payment_method () ?? '' ,
838+ 'payment_method_title ' => $ order ->get_payment_method_title () ?? '' ,
839+ 'status ' => $ order ->get_status () ?? '' ,
840+ 'checkout_order_received_url ' => $ order ->get_checkout_order_received_url () ?? '' ,
841+ 'line_items ' => [],
842+ 'product_names ' => '' ,
843+ 'line_items_quantity ' => 0
846844 ];
847845 if (\defined ('WC_VERSION ' ) && version_compare (WC_VERSION , '8.5.1 ' , '>= ' )) {
848846 $ data += [
@@ -858,39 +856,24 @@ public static function accessOrderData($order)
858856 ];
859857 }
860858
861- $ line_items = [];
862- $ line_items_all = [];
863- $ count = 0 ;
864- foreach ($ order ->get_items () as $ item_id => $ item ) {
859+ foreach ($ order ->get_items () as $ item ) {
865860 $ product_id = $ item ->get_product_id ();
866- $ variation_id = $ item ->get_variation_id ();
867861 $ product = $ item ->get_product ();
868- $ product_name = $ item ->get_name ();
869- $ quantity = $ item ->get_quantity ();
870- $ subtotal = $ item ->get_subtotal ();
871- $ total = $ item ->get_total ();
872- $ subtotal_tax = $ item ->get_subtotal_tax ();
873- $ taxclass = $ item ->get_tax_class ();
874- $ taxstat = $ item ->get_tax_status ();
875- $ product_unit_price = $ product ->get_price ();
876- $ label = 'line_items_ ' ;
877- $ productSku = $ product ->get_sku ();
878- $ count ++;
879862 $ itemData = [
880863 'product_id ' => $ product_id ,
881- 'variation_id ' => $ variation_id ,
882- 'product_name ' => $ product_name ,
883- 'quantity ' => $ quantity ,
884- 'subtotal ' => $ subtotal ,
885- 'total ' => $ total ,
886- 'subtotal_tax ' => $ subtotal_tax ,
887- 'tax_class ' => $ taxclass ,
888- 'tax_status ' => $ taxstat ,
889- 'product_sku ' => $ productSku ,
890- 'product_unit_price ' => $ product_unit_price ,
864+ 'variation_id ' => $ item -> get_variation_id () ?? '' ,
865+ 'product_name ' => $ item -> get_name () ?? '' ,
866+ 'quantity ' => $ item -> get_quantity () ?? '' ,
867+ 'subtotal ' => $ item -> get_subtotal () ?? '' ,
868+ 'total ' => $ item -> get_total () ?? '' ,
869+ 'subtotal_tax ' => $ item -> get_subtotal_tax () ?? '' ,
870+ 'tax_class ' => $ item -> get_tax_class () ?? '' ,
871+ 'tax_status ' => $ item -> get_tax_status () ?? '' ,
872+ 'product_sku ' => $ product -> get_sku () ?? '' ,
873+ 'product_unit_price ' => $ product -> get_price () ?? '' ,
891874 ];
892- $ acfFieldGroups = Helper::acfGetFieldGroups (['product ' ]);
893875
876+ $ acfFieldGroups = Helper::acfGetFieldGroups (['product ' ]);
894877 foreach ($ acfFieldGroups as $ group ) {
895878 $ acfFields = acf_get_fields ($ group ['ID ' ]);
896879
@@ -899,9 +882,10 @@ public static function accessOrderData($order)
899882 }
900883 }
901884
902- $ line_items_all ['line_items ' ][] = (object ) $ itemData ;
885+ $ data ['line_items ' ][] = (object ) $ itemData ;
903886 }
904- $ data += $ line_items_all ;
887+ $ data ['product_names ' ] = implode (', ' , array_column ($ data ['line_items ' ], 'product_name ' ));
888+ $ data ['line_items_quantity ' ] = count ($ data ['line_items ' ]);
905889
906890 return $ data ;
907891 }
0 commit comments