WC_Abstract_Legacy_Order

Legacy Abstract Order.

Defined (1)

The class is defined in the following location(s).

/includes/legacy/abstract-wc-legacy-order.php  
  1. abstract class WC_Abstract_Legacy_Order extends WC_Data { 
  2.  
  3. /** 
  4. * Add coupon code to the order. 
  5. * @param string $code 
  6. * @param int $discount tax amount. 
  7. * @param int $discount_tax amount. 
  8. * @return int order item ID 
  9. * @throws WC_Data_Exception 
  10. */ 
  11. public function add_coupon( $code = array(), $discount = 0, $discount_tax = 0 ) { 
  12. wc_deprecated_function( 'WC_Order::add_coupon', '3.0', 'a new WC_Order_Item_Coupon object and add to order with WC_Order::add_item()' ); 
  13.  
  14. $item = new WC_Order_Item_Coupon(); 
  15. $item->set_props( array( 
  16. 'code' => $code,  
  17. 'discount' => $discount,  
  18. 'discount_tax' => $discount_tax,  
  19. 'order_id' => $this->get_id(),  
  20. ) ); 
  21. $item->save(); 
  22. $this->add_item( $item ); 
  23. wc_do_deprecated_action( 'woocommerce_order_add_coupon', array( $this->get_id(), $item->get_id(), $code, $discount, $discount_tax ), '3.0', 'woocommerce_new_order_item action instead.' ); 
  24. return $item->get_id(); 
  25.  
  26. /** 
  27. * Add a tax row to the order. 
  28. * @param array $args 
  29. * @param int $tax_amount amount of tax. 
  30. * @param int $shipping_tax_amount shipping amount. 
  31. * @return int order item ID 
  32. * @throws WC_Data_Exception 
  33. */ 
  34. public function add_tax( $tax_rate_id, $tax_amount = 0, $shipping_tax_amount = 0 ) { 
  35. wc_deprecated_function( 'WC_Order::add_tax', '3.0', 'a new WC_Order_Item_Tax object and add to order with WC_Order::add_item()' ); 
  36.  
  37. $item = new WC_Order_Item_Tax(); 
  38. $item->set_props( array( 
  39. 'rate_id' => $tax_rate_id,  
  40. 'tax_total' => $tax_amount,  
  41. 'shipping_tax_total' => $shipping_tax_amount,  
  42. ) ); 
  43. $item->set_rate( $tax_rate_id ); 
  44. $item->set_order_id( $this->get_id() ); 
  45. $item->save(); 
  46. $this->add_item( $item ); 
  47. wc_do_deprecated_action( 'woocommerce_order_add_tax', array( $this->get_id(), $item->get_id(), $tax_rate_id, $tax_amount, $shipping_tax_amount ), '3.0', 'woocommerce_new_order_item action instead.' ); 
  48. return $item->get_id(); 
  49.  
  50. /** 
  51. * Add a shipping row to the order. 
  52. * @param WC_Shipping_Rate shipping_rate 
  53. * @return int order item ID 
  54. * @throws WC_Data_Exception 
  55. */ 
  56. public function add_shipping( $shipping_rate ) { 
  57. wc_deprecated_function( 'WC_Order::add_shipping', '3.0', 'a new WC_Order_Item_Shipping object and add to order with WC_Order::add_item()' ); 
  58.  
  59. $item = new WC_Order_Item_Shipping(); 
  60. $item->set_props( array( 
  61. 'method_title' => $shipping_rate->label,  
  62. 'method_id' => $shipping_rate->id,  
  63. 'total' => wc_format_decimal( $shipping_rate->cost ),  
  64. 'taxes' => $shipping_rate->taxes,  
  65. 'order_id' => $this->get_id(),  
  66. ) ); 
  67. foreach ( $shipping_rate->get_meta_data() as $key => $value ) { 
  68. $item->add_meta_data( $key, $value, true ); 
  69. $item->save(); 
  70. $this->add_item( $item ); 
  71. wc_do_deprecated_action( 'woocommerce_order_add_shipping', array( $this->get_id(), $item->get_id(), $shipping_rate ), '3.0', 'woocommerce_new_order_item action instead.' ); 
  72. return $item->get_id(); 
  73.  
  74. /** 
  75. * Add a fee to the order. 
  76. * Order must be saved prior to adding items. 
  77. * Fee is an amount of money charged for a particular piece of work 
  78. * or for a particular right or service, and not supposed to be negative. 
  79. * @throws WC_Data_Exception 
  80. * @param object $fee Fee data. 
  81. * @return int Updated order item ID. 
  82. */ 
  83. public function add_fee( $fee ) { 
  84. wc_deprecated_function( 'WC_Order::add_fee', '3.0', 'a new WC_Order_Item_Fee object and add to order with WC_Order::add_item()' ); 
  85.  
  86. $item = new WC_Order_Item_Fee(); 
  87. $item->set_props( array( 
  88. 'name' => $fee->name,  
  89. 'tax_class' => $fee->taxable ? $fee->tax_class : 0,  
  90. 'total' => $fee->amount,  
  91. 'total_tax' => $fee->tax,  
  92. 'taxes' => array( 
  93. 'total' => $fee->tax_data,  
  94. ),  
  95. 'order_id' => $this->get_id(),  
  96. ) ); 
  97. $item->save(); 
  98. $this->add_item( $item ); 
  99. wc_do_deprecated_action( 'woocommerce_order_add_fee', array( $this->get_id(), $item->get_id(), $fee ), '3.0', 'woocommerce_new_order_item action instead.' ); 
  100. return $item->get_id(); 
  101.  
  102. /** 
  103. * Update a line item for the order. 
  104. * Note this does not update order totals. 
  105. * @param object|int $item order item ID or item object. 
  106. * @param WC_Product $product 
  107. * @param array $args data to update. 
  108. * @return int updated order item ID 
  109. * @throws WC_Data_Exception 
  110. */ 
  111. public function update_product( $item, $product, $args ) { 
  112. wc_deprecated_function( 'WC_Order::update_product', '3.0', 'an interaction with the WC_Order_Item_Product class' ); 
  113. if ( is_numeric( $item ) ) { 
  114. $item = $this->get_item( $item ); 
  115. if ( ! is_object( $item ) || ! $item->is_type( 'line_item' ) ) { 
  116. return false; 
  117. if ( ! $this->get_id() ) { 
  118. $this->save(); // Order must exist 
  119.  
  120. // BW compatibility with old args 
  121. if ( isset( $args['totals'] ) ) { 
  122. foreach ( $args['totals'] as $key => $value ) { 
  123. if ( 'tax' === $key ) { 
  124. $args['total_tax'] = $value; 
  125. } elseif ( 'tax_data' === $key ) { 
  126. $args['taxes'] = $value; 
  127. } else { 
  128. $args[ $key ] = $value; 
  129.  
  130. // Handly qty if set 
  131. if ( isset( $args['qty'] ) ) { 
  132. if ( $product->backorders_require_notification() && $product->is_on_backorder( $args['qty'] ) ) { 
  133. $item->add_meta_data( apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $args['qty'] - max( 0, $product->get_stock_quantity() ), true ); 
  134. $args['subtotal'] = $args['subtotal'] ? $args['subtotal'] : wc_get_price_excluding_tax( $product, array( 'qty' => $args['qty'] ) ); 
  135. $args['total'] = $args['total'] ? $args['total'] : wc_get_price_excluding_tax( $product, array( 'qty' => $args['qty'] ) ); 
  136.  
  137. $item->set_order_id( $this->get_id() ); 
  138. $item->set_props( $args ); 
  139. $item->save(); 
  140. do_action( 'woocommerce_order_edit_product', $this->get_id(), $item->get_id(), $args, $product ); 
  141.  
  142. return $item->get_id(); 
  143.  
  144. /** 
  145. * Update coupon for order. Note this does not update order totals. 
  146. * @param object|int $item 
  147. * @param array $args 
  148. * @return int updated order item ID 
  149. * @throws WC_Data_Exception 
  150. */ 
  151. public function update_coupon( $item, $args ) { 
  152. wc_deprecated_function( 'WC_Order::update_coupon', '3.0', 'an interaction with the WC_Order_Item_Coupon class' ); 
  153. if ( is_numeric( $item ) ) { 
  154. $item = $this->get_item( $item ); 
  155. if ( ! is_object( $item ) || ! $item->is_type( 'coupon' ) ) { 
  156. return false; 
  157. if ( ! $this->get_id() ) { 
  158. $this->save(); // Order must exist 
  159.  
  160. // BW compatibility for old args 
  161. if ( isset( $args['discount_amount'] ) ) { 
  162. $args['discount'] = $args['discount_amount']; 
  163. if ( isset( $args['discount_amount_tax'] ) ) { 
  164. $args['discount_tax'] = $args['discount_amount_tax']; 
  165.  
  166. $item->set_order_id( $this->get_id() ); 
  167. $item->set_props( $args ); 
  168. $item->save(); 
  169.  
  170. do_action( 'woocommerce_order_update_coupon', $this->get_id(), $item->get_id(), $args ); 
  171.  
  172. return $item->get_id(); 
  173.  
  174. /** 
  175. * Update shipping method for order. 
  176. * Note this does not update the order total. 
  177. * @param object|int $item 
  178. * @param array $args 
  179. * @return int updated order item ID 
  180. * @throws WC_Data_Exception 
  181. */ 
  182. public function update_shipping( $item, $args ) { 
  183. wc_deprecated_function( 'WC_Order::update_shipping', '3.0', 'an interaction with the WC_Order_Item_Shipping class' ); 
  184. if ( is_numeric( $item ) ) { 
  185. $item = $this->get_item( $item ); 
  186. if ( ! is_object( $item ) || ! $item->is_type( 'shipping' ) ) { 
  187. return false; 
  188. if ( ! $this->get_id() ) { 
  189. $this->save(); // Order must exist 
  190.  
  191. // BW compatibility for old args 
  192. if ( isset( $args['cost'] ) ) { 
  193. $args['total'] = $args['cost']; 
  194.  
  195. $item->set_order_id( $this->get_id() ); 
  196. $item->set_props( $args ); 
  197. $item->save(); 
  198. $this->calculate_shipping(); 
  199.  
  200. do_action( 'woocommerce_order_update_shipping', $this->get_id(), $item->get_id(), $args ); 
  201.  
  202. return $item->get_id(); 
  203.  
  204. /** 
  205. * Update fee for order. 
  206. * Note this does not update order totals. 
  207. * @param object|int $item 
  208. * @param array $args 
  209. * @return int updated order item ID 
  210. * @throws WC_Data_Exception 
  211. */ 
  212. public function update_fee( $item, $args ) { 
  213. wc_deprecated_function( 'WC_Order::update_fee', '3.0', 'an interaction with the WC_Order_Item_Fee class' ); 
  214. if ( is_numeric( $item ) ) { 
  215. $item = $this->get_item( $item ); 
  216. if ( ! is_object( $item ) || ! $item->is_type( 'fee' ) ) { 
  217. return false; 
  218. if ( ! $this->get_id() ) { 
  219. $this->save(); // Order must exist 
  220.  
  221. $item->set_order_id( $this->get_id() ); 
  222. $item->set_props( $args ); 
  223. $item->save(); 
  224.  
  225. do_action( 'woocommerce_order_update_fee', $this->get_id(), $item->get_id(), $args ); 
  226.  
  227. return $item->get_id(); 
  228.  
  229. /** 
  230. * Update tax line on order. 
  231. * Note this does not update order totals. 
  232. * @since 3.0 
  233. * @param object|int $item 
  234. * @param array $args 
  235. * @return int updated order item ID 
  236. * @throws WC_Data_Exception 
  237. */ 
  238. public function update_tax( $item, $args ) { 
  239. wc_deprecated_function( 'WC_Order::update_tax', '3.0', 'an interaction with the WC_Order_Item_Tax class' ); 
  240. if ( is_numeric( $item ) ) { 
  241. $item = $this->get_item( $item ); 
  242. if ( ! is_object( $item ) || ! $item->is_type( 'tax' ) ) { 
  243. return false; 
  244. if ( ! $this->get_id() ) { 
  245. $this->save(); // Order must exist 
  246.  
  247. $item->set_order_id( $this->get_id() ); 
  248. $item->set_props( $args ); 
  249. $item->save(); 
  250.  
  251. do_action( 'woocommerce_order_update_tax', $this->get_id(), $item->get_id(), $args ); 
  252.  
  253. return $item->get_id(); 
  254.  
  255. /** 
  256. * Get a product (either product or variation). 
  257. * @deprecated Add deprecation notices in future release. Replaced with $item->get_product() 
  258. * @param object $item 
  259. * @return WC_Product|bool 
  260. */ 
  261. public function get_product_from_item( $item ) { 
  262. if ( is_callable( array( $item, 'get_product' ) ) ) { 
  263. $product = $item->get_product(); 
  264. } else { 
  265. $product = false; 
  266. return apply_filters( 'woocommerce_get_product_from_item', $product, $item, $this ); 
  267.  
  268. /** 
  269. * Set the customer address. 
  270. * @param array $address Address data. 
  271. * @param string $type billing or shipping. 
  272. */ 
  273. public function set_address( $address, $type = 'billing' ) { 
  274. foreach ( $address as $key => $value ) { 
  275. update_post_meta( $this->get_id(), "_{$type}_" . $key, $value ); 
  276. if ( is_callable( array( $this, "set_{$type}_{$key}" ) ) ) { 
  277. $this->{"set_{$type}_{$key}"}( $value ); 
  278.  
  279. /** 
  280. * Set an order total. 
  281. * @param float $amount 
  282. * @param string $total_type 
  283. * @return bool 
  284. */ 
  285. public function legacy_set_total( $amount, $total_type = 'total' ) { 
  286. if ( ! in_array( $total_type, array( 'shipping', 'tax', 'shipping_tax', 'total', 'cart_discount', 'cart_discount_tax' ) ) ) { 
  287. return false; 
  288.  
  289. switch ( $total_type ) { 
  290. case 'total' : 
  291. $amount = wc_format_decimal( $amount, wc_get_price_decimals() ); 
  292. $this->set_total( $amount ); 
  293. update_post_meta( $this->get_id(), '_order_total', $amount ); 
  294. break; 
  295. case 'cart_discount' : 
  296. $amount = wc_format_decimal( $amount ); 
  297. $this->set_discount_total( $amount ); 
  298. update_post_meta( $this->get_id(), '_cart_discount', $amount ); 
  299. break; 
  300. case 'cart_discount_tax' : 
  301. $amount = wc_format_decimal( $amount ); 
  302. $this->set_discount_tax( $amount ); 
  303. update_post_meta( $this->get_id(), '_cart_discount_tax', $amount ); 
  304. break; 
  305. case 'shipping' : 
  306. $amount = wc_format_decimal( $amount ); 
  307. $this->set_shipping_total( $amount ); 
  308. update_post_meta( $this->get_id(), '_order_shipping', $amount ); 
  309. break; 
  310. case 'shipping_tax' : 
  311. $amount = wc_format_decimal( $amount ); 
  312. $this->set_shipping_tax( $amount ); 
  313. update_post_meta( $this->get_id(), '_order_shipping_tax', $amount ); 
  314. break; 
  315. case 'tax' : 
  316. $amount = wc_format_decimal( $amount ); 
  317. $this->set_cart_tax( $amount ); 
  318. update_post_meta( $this->get_id(), '_order_tax', $amount ); 
  319. break; 
  320.  
  321. return true; 
  322.  
  323. /** 
  324. * Magic __isset method for backwards compatibility. Handles legacy properties which could be accessed directly in the past. 
  325. * @param string $key 
  326. * @return bool 
  327. */ 
  328. public function __isset( $key ) { 
  329. $legacy_props = array( 'completed_date', 'id', 'order_type', 'post', 'status', 'post_status', 'customer_note', 'customer_message', 'user_id', 'customer_user', 'prices_include_tax', 'tax_display_cart', 'display_totals_ex_tax', 'display_cart_ex_tax', 'order_date', 'modified_date', 'cart_discount', 'cart_discount_tax', 'order_shipping', 'order_shipping_tax', 'order_total', 'order_tax', 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_state', 'billing_postcode', 'billing_country', 'billing_phone', 'billing_email', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_state', 'shipping_postcode', 'shipping_country', 'customer_ip_address', 'customer_user_agent', 'payment_method_title', 'payment_method', 'order_currency' ); 
  330. return $this->get_id() ? ( in_array( $key, $legacy_props ) || metadata_exists( 'post', $this->get_id(), '_' . $key ) ) : false; 
  331.  
  332. /** 
  333. * Magic __get method for backwards compatibility. 
  334. * @param string $key 
  335. * @return mixed 
  336. */ 
  337. public function __get( $key ) { 
  338. wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '3.0' ); 
  339.  
  340. if ( 'completed_date' === $key ) { 
  341. return $this->get_date_completed() ? gmdate( 'Y-m-d H:i:s', $this->get_date_completed()->getOffsetTimestamp() ) : ''; 
  342. } elseif ( 'paid_date' === $key ) { 
  343. return $this->get_date_paid() ? gmdate( 'Y-m-d H:i:s', $this->get_date_paid()->getOffsetTimestamp() ) : ''; 
  344. } elseif ( 'modified_date' === $key ) { 
  345. return $this->get_date_modified() ? gmdate( 'Y-m-d H:i:s', $this->get_date_modified()->getOffsetTimestamp() ) : ''; 
  346. } elseif ( 'order_date' === $key ) { 
  347. return $this->get_date_created() ? gmdate( 'Y-m-d H:i:s', $this->get_date_created()->getOffsetTimestamp() ) : ''; 
  348. } elseif ( 'id' === $key ) { 
  349. return $this->get_id(); 
  350. } elseif ( 'post' === $key ) { 
  351. return get_post( $this->get_id() ); 
  352. } elseif ( 'status' === $key ) { 
  353. return $this->get_status(); 
  354. } elseif ( 'post_status' === $key ) { 
  355. return get_post_status( $this->get_id() ); 
  356. } elseif ( 'customer_message' === $key || 'customer_note' === $key ) { 
  357. return $this->get_customer_note(); 
  358. } elseif ( in_array( $key, array( 'user_id', 'customer_user' ) ) ) { 
  359. return $this->get_customer_id(); 
  360. } elseif ( 'tax_display_cart' === $key ) { 
  361. return get_option( 'woocommerce_tax_display_cart' ); 
  362. } elseif ( 'display_totals_ex_tax' === $key ) { 
  363. return 'excl' === get_option( 'woocommerce_tax_display_cart' ); 
  364. } elseif ( 'display_cart_ex_tax' === $key ) { 
  365. return 'excl' === get_option( 'woocommerce_tax_display_cart' ); 
  366. } elseif ( 'cart_discount' === $key ) { 
  367. return $this->get_total_discount(); 
  368. } elseif ( 'cart_discount_tax' === $key ) { 
  369. return $this->get_discount_tax(); 
  370. } elseif ( 'order_tax' === $key ) { 
  371. return $this->get_cart_tax(); 
  372. } elseif ( 'order_shipping_tax' === $key ) { 
  373. return $this->get_shipping_tax(); 
  374. } elseif ( 'order_shipping' === $key ) { 
  375. return $this->get_shipping_total(); 
  376. } elseif ( 'order_total' === $key ) { 
  377. return $this->get_total(); 
  378. } elseif ( 'order_type' === $key ) { 
  379. return $this->get_type(); 
  380. } elseif ( 'order_currency' === $key ) { 
  381. return $this->get_currency(); 
  382. } elseif ( 'order_version' === $key ) { 
  383. return $this->get_version(); 
  384. } elseif ( is_callable( array( $this, "get_{$key}" ) ) ) { 
  385. return $this->{"get_{$key}"}(); 
  386. } else { 
  387. return get_post_meta( $this->get_id(), '_' . $key, true ); 
  388.  
  389. /** 
  390. * has_meta function for order items. This is different to the WC_Data 
  391. * version and should be removed in future versions. 
  392. * @deprecated 
  393. * @return array of meta data. 
  394. */ 
  395. public function has_meta( $order_item_id ) { 
  396. global $wpdb; 
  397.  
  398. wc_deprecated_function( 'WC_Order::has_meta( $order_item_id )', '3.0', 'WC_Order_item::get_meta_data' ); 
  399.  
  400. return $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value, meta_id, order_item_id 
  401. FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d 
  402. ORDER BY meta_id", absint( $order_item_id ) ), ARRAY_A ); 
  403.  
  404. /** 
  405. * Display meta data belonging to an item. 
  406. * @param array $item 
  407. */ 
  408. public function display_item_meta( $item ) { 
  409. wc_deprecated_function( 'WC_Order::display_item_meta', '3.0', 'wc_display_item_meta' ); 
  410. $product = $item->get_product(); 
  411. $item_meta = new WC_Order_Item_Meta( $item, $product ); 
  412. $item_meta->display(); 
  413.  
  414. /** 
  415. * Display download links for an order item. 
  416. * @param array $item 
  417. */ 
  418. public function display_item_downloads( $item ) { 
  419. wc_deprecated_function( 'WC_Order::display_item_downloads', '3.0', 'wc_display_item_downloads' ); 
  420. $product = $item->get_product(); 
  421.  
  422. if ( $product && $product->exists() && $product->is_downloadable() && $this->is_download_permitted() ) { 
  423. $download_files = $this->get_item_downloads( $item ); 
  424. $i = 0; 
  425. $links = array(); 
  426.  
  427. foreach ( $download_files as $download_id => $file ) { 
  428. $i++; 
  429. /** translators: 1: current item count */ 
  430. $prefix = count( $download_files ) > 1 ? sprintf( __( 'Download %d', 'woocommerce' ), $i ) : __( 'Download', 'woocommerce' ); 
  431. $links[] = '<small class="download-url">' . $prefix . ': <a href="' . esc_url( $file['download_url'] ) . '" target="_blank">' . esc_html( $file['name'] ) . '</a></small>' . "\n"; 
  432.  
  433. echo '<br/>' . implode( '<br/>', $links ); 
  434.  
  435. /** 
  436. * Get the Download URL. 
  437. * @param int $product_id 
  438. * @param int $download_id 
  439. * @return string 
  440. */ 
  441. public function get_download_url( $product_id, $download_id ) { 
  442. wc_deprecated_function( 'WC_Order::get_download_url', '3.0', 'WC_Order_Item_Product::get_item_download_url' ); 
  443. return add_query_arg( array( 
  444. 'download_file' => $product_id,  
  445. 'order' => $this->get_order_key(),  
  446. 'email' => urlencode( $this->get_billing_email() ),  
  447. 'key' => $download_id,  
  448. ), trailingslashit( home_url() ) ); 
  449.  
  450. /** 
  451. * Get the downloadable files for an item in this order. 
  452. * @param array $item 
  453. * @return array 
  454. */ 
  455. public function get_item_downloads( $item ) { 
  456. wc_deprecated_function( 'WC_Order::get_item_downloads', '3.0', 'WC_Order_Item_Product::get_item_downloads' ); 
  457.  
  458. if ( ! $item instanceof WC_Order_Item ) { 
  459. if ( ! empty( $item['variation_id'] ) ) { 
  460. $product_id = $item['variation_id']; 
  461. } elseif ( ! empty( $item['product_id'] ) ) { 
  462. $product_id = $item['product_id']; 
  463. } else { 
  464. return array(); 
  465.  
  466. // Create a 'virtual' order item to allow retrieving item downloads when 
  467. // an array of product_id is passed instead of actual order item. 
  468. $item = new WC_Order_Item_Product(); 
  469. $item->set_product( wc_get_product( $product_id ) ); 
  470. $item->set_order_id( $this->get_id() ); 
  471.  
  472. return $item->get_item_downloads(); 
  473.  
  474. /** 
  475. * Gets shipping total. Alias of WC_Order::get_shipping_total(). 
  476. * @deprecated 3.0.0 since this is an alias only. 
  477. * @return float 
  478. */ 
  479. public function get_total_shipping() { 
  480. return $this->get_shipping_total(); 
  481.  
  482. /** 
  483. * Get order item meta. 
  484. * @deprecated 3.0.0 
  485. * @param mixed $order_item_id 
  486. * @param string $key (default: '') 
  487. * @param bool $single (default: false) 
  488. * @return array|string 
  489. */ 
  490. public function get_item_meta( $order_item_id, $key = '', $single = false ) { 
  491. wc_deprecated_function( 'WC_Order::get_item_meta', '3.0', 'wc_get_order_item_meta' ); 
  492. return get_metadata( 'order_item', $order_item_id, $key, $single ); 
  493.  
  494. /** 
  495. * Get all item meta data in array format in the order it was saved. Does not group meta by key like get_item_meta(). 
  496. * @param mixed $order_item_id 
  497. * @return array of objects 
  498. */ 
  499. public function get_item_meta_array( $order_item_id ) { 
  500. wc_deprecated_function( 'WC_Order::get_item_meta_array', '3.0', 'WC_Order_Item::get_meta_data() (note the format has changed)' ); 
  501. $item = $this->get_item( $order_item_id ); 
  502. $meta_data = $item->get_meta_data(); 
  503. $item_meta_array = array(); 
  504.  
  505. foreach ( $meta_data as $meta ) { 
  506. $item_meta_array[ $meta->id ] = $meta; 
  507.  
  508. return $item_meta_array; 
  509.  
  510. /** 
  511. * Expand item meta into the $item array. 
  512. * @deprecated 3.0.0 Item meta no longer expanded due to new order item 
  513. * classes. This function now does nothing to avoid data breakage. 
  514. * @param array $item before expansion. 
  515. * @return array 
  516. */ 
  517. public function expand_item_meta( $item ) { 
  518. wc_deprecated_function( 'WC_Order::expand_item_meta', '3.0' ); 
  519. return $item; 
  520.  
  521. /** 
  522. * Load the order object. Called from the constructor. 
  523. * @deprecated 3.0.0 Logic moved to constructor 
  524. * @param int|object|WC_Order $order Order to init. 
  525. */ 
  526. protected function init( $order ) { 
  527. wc_deprecated_function( 'WC_Order::init', '3.0', 'Logic moved to constructor' ); 
  528. if ( is_numeric( $order ) ) { 
  529. $this->set_id( $order ); 
  530. } elseif ( $order instanceof WC_Order ) { 
  531. $this->set_id( absint( $order->get_id() ) ); 
  532. } elseif ( isset( $order->ID ) ) { 
  533. $this->set_id( absint( $order->ID ) ); 
  534. $this->set_object_read( false ); 
  535. $this->data_store->read( $this ); 
  536.  
  537. /** 
  538. * Gets an order from the database. 
  539. * @deprecated 3.0 
  540. * @param int $id (default: 0). 
  541. * @return bool 
  542. */ 
  543. public function get_order( $id = 0 ) { 
  544. wc_deprecated_function( 'WC_Order::get_order', '3.0' ); 
  545.  
  546. if ( ! $id ) { 
  547. return false; 
  548.  
  549. $result = get_post( $id ); 
  550.  
  551. if ( $result ) { 
  552. $this->populate( $result ); 
  553. return true; 
  554.  
  555. return false; 
  556.  
  557. /** 
  558. * Populates an order from the loaded post data. 
  559. * @deprecated 3.0 
  560. * @param mixed $result 
  561. */ 
  562. public function populate( $result ) { 
  563. wc_deprecated_function( 'WC_Order::populate', '3.0' ); 
  564. $this->set_id( $result->ID ); 
  565. $this->set_object_read( false ); 
  566. $this->data_store->read( $this ); 
  567.  
  568. /** 
  569. * Cancel the order and restore the cart (before payment). 
  570. * @deprecated 3.0.0 Moved to event handler. 
  571. * @param string $note (default: '') Optional note to add. 
  572. */ 
  573. public function cancel_order( $note = '' ) { 
  574. wc_deprecated_function( 'WC_Order::cancel_order', '3.0', 'WC_Order::update_status' ); 
  575. WC()->session->set( 'order_awaiting_payment', false ); 
  576. $this->update_status( 'cancelled', $note ); 
  577.  
  578. /** 
  579. * Record sales. 
  580. * @deprecated 3.0.0 
  581. */ 
  582. public function record_product_sales() { 
  583. wc_deprecated_function( 'WC_Order::record_product_sales', '3.0', 'wc_update_total_sales_counts' ); 
  584. wc_update_total_sales_counts( $this->get_id() ); 
  585.  
  586. /** 
  587. * Increase applied coupon counts. 
  588. * @deprecated 3.0.0 
  589. */ 
  590. public function increase_coupon_usage_counts() { 
  591. wc_deprecated_function( 'WC_Order::increase_coupon_usage_counts', '3.0', 'wc_update_coupon_usage_counts' ); 
  592. wc_update_coupon_usage_counts( $this->get_id() ); 
  593.  
  594. /** 
  595. * Decrease applied coupon counts. 
  596. * @deprecated 3.0.0 
  597. */ 
  598. public function decrease_coupon_usage_counts() { 
  599. wc_deprecated_function( 'WC_Order::decrease_coupon_usage_counts', '3.0', 'wc_update_coupon_usage_counts' ); 
  600. wc_update_coupon_usage_counts( $this->get_id() ); 
  601.  
  602. /** 
  603. * Reduce stock levels for all line items in the order. 
  604. * @deprecated 3.0.0 
  605. */ 
  606. public function reduce_order_stock() { 
  607. wc_deprecated_function( 'WC_Order::reduce_order_stock', '3.0', 'wc_reduce_stock_levels' ); 
  608. wc_reduce_stock_levels( $this->get_id() ); 
  609.  
  610. /** 
  611. * Send the stock notifications. 
  612. * @deprecated 3.0.0 No longer needs to be called directly. 
  613. */ 
  614. public function send_stock_notifications( $product, $new_stock, $qty_ordered ) { 
  615. wc_deprecated_function( 'WC_Order::send_stock_notifications', '3.0' ); 
  616.  
  617. /** 
  618. * Output items for display in html emails. 
  619. * @deprecated 3.0.0 Moved to template functions. 
  620. * @param array $args Items args. 
  621. * @return string 
  622. */ 
  623. public function email_order_items_table( $args = array() ) { 
  624. wc_deprecated_function( 'WC_Order::email_order_items_table', '3.0', 'wc_get_email_order_items' ); 
  625. return wc_get_email_order_items( $this, $args ); 
  626.  
  627. /** 
  628. * Get currency. 
  629. * @deprecated 3.0.0 
  630. */ 
  631. public function get_order_currency() { 
  632. wc_deprecated_function( 'WC_Order::get_order_currency', '3.0', 'WC_Order::get_currency' ); 
  633. return apply_filters( 'woocommerce_get_order_currency', $this->get_currency(), $this );