/includes/legacy/abstract-wc-legacy-order.php

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