@@ -10,7 +10,8 @@ public static function woo_version()
1010 require_once (ABSPATH . 'wp-admin/includes/plugin.php ' );
1111 }
1212
13- return get_plugins ('/woocommerce ' )['woocommerce.php ' ]['Version ' ];
13+ $ woo = get_plugins ('/woocommerce ' );
14+ return $ woo ['woocommerce.php ' ]['Version ' ];
1415 }
1516
1617 public static function get_meta ()
@@ -52,18 +53,24 @@ public function get_articles($items)
5253 return $ articles ;
5354 }
5455
55- public function get_customer ( $ customer )
56+ public function get_user ( $ user )
5657 {
57- $ serializer = array (
58- 'id ' => (string ) $ customer ->id ,
59- 'type ' => 'n ' ,
58+ return array (
59+ 'id ' => (string ) $ user ->id ,
60+ 'type ' => 'e ' ,
6061 'gender ' => 0 ,
61- 'email ' => $ customer ->user_email ,
62- 'first_name ' => $ customer ->first_name ,
63- 'last_name ' => $ customer ->last_name ,
64- 'date_joined ' => date (DATE_ISO8601 , $ customer ->user_registered ));
62+ 'email ' => $ user ->user_email ,
63+ 'first_name ' => $ user ->first_name ,
64+ 'last_name ' => $ user ->last_name ,
65+ 'date_joined ' => date (DATE_ISO8601 , $ user ->user_registered ));
66+ }
6567
66- return $ serializer ;
68+ public function get_customer ($ billing_email )
69+ {
70+ return array (
71+ 'type ' => 'n ' ,
72+ 'gender ' => 0 ,
73+ 'email ' => $ billing_email );
6774 }
6875
6976 public function get_address ($ order , $ type )
@@ -106,7 +113,7 @@ public function get_shipping_info($order)
106113 public function get_order ($ order )
107114 {
108115 $ serializer = array (
109- 'id ' => $ order ->id ,
116+ 'id ' => ( string ) $ order ->id ,
110117 'articles ' => $ this ->get_articles ($ order ->get_items ()),
111118 'currency ' => get_woocommerce_currency (),
112119 'total_amount ' => Aplazame_Filters::decimals ($ order ->get_total ()),
@@ -116,9 +123,9 @@ public function get_order($order)
116123 return $ serializer ;
117124 }
118125
119- public function get_checkout ($ order , $ checkout_url , $ customer )
126+ public function get_checkout ($ order , $ checkout_url , $ user )
120127 {
121- return array (
128+ $ serializer = array (
122129 'toc ' => true ,
123130 'merchant ' => array (
124131 'confirmation_url ' => home_url (
@@ -130,11 +137,19 @@ public function get_checkout($order, $checkout_url, $customer)
130137 'success_url ' => html_entity_decode (
131138 $ order ->get_checkout_order_received_url ())
132139 ),
133- 'customer ' => $ this ->get_customer ($ customer ),
140+ 'customer ' => $ user ->id ?$ this ->get_user (
141+ $ user ):$ this ->get_customer ($ order ->billing_email ),
134142 'order ' => $ this ->get_order ($ order ),
135143 'billing ' => $ this ->get_address ($ order , 'billing ' ),
136- 'shipping ' => $ this ->get_shipping_info ($ order ),
137144 'meta ' => static ::get_meta ());
145+
146+ $ shipping_method = $ order ->get_shipping_method ();
147+
148+ if (!empty ($ shipping_method )) {
149+ $ serializer ['shipping ' ] = $ this ->get_shipping_info ($ order );
150+ }
151+
152+ return $ serializer ;
138153 }
139154
140155 public function get_history ($ qs )
0 commit comments