class-wc-order.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  1. <?php
  2. /**
  3. * Regular order
  4. *
  5. * @package WooCommerce\Classes
  6. * @version 2.2.0
  7. */
  8. defined( 'ABSPATH' ) || exit;
  9. /**
  10. * Order Class.
  11. *
  12. * These are regular WooCommerce orders, which extend the abstract order class.
  13. */
  14. class WC_Order extends WC_Abstract_Order {
  15. /**
  16. * Stores data about status changes so relevant hooks can be fired.
  17. *
  18. * @var bool|array
  19. */
  20. protected $status_transition = false;
  21. /**
  22. * Order Data array. This is the core order data exposed in APIs since 3.0.0.
  23. *
  24. * @since 3.0.0
  25. * @var array
  26. */
  27. protected $data = array(
  28. // Abstract order props.
  29. 'parent_id' => 0,
  30. 'status' => '',
  31. 'currency' => '',
  32. 'version' => '',
  33. 'prices_include_tax' => false,
  34. 'date_created' => null,
  35. 'date_modified' => null,
  36. 'discount_total' => 0,
  37. 'discount_tax' => 0,
  38. 'shipping_total' => 0,
  39. 'shipping_tax' => 0,
  40. 'cart_tax' => 0,
  41. 'total' => 0,
  42. 'total_tax' => 0,
  43. // Order props.
  44. 'customer_id' => 0,
  45. 'order_key' => '',
  46. 'billing' => array(
  47. 'first_name' => '',
  48. 'last_name' => '',
  49. 'company' => '',
  50. 'address_1' => '',
  51. 'address_2' => '',
  52. 'city' => '',
  53. 'state' => '',
  54. 'postcode' => '',
  55. 'country' => '',
  56. 'email' => '',
  57. 'phone' => '',
  58. ),
  59. 'shipping' => array(
  60. 'first_name' => '',
  61. 'last_name' => '',
  62. 'company' => '',
  63. 'address_1' => '',
  64. 'address_2' => '',
  65. 'city' => '',
  66. 'state' => '',
  67. 'postcode' => '',
  68. 'country' => '',
  69. ),
  70. 'payment_method' => '',
  71. 'payment_method_title' => '',
  72. 'transaction_id' => '',
  73. 'customer_ip_address' => '',
  74. 'customer_user_agent' => '',
  75. 'created_via' => '',
  76. 'customer_note' => '',
  77. 'date_completed' => null,
  78. 'date_paid' => null,
  79. 'cart_hash' => '',
  80. );
  81. /**
  82. * When a payment is complete this function is called.
  83. *
  84. * Most of the time this should mark an order as 'processing' so that admin can process/post the items.
  85. * If the cart contains only downloadable items then the order is 'completed' since the admin needs to take no action.
  86. * Stock levels are reduced at this point.
  87. * Sales are also recorded for products.
  88. * Finally, record the date of payment.
  89. *
  90. * @param string $transaction_id Optional transaction id to store in post meta.
  91. * @return bool success
  92. */
  93. public function payment_complete( $transaction_id = '' ) {
  94. if ( ! $this->get_id() ) { // Order must exist.
  95. return false;
  96. }
  97. try {
  98. do_action( 'woocommerce_pre_payment_complete', $this->get_id() );
  99. if ( WC()->session ) {
  100. WC()->session->set( 'order_awaiting_payment', false );
  101. }
  102. if ( $this->has_status( apply_filters( 'woocommerce_valid_order_statuses_for_payment_complete', array( 'on-hold', 'pending', 'failed', 'cancelled' ), $this ) ) ) {
  103. if ( ! empty( $transaction_id ) ) {
  104. $this->set_transaction_id( $transaction_id );
  105. }
  106. if ( ! $this->get_date_paid( 'edit' ) ) {
  107. $this->set_date_paid( current_time( 'timestamp', true ) );
  108. }
  109. $this->set_status( apply_filters( 'woocommerce_payment_complete_order_status', $this->needs_processing() ? 'processing' : 'completed', $this->get_id(), $this ) );
  110. $this->save();
  111. do_action( 'woocommerce_payment_complete', $this->get_id() );
  112. } else {
  113. do_action( 'woocommerce_payment_complete_order_status_' . $this->get_status(), $this->get_id() );
  114. }
  115. } catch ( Exception $e ) {
  116. /**
  117. * If there was an error completing the payment, log to a file and add an order note so the admin can take action.
  118. */
  119. $logger = wc_get_logger();
  120. $logger->error(
  121. sprintf( 'Error completing payment for order #%d', $this->get_id() ), array(
  122. 'order' => $this,
  123. 'error' => $e,
  124. )
  125. );
  126. $this->add_order_note( __( 'Payment complete event failed.', 'woocommerce' ) . ' ' . $e->getMessage() );
  127. return false;
  128. }
  129. return true;
  130. }
  131. /**
  132. * Gets order total - formatted for display.
  133. *
  134. * @param string $tax_display Type of tax display.
  135. * @param bool $display_refunded If should include refunded value.
  136. *
  137. * @return string
  138. */
  139. public function get_formatted_order_total( $tax_display = '', $display_refunded = true ) {
  140. $formatted_total = wc_price( $this->get_total(), array( 'currency' => $this->get_currency() ) );
  141. $order_total = $this->get_total();
  142. $total_refunded = $this->get_total_refunded();
  143. $tax_string = '';
  144. // Tax for inclusive prices.
  145. if ( wc_tax_enabled() && 'incl' === $tax_display ) {
  146. $tax_string_array = array();
  147. $tax_totals = $this->get_tax_totals();
  148. if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) {
  149. foreach ( $tax_totals as $code => $tax ) {
  150. $tax_amount = ( $total_refunded && $display_refunded ) ? wc_price( WC_Tax::round( $tax->amount - $this->get_total_tax_refunded_by_rate_id( $tax->rate_id ) ), array( 'currency' => $this->get_currency() ) ) : $tax->formatted_amount;
  151. $tax_string_array[] = sprintf( '%s %s', $tax_amount, $tax->label );
  152. }
  153. } elseif ( ! empty( $tax_totals ) ) {
  154. $tax_amount = ( $total_refunded && $display_refunded ) ? $this->get_total_tax() - $this->get_total_tax_refunded() : $this->get_total_tax();
  155. $tax_string_array[] = sprintf( '%s %s', wc_price( $tax_amount, array( 'currency' => $this->get_currency() ) ), WC()->countries->tax_or_vat() );
  156. }
  157. if ( ! empty( $tax_string_array ) ) {
  158. /* translators: %s: taxes */
  159. $tax_string = ' <small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) . '</small>';
  160. }
  161. }
  162. if ( $total_refunded && $display_refunded ) {
  163. $formatted_total = '<del>' . strip_tags( $formatted_total ) . '</del> <ins>' . wc_price( $order_total - $total_refunded, array( 'currency' => $this->get_currency() ) ) . $tax_string . '</ins>';
  164. } else {
  165. $formatted_total .= $tax_string;
  166. }
  167. /**
  168. * Filter WooCommerce formatted order total.
  169. *
  170. * @param string $formatted_total Total to display.
  171. * @param WC_Order $order Order data.
  172. * @param string $tax_display Type of tax display.
  173. * @param bool $display_refunded If should include refunded value.
  174. */
  175. return apply_filters( 'woocommerce_get_formatted_order_total', $formatted_total, $this, $tax_display, $display_refunded );
  176. }
  177. /*
  178. |--------------------------------------------------------------------------
  179. | CRUD methods
  180. |--------------------------------------------------------------------------
  181. |
  182. | Methods which create, read, update and delete orders from the database.
  183. | Written in abstract fashion so that the way orders are stored can be
  184. | changed more easily in the future.
  185. |
  186. | A save method is included for convenience (chooses update or create based
  187. | on if the order exists yet).
  188. |
  189. */
  190. /**
  191. * Save data to the database.
  192. *
  193. * @since 3.0.0
  194. * @return int order ID
  195. */
  196. public function save() {
  197. try {
  198. $this->maybe_set_user_billing_email();
  199. if ( $this->data_store ) {
  200. // Trigger action before saving to the DB. Allows you to adjust object props before save.
  201. do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
  202. if ( $this->get_id() ) {
  203. $this->data_store->update( $this );
  204. } else {
  205. $this->data_store->create( $this );
  206. }
  207. }
  208. $this->save_items();
  209. $this->status_transition();
  210. } catch ( Exception $e ) {
  211. $logger = wc_get_logger();
  212. $logger->error(
  213. sprintf( 'Error saving order #%d', $this->get_id() ), array(
  214. 'order' => $this,
  215. 'error' => $e,
  216. )
  217. );
  218. $this->add_order_note( __( 'Error saving order.', 'woocommerce' ) . ' ' . $e->getMessage() );
  219. }
  220. return $this->get_id();
  221. }
  222. /**
  223. * Set order status.
  224. *
  225. * @since 3.0.0
  226. * @param string $new_status Status to change the order to. No internal wc- prefix is required.
  227. * @param string $note Optional note to add.
  228. * @param bool $manual_update Is this a manual order status change?.
  229. * @return array
  230. */
  231. public function set_status( $new_status, $note = '', $manual_update = false ) {
  232. $result = parent::set_status( $new_status );
  233. if ( true === $this->object_read && ! empty( $result['from'] ) && $result['from'] !== $result['to'] ) {
  234. $this->status_transition = array(
  235. 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $result['from'],
  236. 'to' => $result['to'],
  237. 'note' => $note,
  238. 'manual' => (bool) $manual_update,
  239. );
  240. $this->maybe_set_date_paid();
  241. $this->maybe_set_date_completed();
  242. }
  243. return $result;
  244. }
  245. /**
  246. * Maybe set date paid.
  247. *
  248. * Sets the date paid variable when transitioning to the payment complete
  249. * order status. This is either processing or completed. This is not filtered
  250. * to avoid infinite loops e.g. if loading an order via the filter.
  251. *
  252. * Date paid is set once in this manner - only when it is not already set.
  253. * This ensures the data exists even if a gateway does not use the
  254. * `payment_complete` method.
  255. *
  256. * @since 3.0.0
  257. */
  258. public function maybe_set_date_paid() {
  259. if ( ! $this->get_date_paid( 'edit' ) && $this->has_status( apply_filters( 'woocommerce_payment_complete_order_status', $this->needs_processing() ? 'processing' : 'completed', $this->get_id(), $this ) ) ) {
  260. $this->set_date_paid( current_time( 'timestamp', true ) );
  261. }
  262. }
  263. /**
  264. * Maybe set date completed.
  265. *
  266. * Sets the date completed variable when transitioning to completed status.
  267. *
  268. * @since 3.0.0
  269. */
  270. protected function maybe_set_date_completed() {
  271. if ( $this->has_status( 'completed' ) ) {
  272. $this->set_date_completed( current_time( 'timestamp', true ) );
  273. }
  274. }
  275. /**
  276. * Updates status of order immediately.
  277. *
  278. * @uses WC_Order::set_status()
  279. * @param string $new_status Status to change the order to. No internal wc- prefix is required.
  280. * @param string $note Optional note to add.
  281. * @param bool $manual Is this a manual order status change?.
  282. * @return bool
  283. */
  284. public function update_status( $new_status, $note = '', $manual = false ) {
  285. if ( ! $this->get_id() ) { // Order must exist.
  286. return false;
  287. }
  288. try {
  289. $this->set_status( $new_status, $note, $manual );
  290. $this->save();
  291. } catch ( Exception $e ) {
  292. $logger = wc_get_logger();
  293. $logger->error(
  294. sprintf( 'Error updating status for order #%d', $this->get_id() ), array(
  295. 'order' => $this,
  296. 'error' => $e,
  297. )
  298. );
  299. $this->add_order_note( __( 'Update status event failed.', 'woocommerce' ) . ' ' . $e->getMessage() );
  300. return false;
  301. }
  302. return true;
  303. }
  304. /**
  305. * Handle the status transition.
  306. */
  307. protected function status_transition() {
  308. $status_transition = $this->status_transition;
  309. // Reset status transition variable.
  310. $this->status_transition = false;
  311. if ( $status_transition ) {
  312. try {
  313. do_action( 'woocommerce_order_status_' . $status_transition['to'], $this->get_id(), $this );
  314. if ( ! empty( $status_transition['from'] ) ) {
  315. /* translators: 1: old order status 2: new order status */
  316. $transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );
  317. do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
  318. do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
  319. } else {
  320. /* translators: %s: new order status */
  321. $transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) );
  322. }
  323. // Note the transition occurred.
  324. $this->add_order_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
  325. } catch ( Exception $e ) {
  326. $logger = wc_get_logger();
  327. $logger->error(
  328. sprintf( 'Status transition of order #%d errored!', $this->get_id() ), array(
  329. 'order' => $this,
  330. 'error' => $e,
  331. )
  332. );
  333. $this->add_order_note( __( 'Error during status transition.', 'woocommerce' ) . ' ' . $e->getMessage() );
  334. }
  335. }
  336. }
  337. /*
  338. |--------------------------------------------------------------------------
  339. | Getters
  340. |--------------------------------------------------------------------------
  341. |
  342. | Methods for getting data from the order object.
  343. |
  344. */
  345. /**
  346. * Get all class data in array format.
  347. *
  348. * @since 3.0.0
  349. * @return array
  350. */
  351. public function get_data() {
  352. return array_merge(
  353. array(
  354. 'id' => $this->get_id(),
  355. ),
  356. $this->data,
  357. array(
  358. 'number' => $this->get_order_number(),
  359. 'meta_data' => $this->get_meta_data(),
  360. 'line_items' => $this->get_items( 'line_item' ),
  361. 'tax_lines' => $this->get_items( 'tax' ),
  362. 'shipping_lines' => $this->get_items( 'shipping' ),
  363. 'fee_lines' => $this->get_items( 'fee' ),
  364. 'coupon_lines' => $this->get_items( 'coupon' ),
  365. )
  366. );
  367. }
  368. /**
  369. * Expands the shipping and billing information in the changes array.
  370. */
  371. public function get_changes() {
  372. $changed_props = parent::get_changes();
  373. $subs = array( 'shipping', 'billing' );
  374. foreach ( $subs as $sub ) {
  375. if ( ! empty( $changed_props[ $sub ] ) ) {
  376. foreach ( $changed_props[ $sub ] as $sub_prop => $value ) {
  377. $changed_props[ $sub . '_' . $sub_prop ] = $value;
  378. }
  379. }
  380. }
  381. if ( isset( $changed_props['customer_note'] ) ) {
  382. $changed_props['post_excerpt'] = $changed_props['customer_note'];
  383. }
  384. return $changed_props;
  385. }
  386. /**
  387. * Gets the order number for display (by default, order ID).
  388. *
  389. * @return string
  390. */
  391. public function get_order_number() {
  392. return (string) apply_filters( 'woocommerce_order_number', $this->get_id(), $this );
  393. }
  394. /**
  395. * Get order key.
  396. *
  397. * @since 3.0.0
  398. * @param string $context What the value is for. Valid values are view and edit.
  399. * @return string
  400. */
  401. public function get_order_key( $context = 'view' ) {
  402. return $this->get_prop( 'order_key', $context );
  403. }
  404. /**
  405. * Get customer_id.
  406. *
  407. * @param string $context What the value is for. Valid values are view and edit.
  408. * @return int
  409. */
  410. public function get_customer_id( $context = 'view' ) {
  411. return $this->get_prop( 'customer_id', $context );
  412. }
  413. /**
  414. * Alias for get_customer_id().
  415. *
  416. * @param string $context What the value is for. Valid values are view and edit.
  417. * @return int
  418. */
  419. public function get_user_id( $context = 'view' ) {
  420. return $this->get_customer_id( $context );
  421. }
  422. /**
  423. * Get the user associated with the order. False for guests.
  424. *
  425. * @return WP_User|false
  426. */
  427. public function get_user() {
  428. return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
  429. }
  430. /**
  431. * Gets a prop for a getter method.
  432. *
  433. * @since 3.0.0
  434. * @param string $prop Name of prop to get.
  435. * @param string $address billing or shipping.
  436. * @param string $context What the value is for. Valid values are view and edit.
  437. * @return mixed
  438. */
  439. protected function get_address_prop( $prop, $address = 'billing', $context = 'view' ) {
  440. $value = null;
  441. if ( array_key_exists( $prop, $this->data[ $address ] ) ) {
  442. $value = isset( $this->changes[ $address ][ $prop ] ) ? $this->changes[ $address ][ $prop ] : $this->data[ $address ][ $prop ];
  443. if ( 'view' === $context ) {
  444. $value = apply_filters( $this->get_hook_prefix() . $address . '_' . $prop, $value, $this );
  445. }
  446. }
  447. return $value;
  448. }
  449. /**
  450. * Get billing first name.
  451. *
  452. * @param string $context What the value is for. Valid values are view and edit.
  453. * @return string
  454. */
  455. public function get_billing_first_name( $context = 'view' ) {
  456. return $this->get_address_prop( 'first_name', 'billing', $context );
  457. }
  458. /**
  459. * Get billing last name.
  460. *
  461. * @param string $context What the value is for. Valid values are view and edit.
  462. * @return string
  463. */
  464. public function get_billing_last_name( $context = 'view' ) {
  465. return $this->get_address_prop( 'last_name', 'billing', $context );
  466. }
  467. /**
  468. * Get billing company.
  469. *
  470. * @param string $context What the value is for. Valid values are view and edit.
  471. * @return string
  472. */
  473. public function get_billing_company( $context = 'view' ) {
  474. return $this->get_address_prop( 'company', 'billing', $context );
  475. }
  476. /**
  477. * Get billing address line 1.
  478. *
  479. * @param string $context What the value is for. Valid values are view and edit.
  480. * @return string
  481. */
  482. public function get_billing_address_1( $context = 'view' ) {
  483. return $this->get_address_prop( 'address_1', 'billing', $context );
  484. }
  485. /**
  486. * Get billing address line 2.
  487. *
  488. * @param string $context What the value is for. Valid values are view and edit.
  489. * @return string
  490. */
  491. public function get_billing_address_2( $context = 'view' ) {
  492. return $this->get_address_prop( 'address_2', 'billing', $context );
  493. }
  494. /**
  495. * Get billing city.
  496. *
  497. * @param string $context What the value is for. Valid values are view and edit.
  498. * @return string
  499. */
  500. public function get_billing_city( $context = 'view' ) {
  501. return $this->get_address_prop( 'city', 'billing', $context );
  502. }
  503. /**
  504. * Get billing state.
  505. *
  506. * @param string $context What the value is for. Valid values are view and edit.
  507. * @return string
  508. */
  509. public function get_billing_state( $context = 'view' ) {
  510. return $this->get_address_prop( 'state', 'billing', $context );
  511. }
  512. /**
  513. * Get billing postcode.
  514. *
  515. * @param string $context What the value is for. Valid values are view and edit.
  516. * @return string
  517. */
  518. public function get_billing_postcode( $context = 'view' ) {
  519. return $this->get_address_prop( 'postcode', 'billing', $context );
  520. }
  521. /**
  522. * Get billing country.
  523. *
  524. * @param string $context What the value is for. Valid values are view and edit.
  525. * @return string
  526. */
  527. public function get_billing_country( $context = 'view' ) {
  528. return $this->get_address_prop( 'country', 'billing', $context );
  529. }
  530. /**
  531. * Get billing email.
  532. *
  533. * @param string $context What the value is for. Valid values are view and edit.
  534. * @return string
  535. */
  536. public function get_billing_email( $context = 'view' ) {
  537. return $this->get_address_prop( 'email', 'billing', $context );
  538. }
  539. /**
  540. * Get billing phone.
  541. *
  542. * @param string $context What the value is for. Valid values are view and edit.
  543. * @return string
  544. */
  545. public function get_billing_phone( $context = 'view' ) {
  546. return $this->get_address_prop( 'phone', 'billing', $context );
  547. }
  548. /**
  549. * Get shipping first name.
  550. *
  551. * @param string $context What the value is for. Valid values are view and edit.
  552. * @return string
  553. */
  554. public function get_shipping_first_name( $context = 'view' ) {
  555. return $this->get_address_prop( 'first_name', 'shipping', $context );
  556. }
  557. /**
  558. * Get shipping_last_name.
  559. *
  560. * @param string $context What the value is for. Valid values are view and edit.
  561. * @return string
  562. */
  563. public function get_shipping_last_name( $context = 'view' ) {
  564. return $this->get_address_prop( 'last_name', 'shipping', $context );
  565. }
  566. /**
  567. * Get shipping company.
  568. *
  569. * @param string $context What the value is for. Valid values are view and edit.
  570. * @return string
  571. */
  572. public function get_shipping_company( $context = 'view' ) {
  573. return $this->get_address_prop( 'company', 'shipping', $context );
  574. }
  575. /**
  576. * Get shipping address line 1.
  577. *
  578. * @param string $context What the value is for. Valid values are view and edit.
  579. * @return string
  580. */
  581. public function get_shipping_address_1( $context = 'view' ) {
  582. return $this->get_address_prop( 'address_1', 'shipping', $context );
  583. }
  584. /**
  585. * Get shipping address line 2.
  586. *
  587. * @param string $context What the value is for. Valid values are view and edit.
  588. * @return string
  589. */
  590. public function get_shipping_address_2( $context = 'view' ) {
  591. return $this->get_address_prop( 'address_2', 'shipping', $context );
  592. }
  593. /**
  594. * Get shipping city.
  595. *
  596. * @param string $context What the value is for. Valid values are view and edit.
  597. * @return string
  598. */
  599. public function get_shipping_city( $context = 'view' ) {
  600. return $this->get_address_prop( 'city', 'shipping', $context );
  601. }
  602. /**
  603. * Get shipping state.
  604. *
  605. * @param string $context What the value is for. Valid values are view and edit.
  606. * @return string
  607. */
  608. public function get_shipping_state( $context = 'view' ) {
  609. return $this->get_address_prop( 'state', 'shipping', $context );
  610. }
  611. /**
  612. * Get shipping postcode.
  613. *
  614. * @param string $context What the value is for. Valid values are view and edit.
  615. * @return string
  616. */
  617. public function get_shipping_postcode( $context = 'view' ) {
  618. return $this->get_address_prop( 'postcode', 'shipping', $context );
  619. }
  620. /**
  621. * Get shipping country.
  622. *
  623. * @param string $context What the value is for. Valid values are view and edit.
  624. * @return string
  625. */
  626. public function get_shipping_country( $context = 'view' ) {
  627. return $this->get_address_prop( 'country', 'shipping', $context );
  628. }
  629. /**
  630. * Get the payment method.
  631. *
  632. * @param string $context What the value is for. Valid values are view and edit.
  633. * @return string
  634. */
  635. public function get_payment_method( $context = 'view' ) {
  636. return $this->get_prop( 'payment_method', $context );
  637. }
  638. /**
  639. * Get payment method title.
  640. *
  641. * @param string $context What the value is for. Valid values are view and edit.
  642. * @return string
  643. */
  644. public function get_payment_method_title( $context = 'view' ) {
  645. return $this->get_prop( 'payment_method_title', $context );
  646. }
  647. /**
  648. * Get transaction d.
  649. *
  650. * @param string $context What the value is for. Valid values are view and edit.
  651. * @return string
  652. */
  653. public function get_transaction_id( $context = 'view' ) {
  654. return $this->get_prop( 'transaction_id', $context );
  655. }
  656. /**
  657. * Get customer ip address.
  658. *
  659. * @param string $context What the value is for. Valid values are view and edit.
  660. * @return string
  661. */
  662. public function get_customer_ip_address( $context = 'view' ) {
  663. return $this->get_prop( 'customer_ip_address', $context );
  664. }
  665. /**
  666. * Get customer user agent.
  667. *
  668. * @param string $context What the value is for. Valid values are view and edit.
  669. * @return string
  670. */
  671. public function get_customer_user_agent( $context = 'view' ) {
  672. return $this->get_prop( 'customer_user_agent', $context );
  673. }
  674. /**
  675. * Get created via.
  676. *
  677. * @param string $context What the value is for. Valid values are view and edit.
  678. * @return string
  679. */
  680. public function get_created_via( $context = 'view' ) {
  681. return $this->get_prop( 'created_via', $context );
  682. }
  683. /**
  684. * Get customer note.
  685. *
  686. * @param string $context What the value is for. Valid values are view and edit.
  687. * @return string
  688. */
  689. public function get_customer_note( $context = 'view' ) {
  690. return $this->get_prop( 'customer_note', $context );
  691. }
  692. /**
  693. * Get date completed.
  694. *
  695. * @param string $context What the value is for. Valid values are view and edit.
  696. * @return WC_DateTime|NULL object if the date is set or null if there is no date.
  697. */
  698. public function get_date_completed( $context = 'view' ) {
  699. return $this->get_prop( 'date_completed', $context );
  700. }
  701. /**
  702. * Get date paid.
  703. *
  704. * @param string $context What the value is for. Valid values are view and edit.
  705. * @return WC_DateTime|NULL object if the date is set or null if there is no date.
  706. */
  707. public function get_date_paid( $context = 'view' ) {
  708. $date_paid = $this->get_prop( 'date_paid', $context );
  709. if ( 'view' === $context && ! $date_paid && version_compare( $this->get_version( 'edit' ), '3.0', '<' ) && $this->has_status( apply_filters( 'woocommerce_payment_complete_order_status', $this->needs_processing() ? 'processing' : 'completed', $this->get_id(), $this ) ) ) {
  710. // In view context, return a date if missing.
  711. $date_paid = $this->get_date_created( 'edit' );
  712. }
  713. return $date_paid;
  714. }
  715. /**
  716. * Get cart hash.
  717. *
  718. * @param string $context What the value is for. Valid values are view and edit.
  719. * @return string
  720. */
  721. public function get_cart_hash( $context = 'view' ) {
  722. return $this->get_prop( 'cart_hash', $context );
  723. }
  724. /**
  725. * Returns the requested address in raw, non-formatted way.
  726. * Note: Merges raw data with get_prop data so changes are returned too.
  727. *
  728. * @since 2.4.0
  729. * @param string $type Billing or shipping. Anything else besides 'billing' will return shipping address.
  730. * @return array The stored address after filter.
  731. */
  732. public function get_address( $type = 'billing' ) {
  733. return apply_filters( 'woocommerce_get_order_address', array_merge( $this->data[ $type ], $this->get_prop( $type, 'view' ) ), $type, $this );
  734. }
  735. /**
  736. * Get a formatted shipping address for the order.
  737. *
  738. * @return string
  739. */
  740. public function get_shipping_address_map_url() {
  741. $address = $this->get_address( 'shipping' );
  742. // Remove name and company before generate the Google Maps URL.
  743. unset( $address['first_name'], $address['last_name'], $address['company'] );
  744. $address = apply_filters( 'woocommerce_shipping_address_map_url_parts', $address, $this );
  745. return apply_filters( 'woocommerce_shipping_address_map_url', 'https://maps.google.com/maps?&q=' . rawurlencode( implode( ', ', $address ) ) . '&z=16', $this );
  746. }
  747. /**
  748. * Get a formatted billing full name.
  749. *
  750. * @return string
  751. */
  752. public function get_formatted_billing_full_name() {
  753. /* translators: 1: first name 2: last name */
  754. return sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $this->get_billing_first_name(), $this->get_billing_last_name() );
  755. }
  756. /**
  757. * Get a formatted shipping full name.
  758. *
  759. * @return string
  760. */
  761. public function get_formatted_shipping_full_name() {
  762. /* translators: 1: first name 2: last name */
  763. return sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $this->get_shipping_first_name(), $this->get_shipping_last_name() );
  764. }
  765. /**
  766. * Get a formatted billing address for the order.
  767. *
  768. * @param string $empty_content Content to show if no address is present. @since 3.3.0.
  769. * @return string
  770. */
  771. public function get_formatted_billing_address( $empty_content = '' ) {
  772. $address = apply_filters( 'woocommerce_order_formatted_billing_address', $this->get_address( 'billing' ), $this );
  773. $address = WC()->countries->get_formatted_address( $address );
  774. return $address ? $address : $empty_content;
  775. }
  776. /**
  777. * Get a formatted shipping address for the order.
  778. *
  779. * @param string $empty_content Content to show if no address is present. @since 3.3.0.
  780. * @return string
  781. */
  782. public function get_formatted_shipping_address( $empty_content = '' ) {
  783. $address = '';
  784. if ( $this->has_shipping_address() ) {
  785. $address = apply_filters( 'woocommerce_order_formatted_shipping_address', $this->get_address( 'shipping' ), $this );
  786. $address = WC()->countries->get_formatted_address( $address );
  787. }
  788. return $address ? $address : $empty_content;
  789. }
  790. /**
  791. * Returns true if the order has a billing address.
  792. *
  793. * @since 3.0.4
  794. * @return boolean
  795. */
  796. public function has_billing_address() {
  797. return $this->get_billing_address_1() || $this->get_billing_address_2();
  798. }
  799. /**
  800. * Returns true if the order has a shipping address.
  801. *
  802. * @since 3.0.4
  803. * @return boolean
  804. */
  805. public function has_shipping_address() {
  806. return $this->get_shipping_address_1() || $this->get_shipping_address_2();
  807. }
  808. /*
  809. |--------------------------------------------------------------------------
  810. | Setters
  811. |--------------------------------------------------------------------------
  812. |
  813. | Functions for setting order data. These should not update anything in the
  814. | database itself and should only change what is stored in the class
  815. | object. However, for backwards compatibility pre 3.0.0 some of these
  816. | setters may handle both.
  817. |
  818. */
  819. /**
  820. * Sets a prop for a setter method.
  821. *
  822. * @since 3.0.0
  823. * @param string $prop Name of prop to set.
  824. * @param string $address Name of address to set. billing or shipping.
  825. * @param mixed $value Value of the prop.
  826. */
  827. protected function set_address_prop( $prop, $address = 'billing', $value ) {
  828. if ( array_key_exists( $prop, $this->data[ $address ] ) ) {
  829. if ( true === $this->object_read ) {
  830. if ( $value !== $this->data[ $address ][ $prop ] || ( isset( $this->changes[ $address ] ) && array_key_exists( $prop, $this->changes[ $address ] ) ) ) {
  831. $this->changes[ $address ][ $prop ] = $value;
  832. }
  833. } else {
  834. $this->data[ $address ][ $prop ] = $value;
  835. }
  836. }
  837. }
  838. /**
  839. * Set order key.
  840. *
  841. * @param string $value Max length 22 chars.
  842. * @throws WC_Data_Exception Throws exception when invalid data is found.
  843. */
  844. public function set_order_key( $value ) {
  845. $this->set_prop( 'order_key', substr( $value, 0, 22 ) );
  846. }
  847. /**
  848. * Set customer id.
  849. *
  850. * @param int $value Customer ID.
  851. * @throws WC_Data_Exception Throws exception when invalid data is found.
  852. */
  853. public function set_customer_id( $value ) {
  854. $this->set_prop( 'customer_id', absint( $value ) );
  855. }
  856. /**
  857. * Set billing first name.
  858. *
  859. * @param string $value Billing first name.
  860. * @throws WC_Data_Exception Throws exception when invalid data is found.
  861. */
  862. public function set_billing_first_name( $value ) {
  863. $this->set_address_prop( 'first_name', 'billing', $value );
  864. }
  865. /**
  866. * Set billing last name.
  867. *
  868. * @param string $value Billing last name.
  869. * @throws WC_Data_Exception Throws exception when invalid data is found.
  870. */
  871. public function set_billing_last_name( $value ) {
  872. $this->set_address_prop( 'last_name', 'billing', $value );
  873. }
  874. /**
  875. * Set billing company.
  876. *
  877. * @param string $value Billing company.
  878. * @throws WC_Data_Exception Throws exception when invalid data is found.
  879. */
  880. public function set_billing_company( $value ) {
  881. $this->set_address_prop( 'company', 'billing', $value );
  882. }
  883. /**
  884. * Set billing address line 1.
  885. *
  886. * @param string $value Billing address line 1.
  887. * @throws WC_Data_Exception Throws exception when invalid data is found.
  888. */
  889. public function set_billing_address_1( $value ) {
  890. $this->set_address_prop( 'address_1', 'billing', $value );
  891. }
  892. /**
  893. * Set billing address line 2.
  894. *
  895. * @param string $value Billing address line 2.
  896. * @throws WC_Data_Exception Throws exception when invalid data is found.
  897. */
  898. public function set_billing_address_2( $value ) {
  899. $this->set_address_prop( 'address_2', 'billing', $value );
  900. }
  901. /**
  902. * Set billing city.
  903. *
  904. * @param string $value Billing city.
  905. * @throws WC_Data_Exception Throws exception when invalid data is found.
  906. */
  907. public function set_billing_city( $value ) {
  908. $this->set_address_prop( 'city', 'billing', $value );
  909. }
  910. /**
  911. * Set billing state.
  912. *
  913. * @param string $value Billing state.
  914. * @throws WC_Data_Exception Throws exception when invalid data is found.
  915. */
  916. public function set_billing_state( $value ) {
  917. $this->set_address_prop( 'state', 'billing', $value );
  918. }
  919. /**
  920. * Set billing postcode.
  921. *
  922. * @param string $value Billing postcode.
  923. * @throws WC_Data_Exception Throws exception when invalid data is found.
  924. */
  925. public function set_billing_postcode( $value ) {
  926. $this->set_address_prop( 'postcode', 'billing', $value );
  927. }
  928. /**
  929. * Set billing country.
  930. *
  931. * @param string $value Billing country.
  932. * @throws WC_Data_Exception Throws exception when invalid data is found.
  933. */
  934. public function set_billing_country( $value ) {
  935. $this->set_address_prop( 'country', 'billing', $value );
  936. }
  937. /**
  938. * Maybe set empty billing email to that of the user who owns the order.
  939. */
  940. protected function maybe_set_user_billing_email() {
  941. $user = $this->get_user();
  942. if ( ! $this->get_billing_email() && $user ) {
  943. try {
  944. $this->set_billing_email( $user->user_email );
  945. } catch ( WC_Data_Exception $e ) {
  946. unset( $e );
  947. }
  948. }
  949. }
  950. /**
  951. * Set billing email.
  952. *
  953. * @param string $value Billing email.
  954. * @throws WC_Data_Exception Throws exception when invalid data is found.
  955. */
  956. public function set_billing_email( $value ) {
  957. if ( $value && ! is_email( $value ) ) {
  958. $this->error( 'order_invalid_billing_email', __( 'Invalid billing email address', 'woocommerce' ) );
  959. }
  960. $this->set_address_prop( 'email', 'billing', sanitize_email( $value ) );
  961. }
  962. /**
  963. * Set billing phone.
  964. *
  965. * @param string $value Billing phone.
  966. * @throws WC_Data_Exception Throws exception when invalid data is found.
  967. */
  968. public function set_billing_phone( $value ) {
  969. $this->set_address_prop( 'phone', 'billing', $value );
  970. }
  971. /**
  972. * Set shipping first name.
  973. *
  974. * @param string $value Shipping first name.
  975. * @throws WC_Data_Exception Throws exception when invalid data is found.
  976. */
  977. public function set_shipping_first_name( $value ) {
  978. $this->set_address_prop( 'first_name', 'shipping', $value );
  979. }
  980. /**
  981. * Set shipping last name.
  982. *
  983. * @param string $value Shipping last name.
  984. * @throws WC_Data_Exception Throws exception when invalid data is found.
  985. */
  986. public function set_shipping_last_name( $value ) {
  987. $this->set_address_prop( 'last_name', 'shipping', $value );
  988. }
  989. /**
  990. * Set shipping company.
  991. *
  992. * @param string $value Shipping company.
  993. * @throws WC_Data_Exception Throws exception when invalid data is found.
  994. */
  995. public function set_shipping_company( $value ) {
  996. $this->set_address_prop( 'company', 'shipping', $value );
  997. }
  998. /**
  999. * Set shipping address line 1.
  1000. *
  1001. * @param string $value Shipping address line 1.
  1002. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1003. */
  1004. public function set_shipping_address_1( $value ) {
  1005. $this->set_address_prop( 'address_1', 'shipping', $value );
  1006. }
  1007. /**
  1008. * Set shipping address line 2.
  1009. *
  1010. * @param string $value Shipping address line 2.
  1011. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1012. */
  1013. public function set_shipping_address_2( $value ) {
  1014. $this->set_address_prop( 'address_2', 'shipping', $value );
  1015. }
  1016. /**
  1017. * Set shipping city.
  1018. *
  1019. * @param string $value Shipping city.
  1020. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1021. */
  1022. public function set_shipping_city( $value ) {
  1023. $this->set_address_prop( 'city', 'shipping', $value );
  1024. }
  1025. /**
  1026. * Set shipping state.
  1027. *
  1028. * @param string $value Shipping state.
  1029. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1030. */
  1031. public function set_shipping_state( $value ) {
  1032. $this->set_address_prop( 'state', 'shipping', $value );
  1033. }
  1034. /**
  1035. * Set shipping postcode.
  1036. *
  1037. * @param string $value Shipping postcode.
  1038. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1039. */
  1040. public function set_shipping_postcode( $value ) {
  1041. $this->set_address_prop( 'postcode', 'shipping', $value );
  1042. }
  1043. /**
  1044. * Set shipping country.
  1045. *
  1046. * @param string $value Shipping country.
  1047. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1048. */
  1049. public function set_shipping_country( $value ) {
  1050. $this->set_address_prop( 'country', 'shipping', $value );
  1051. }
  1052. /**
  1053. * Set the payment method.
  1054. *
  1055. * @param string $payment_method Supports WC_Payment_Gateway for bw compatibility with < 3.0.
  1056. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1057. */
  1058. public function set_payment_method( $payment_method = '' ) {
  1059. if ( is_object( $payment_method ) ) {
  1060. $this->set_payment_method( $payment_method->id );
  1061. $this->set_payment_method_title( $payment_method->get_title() );
  1062. } elseif ( '' === $payment_method ) {
  1063. $this->set_prop( 'payment_method', '' );
  1064. $this->set_prop( 'payment_method_title', '' );
  1065. } else {
  1066. $this->set_prop( 'payment_method', $payment_method );
  1067. }
  1068. }
  1069. /**
  1070. * Set payment method title.
  1071. *
  1072. * @param string $value Payment method title.
  1073. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1074. */
  1075. public function set_payment_method_title( $value ) {
  1076. $this->set_prop( 'payment_method_title', $value );
  1077. }
  1078. /**
  1079. * Set transaction id.
  1080. *
  1081. * @param string $value Transaction id.
  1082. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1083. */
  1084. public function set_transaction_id( $value ) {
  1085. $this->set_prop( 'transaction_id', $value );
  1086. }
  1087. /**
  1088. * Set customer ip address.
  1089. *
  1090. * @param string $value Customer ip address.
  1091. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1092. */
  1093. public function set_customer_ip_address( $value ) {
  1094. $this->set_prop( 'customer_ip_address', $value );
  1095. }
  1096. /**
  1097. * Set customer user agent.
  1098. *
  1099. * @param string $value Customer user agent.
  1100. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1101. */
  1102. public function set_customer_user_agent( $value ) {
  1103. $this->set_prop( 'customer_user_agent', $value );
  1104. }
  1105. /**
  1106. * Set created via.
  1107. *
  1108. * @param string $value Created via.
  1109. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1110. */
  1111. public function set_created_via( $value ) {
  1112. $this->set_prop( 'created_via', $value );
  1113. }
  1114. /**
  1115. * Set customer note.
  1116. *
  1117. * @param string $value Customer note.
  1118. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1119. */
  1120. public function set_customer_note( $value ) {
  1121. $this->set_prop( 'customer_note', $value );
  1122. }
  1123. /**
  1124. * Set date completed.
  1125. *
  1126. * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  1127. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1128. */
  1129. public function set_date_completed( $date = null ) {
  1130. $this->set_date_prop( 'date_completed', $date );
  1131. }
  1132. /**
  1133. * Set date paid.
  1134. *
  1135. * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  1136. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1137. */
  1138. public function set_date_paid( $date = null ) {
  1139. $this->set_date_prop( 'date_paid', $date );
  1140. }
  1141. /**
  1142. * Set cart hash.
  1143. *
  1144. * @param string $value Cart hash.
  1145. * @throws WC_Data_Exception Throws exception when invalid data is found.
  1146. */
  1147. public function set_cart_hash( $value ) {
  1148. $this->set_prop( 'cart_hash', $value );
  1149. }
  1150. /*
  1151. |--------------------------------------------------------------------------
  1152. | Conditionals
  1153. |--------------------------------------------------------------------------
  1154. |
  1155. | Checks if a condition is true or false.
  1156. |
  1157. */
  1158. /**
  1159. * Check if an order key is valid.
  1160. *
  1161. * @param string $key Order key.
  1162. * @return bool
  1163. */
  1164. public function key_is_valid( $key ) {
  1165. return $key === $this->get_order_key();
  1166. }
  1167. /**
  1168. * See if order matches cart_hash.
  1169. *
  1170. * @param string $cart_hash Cart hash.
  1171. * @return bool
  1172. */
  1173. public function has_cart_hash( $cart_hash = '' ) {
  1174. return hash_equals( $this->get_cart_hash(), $cart_hash ); // @codingStandardsIgnoreLine
  1175. }
  1176. /**
  1177. * Checks if an order can be edited, specifically for use on the Edit Order screen.
  1178. *
  1179. * @return bool
  1180. */
  1181. public function is_editable() {
  1182. return apply_filters( 'wc_order_is_editable', in_array( $this->get_status(), array( 'pending', 'on-hold', 'auto-draft' ), true ), $this );
  1183. }
  1184. /**
  1185. * Returns if an order has been paid for based on the order status.
  1186. *
  1187. * @since 2.5.0
  1188. * @return bool
  1189. */
  1190. public function is_paid() {
  1191. return apply_filters( 'woocommerce_order_is_paid', $this->has_status( wc_get_is_paid_statuses() ), $this );
  1192. }
  1193. /**
  1194. * Checks if product download is permitted.
  1195. *
  1196. * @return bool
  1197. */
  1198. public function is_download_permitted() {
  1199. return apply_filters( 'woocommerce_order_is_download_permitted', $this->has_status( 'completed' ) || ( 'yes' === get_option( 'woocommerce_downloads_grant_access_after_payment' ) && $this->has_status( 'processing' ) ), $this );
  1200. }
  1201. /**
  1202. * Checks if an order needs display the shipping address, based on shipping method.
  1203. *
  1204. * @return bool
  1205. */
  1206. public function needs_shipping_address() {
  1207. if ( 'no' === get_option( 'woocommerce_calc_shipping' ) ) {
  1208. return false;
  1209. }
  1210. $hide = apply_filters( 'woocommerce_order_hide_shipping_address', array( 'local_pickup' ), $this );
  1211. $needs_address = false;
  1212. foreach ( $this->get_shipping_methods() as $shipping_method ) {
  1213. // Remove any instance IDs after ":".
  1214. $shipping_method_id = current( explode( ':', $shipping_method['method_id'] ) );
  1215. if ( ! in_array( $shipping_method_id, $hide, true ) ) {
  1216. $needs_address = true;
  1217. break;
  1218. }
  1219. }
  1220. return apply_filters( 'woocommerce_order_needs_shipping_address', $needs_address, $hide, $this );
  1221. }
  1222. /**
  1223. * Returns true if the order contains a downloadable product.
  1224. *
  1225. * @return bool
  1226. */
  1227. public function has_downloadable_item() {
  1228. foreach ( $this->get_items() as $item ) {
  1229. if ( $item->is_type( 'line_item' ) ) {
  1230. $product = $item->get_product();
  1231. if ( $product && $product->has_file() ) {
  1232. return true;
  1233. }
  1234. }
  1235. }
  1236. return false;
  1237. }
  1238. /**
  1239. * Get downloads from all line items for this order.
  1240. *
  1241. * @since 3.2.0
  1242. * @return array
  1243. */
  1244. public function get_downloadable_items() {
  1245. $downloads = array();
  1246. foreach ( $this->get_items() as $item ) {
  1247. if ( ! is_object( $item ) ) {
  1248. continue;
  1249. }
  1250. if ( $item->is_type( 'line_item' ) ) {
  1251. $item_downloads = $item->get_item_downloads();
  1252. $product = $item->get_product();
  1253. if ( $product && $item_downloads ) {
  1254. foreach ( $item_downloads as $file ) {
  1255. $downloads[] = array(
  1256. 'download_url' => $file['download_url'],
  1257. 'download_id' => $file['id'],
  1258. 'product_id' => $product->get_id(),
  1259. 'product_name' => $product->get_name(),
  1260. 'product_url' => $product->is_visible() ? $product->get_permalink() : '', // Since 3.3.0.
  1261. 'download_name' => $file['name'],
  1262. 'order_id' => $this->get_id(),
  1263. 'order_key' => $this->get_order_key(),
  1264. 'downloads_remaining' => $file['downloads_remaining'],
  1265. 'access_expires' => $file['access_expires'],
  1266. 'file' => array(
  1267. 'name' => $file['name'],
  1268. 'file' => $file['file'],
  1269. ),
  1270. );
  1271. }
  1272. }
  1273. }
  1274. }
  1275. return apply_filters( 'woocommerce_order_get_downloadable_items', $downloads, $this );
  1276. }
  1277. /**
  1278. * Checks if an order needs payment, based on status and order total.
  1279. *
  1280. * @return bool
  1281. */
  1282. public function needs_payment() {
  1283. $valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this );
  1284. return apply_filters( 'woocommerce_order_needs_payment', ( $this->has_status( $valid_order_statuses ) && $this->get_total() > 0 ), $this, $valid_order_statuses );
  1285. }
  1286. /**
  1287. * See if the order needs processing before it can be completed.
  1288. *
  1289. * Orders which only contain virtual, downloadable items do not need admin
  1290. * intervention.
  1291. *
  1292. * Uses a transient so these calls are not repeated multiple times, and because
  1293. * once the order is processed this code/transient does not need to persist.
  1294. *
  1295. * @since 3.0.0
  1296. * @return bool
  1297. */
  1298. public function needs_processing() {
  1299. $transient_name = 'wc_order_' . $this->get_id() . '_needs_processing';
  1300. $needs_processing = get_transient( $transient_name );
  1301. if ( false === $needs_processing ) {
  1302. $needs_processing = 0;
  1303. if ( count( $this->get_items() ) > 0 ) {
  1304. foreach ( $this->get_items() as $item ) {
  1305. if ( $item->is_type( 'line_item' ) ) {
  1306. $product = $item->get_product();
  1307. if ( ! $product ) {
  1308. continue;
  1309. }
  1310. $virtual_downloadable_item = $product->is_downloadable() && $product->is_virtual();
  1311. if ( apply_filters( 'woocommerce_order_item_needs_processing', ! $virtual_downloadable_item, $product, $this->get_id() ) ) {
  1312. $needs_processing = 1;
  1313. break;
  1314. }
  1315. }
  1316. }
  1317. }
  1318. set_transient( $transient_name, $needs_processing, DAY_IN_SECONDS );
  1319. }
  1320. return 1 === absint( $needs_processing );
  1321. }
  1322. /*
  1323. |--------------------------------------------------------------------------
  1324. | URLs and Endpoints
  1325. |--------------------------------------------------------------------------
  1326. */
  1327. /**
  1328. * Generates a URL so that a customer can pay for their (unpaid - pending) order. Pass 'true' for the checkout version which doesn't offer gateway choices.
  1329. *
  1330. * @param bool $on_checkout If on checkout.
  1331. * @return string
  1332. */
  1333. public function get_checkout_payment_url( $on_checkout = false ) {
  1334. $pay_url = wc_get_endpoint_url( 'order-pay', $this->get_id(), wc_get_page_permalink( 'checkout' ) );
  1335. if ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || is_ssl() ) {
  1336. $pay_url = str_replace( 'http:', 'https:', $pay_url );
  1337. }
  1338. if ( $on_checkout ) {
  1339. $pay_url = add_query_arg( 'key', $this->get_order_key(), $pay_url );
  1340. } else {
  1341. $pay_url = add_query_arg(
  1342. array(
  1343. 'pay_for_order' => 'true',
  1344. 'key' => $this->get_order_key(),
  1345. ), $pay_url
  1346. );
  1347. }
  1348. return apply_filters( 'woocommerce_get_checkout_payment_url', $pay_url, $this );
  1349. }
  1350. /**
  1351. * Generates a URL for the thanks page (order received).
  1352. *
  1353. * @return string
  1354. */
  1355. public function get_checkout_order_received_url() {
  1356. $order_received_url = wc_get_endpoint_url( 'order-received', $this->get_id(), wc_get_page_permalink( 'checkout' ) );
  1357. if ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || is_ssl() ) {
  1358. $order_received_url = str_replace( 'http:', 'https:', $order_received_url );
  1359. }
  1360. $order_received_url = add_query_arg( 'key', $this->get_order_key(), $order_received_url );
  1361. return apply_filters( 'woocommerce_get_checkout_order_received_url', $order_received_url, $this );
  1362. }
  1363. /**
  1364. * Generates a URL so that a customer can cancel their (unpaid - pending) order.
  1365. *
  1366. * @param string $redirect Redirect URL.
  1367. * @return string
  1368. */
  1369. public function get_cancel_order_url( $redirect = '' ) {
  1370. return apply_filters(
  1371. 'woocommerce_get_cancel_order_url', wp_nonce_url(
  1372. add_query_arg(
  1373. array(
  1374. 'cancel_order' => 'true',
  1375. 'order' => $this->get_order_key(),
  1376. 'order_id' => $this->get_id(),
  1377. 'redirect' => $redirect,
  1378. ), $this->get_cancel_endpoint()
  1379. ), 'woocommerce-cancel_order'
  1380. )
  1381. );
  1382. }
  1383. /**
  1384. * Generates a raw (unescaped) cancel-order URL for use by payment gateways.
  1385. *
  1386. * @param string $redirect Redirect URL.
  1387. * @return string The unescaped cancel-order URL.
  1388. */
  1389. public function get_cancel_order_url_raw( $redirect = '' ) {
  1390. return apply_filters(
  1391. 'woocommerce_get_cancel_order_url_raw', add_query_arg(
  1392. array(
  1393. 'cancel_order' => 'true',
  1394. 'order' => $this->get_order_key(),
  1395. 'order_id' => $this->get_id(),
  1396. 'redirect' => $redirect,
  1397. '_wpnonce' => wp_create_nonce( 'woocommerce-cancel_order' ),
  1398. ), $this->get_cancel_endpoint()
  1399. )
  1400. );
  1401. }
  1402. /**
  1403. * Helper method to return the cancel endpoint.
  1404. *
  1405. * @return string the cancel endpoint; either the cart page or the home page.
  1406. */
  1407. public function get_cancel_endpoint() {
  1408. $cancel_endpoint = wc_get_page_permalink( 'cart' );
  1409. if ( ! $cancel_endpoint ) {
  1410. $cancel_endpoint = home_url();
  1411. }
  1412. if ( false === strpos( $cancel_endpoint, '?' ) ) {
  1413. $cancel_endpoint = trailingslashit( $cancel_endpoint );
  1414. }
  1415. return $cancel_endpoint;
  1416. }
  1417. /**
  1418. * Generates a URL to view an order from the my account page.
  1419. *
  1420. * @return string
  1421. */
  1422. public function get_view_order_url() {
  1423. return apply_filters( 'woocommerce_get_view_order_url', wc_get_endpoint_url( 'view-order', $this->get_id(), wc_get_page_permalink( 'myaccount' ) ), $this );
  1424. }
  1425. /**
  1426. * Get's the URL to edit the order in the backend.
  1427. *
  1428. * @since 3.3.0
  1429. * @return string
  1430. */
  1431. public function get_edit_order_url() {
  1432. return apply_filters( 'woocommerce_get_edit_order_url', get_admin_url( null, 'post.php?post=' . $this->get_id() . '&action=edit' ), $this );
  1433. }
  1434. /*
  1435. |--------------------------------------------------------------------------
  1436. | Order notes.
  1437. |--------------------------------------------------------------------------
  1438. */
  1439. /**
  1440. * Adds a note (comment) to the order. Order must exist.
  1441. *
  1442. * @param string $note Note to add.
  1443. * @param int $is_customer_note Is this a note for the customer?.
  1444. * @param bool $added_by_user Was the note added by a user?.
  1445. * @return int Comment ID.
  1446. */
  1447. public function add_order_note( $note, $is_customer_note = 0, $added_by_user = false ) {
  1448. if ( ! $this->get_id() ) {
  1449. return 0;
  1450. }
  1451. if ( is_user_logged_in() && current_user_can( 'edit_shop_order', $this->get_id() ) && $added_by_user ) {
  1452. $user = get_user_by( 'id', get_current_user_id() );
  1453. $comment_author = $user->display_name;
  1454. $comment_author_email = $user->user_email;
  1455. } else {
  1456. $comment_author = __( 'WooCommerce', 'woocommerce' );
  1457. $comment_author_email = strtolower( __( 'WooCommerce', 'woocommerce' ) ) . '@';
  1458. $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : 'noreply.com'; // WPCS: input var ok.
  1459. $comment_author_email = sanitize_email( $comment_author_email );
  1460. }
  1461. $commentdata = apply_filters(
  1462. 'woocommerce_new_order_note_data',
  1463. array(
  1464. 'comment_post_ID' => $this->get_id(),
  1465. 'comment_author' => $comment_author,
  1466. 'comment_author_email' => $comment_author_email,
  1467. 'comment_author_url' => '',
  1468. 'comment_content' => $note,
  1469. 'comment_agent' => 'WooCommerce',
  1470. 'comment_type' => 'order_note',
  1471. 'comment_parent' => 0,
  1472. 'comment_approved' => 1,
  1473. ),
  1474. array(
  1475. 'order_id' => $this->get_id(),
  1476. 'is_customer_note' => $is_customer_note,
  1477. )
  1478. );
  1479. $comment_id = wp_insert_comment( $commentdata );
  1480. if ( $is_customer_note ) {
  1481. add_comment_meta( $comment_id, 'is_customer_note', 1 );
  1482. do_action(
  1483. 'woocommerce_new_customer_note', array(
  1484. 'order_id' => $this->get_id(),
  1485. 'customer_note' => $commentdata['comment_content'],
  1486. )
  1487. );
  1488. }
  1489. return $comment_id;
  1490. }
  1491. /**
  1492. * List order notes (public) for the customer.
  1493. *
  1494. * @return array
  1495. */
  1496. public function get_customer_order_notes() {
  1497. $notes = array();
  1498. $args = array(
  1499. 'post_id' => $this->get_id(),
  1500. 'approve' => 'approve',
  1501. 'type' => '',
  1502. );
  1503. remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) );
  1504. $comments = get_comments( $args );
  1505. foreach ( $comments as $comment ) {
  1506. if ( ! get_comment_meta( $comment->comment_ID, 'is_customer_note', true ) ) {
  1507. continue;
  1508. }
  1509. $comment->comment_content = make_clickable( $comment->comment_content );
  1510. $notes[] = $comment;
  1511. }
  1512. add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) );
  1513. return $notes;
  1514. }
  1515. /*
  1516. |--------------------------------------------------------------------------
  1517. | Refunds
  1518. |--------------------------------------------------------------------------
  1519. */
  1520. /**
  1521. * Get order refunds.
  1522. *
  1523. * @since 2.2
  1524. * @return array of WC_Order_Refund objects
  1525. */
  1526. public function get_refunds() {
  1527. $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'refunds' . $this->get_id();
  1528. $cached_data = wp_cache_get( $cache_key, $this->cache_group );
  1529. if ( false !== $cached_data ) {
  1530. return $cached_data;
  1531. }
  1532. $this->refunds = wc_get_orders(
  1533. array(
  1534. 'type' => 'shop_order_refund',
  1535. 'parent' => $this->get_id(),
  1536. 'limit' => -1,
  1537. )
  1538. );
  1539. wp_cache_set( $cache_key, $this->refunds, $this->cache_group );
  1540. return $this->refunds;
  1541. }
  1542. /**
  1543. * Get amount already refunded.
  1544. *
  1545. * @since 2.2
  1546. * @return string
  1547. */
  1548. public function get_total_refunded() {
  1549. $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'total_refunded' . $this->get_id();
  1550. $cached_data = wp_cache_get( $cache_key, $this->cache_group );
  1551. if ( false !== $cached_data ) {
  1552. return $cached_data;
  1553. }
  1554. $total_refunded = $this->data_store->get_total_refunded( $this );
  1555. wp_cache_set( $cache_key, $total_refunded, $this->cache_group );
  1556. return $total_refunded;
  1557. }
  1558. /**
  1559. * Get the total tax refunded.
  1560. *
  1561. * @since 2.3
  1562. * @return float
  1563. */
  1564. public function get_total_tax_refunded() {
  1565. $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'total_tax_refunded' . $this->get_id();
  1566. $cached_data = wp_cache_get( $cache_key, $this->cache_group );
  1567. if ( false !== $cached_data ) {
  1568. return $cached_data;
  1569. }
  1570. $total_refunded = $this->data_store->get_total_tax_refunded( $this );
  1571. wp_cache_set( $cache_key, $total_refunded, $this->cache_group );
  1572. return $total_refunded;
  1573. }
  1574. /**
  1575. * Get the total shipping refunded.
  1576. *
  1577. * @since 2.4
  1578. * @return float
  1579. */
  1580. public function get_total_shipping_refunded() {
  1581. $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'total_shipping_refunded' . $this->get_id();
  1582. $cached_data = wp_cache_get( $cache_key, $this->cache_group );
  1583. if ( false !== $cached_data ) {
  1584. return $cached_data;
  1585. }
  1586. $total_refunded = $this->data_store->get_total_shipping_refunded( $this );
  1587. wp_cache_set( $cache_key, $total_refunded, $this->cache_group );
  1588. return $total_refunded;
  1589. }
  1590. /**
  1591. * Gets the count of order items of a certain type that have been refunded.
  1592. *
  1593. * @since 2.4.0
  1594. * @param string $item_type Item type.
  1595. * @return string
  1596. */
  1597. public function get_item_count_refunded( $item_type = '' ) {
  1598. if ( empty( $item_type ) ) {
  1599. $item_type = array( 'line_item' );
  1600. }
  1601. if ( ! is_array( $item_type ) ) {
  1602. $item_type = array( $item_type );
  1603. }
  1604. $count = 0;
  1605. foreach ( $this->get_refunds() as $refund ) {
  1606. foreach ( $refund->get_items( $item_type ) as $refunded_item ) {
  1607. $count += abs( $refunded_item->get_quantity() );
  1608. }
  1609. }
  1610. return apply_filters( 'woocommerce_get_item_count_refunded', $count, $item_type, $this );
  1611. }
  1612. /**
  1613. * Get the total number of items refunded.
  1614. *
  1615. * @since 2.4.0
  1616. *
  1617. * @param string $item_type Type of the item we're checking, if not a line_item.
  1618. * @return int
  1619. */
  1620. public function get_total_qty_refunded( $item_type = 'line_item' ) {
  1621. $qty = 0;
  1622. foreach ( $this->get_refunds() as $refund ) {
  1623. foreach ( $refund->get_items( $item_type ) as $refunded_item ) {
  1624. $qty += $refunded_item->get_quantity();
  1625. }
  1626. }
  1627. return $qty;
  1628. }
  1629. /**
  1630. * Get the refunded amount for a line item.
  1631. *
  1632. * @param int $item_id ID of the item we're checking.
  1633. * @param string $item_type Type of the item we're checking, if not a line_item.
  1634. * @return int
  1635. */
  1636. public function get_qty_refunded_for_item( $item_id, $item_type = 'line_item' ) {
  1637. $qty = 0;
  1638. foreach ( $this->get_refunds() as $refund ) {
  1639. foreach ( $refund->get_items( $item_type ) as $refunded_item ) {
  1640. if ( absint( $refunded_item->get_meta( '_refunded_item_id' ) ) === $item_id ) {
  1641. $qty += $refunded_item->get_quantity();
  1642. }
  1643. }
  1644. }
  1645. return $qty;
  1646. }
  1647. /**
  1648. * Get the refunded amount for a line item.
  1649. *
  1650. * @param int $item_id ID of the item we're checking.
  1651. * @param string $item_type Type of the item we're checking, if not a line_item.
  1652. * @return int
  1653. */
  1654. public function get_total_refunded_for_item( $item_id, $item_type = 'line_item' ) {
  1655. $total = 0;
  1656. foreach ( $this->get_refunds() as $refund ) {
  1657. foreach ( $refund->get_items( $item_type ) as $refunded_item ) {
  1658. if ( absint( $refunded_item->get_meta( '_refunded_item_id' ) ) === $item_id ) {
  1659. $total += $refunded_item->get_total();
  1660. }
  1661. }
  1662. }
  1663. return $total * -1;
  1664. }
  1665. /**
  1666. * Get the refunded tax amount for a line item.
  1667. *
  1668. * @param int $item_id ID of the item we're checking.
  1669. * @param int $tax_id ID of the tax we're checking.
  1670. * @param string $item_type Type of the item we're checking, if not a line_item.
  1671. * @return double
  1672. */
  1673. public function get_tax_refunded_for_item( $item_id, $tax_id, $item_type = 'line_item' ) {
  1674. $total = 0;
  1675. foreach ( $this->get_refunds() as $refund ) {
  1676. foreach ( $refund->get_items( $item_type ) as $refunded_item ) {
  1677. $refunded_item_id = (int) $refunded_item->get_meta( '_refunded_item_id' );
  1678. if ( $refunded_item_id === $item_id ) {
  1679. $taxes = $refunded_item->get_taxes();
  1680. $total += isset( $taxes['total'][ $tax_id ] ) ? (float) $taxes['total'][ $tax_id ] : 0;
  1681. break;
  1682. }
  1683. }
  1684. }
  1685. return wc_round_tax_total( $total ) * -1;
  1686. }
  1687. /**
  1688. * Get total tax refunded by rate ID.
  1689. *
  1690. * @param int $rate_id Rate ID.
  1691. * @return float
  1692. */
  1693. public function get_total_tax_refunded_by_rate_id( $rate_id ) {
  1694. $total = 0;
  1695. foreach ( $this->get_refunds() as $refund ) {
  1696. foreach ( $refund->get_items( 'tax' ) as $refunded_item ) {
  1697. if ( absint( $refunded_item->get_rate_id() ) === $rate_id ) {
  1698. $total += abs( $refunded_item->get_tax_total() ) + abs( $refunded_item->get_shipping_tax_total() );
  1699. }
  1700. }
  1701. }
  1702. return $total;
  1703. }
  1704. /**
  1705. * How much money is left to refund?
  1706. *
  1707. * @return string
  1708. */
  1709. public function get_remaining_refund_amount() {
  1710. return wc_format_decimal( $this->get_total() - $this->get_total_refunded(), wc_get_price_decimals() );
  1711. }
  1712. /**
  1713. * How many items are left to refund?
  1714. *
  1715. * @return int
  1716. */
  1717. public function get_remaining_refund_items() {
  1718. return absint( $this->get_item_count() - $this->get_item_count_refunded() );
  1719. }
  1720. /**
  1721. * Add total row for the payment method.
  1722. *
  1723. * @param array $total_rows Total rows.
  1724. * @param string $tax_display Tax to display.
  1725. */
  1726. protected function add_order_item_totals_payment_method_row( &$total_rows, $tax_display ) {
  1727. if ( $this->get_total() > 0 && $this->get_payment_method_title() ) {
  1728. $total_rows['payment_method'] = array(
  1729. 'label' => __( 'Payment method:', 'woocommerce' ),
  1730. 'value' => $this->get_payment_method_title(),
  1731. );
  1732. }
  1733. }
  1734. /**
  1735. * Add total row for refunds.
  1736. *
  1737. * @param array $total_rows Total rows.
  1738. * @param string $tax_display Tax to display.
  1739. */
  1740. protected function add_order_item_totals_refund_rows( &$total_rows, $tax_display ) {
  1741. $refunds = $this->get_refunds();
  1742. if ( $refunds ) {
  1743. foreach ( $refunds as $id => $refund ) {
  1744. $total_rows[ 'refund_' . $id ] = array(
  1745. 'label' => $refund->get_reason() ? $refund->get_reason() : __( 'Refund', 'woocommerce' ) . ':',
  1746. 'value' => wc_price( '-' . $refund->get_amount(), array( 'currency' => $this->get_currency() ) ),
  1747. );
  1748. }
  1749. }
  1750. }
  1751. /**
  1752. * Get totals for display on pages and in emails.
  1753. *
  1754. * @param string $tax_display Tax to display.
  1755. * @return array
  1756. */
  1757. public function get_order_item_totals( $tax_display = '' ) {
  1758. $tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
  1759. $total_rows = array();
  1760. $this->add_order_item_totals_subtotal_row( $total_rows, $tax_display );
  1761. $this->add_order_item_totals_discount_row( $total_rows, $tax_display );
  1762. $this->add_order_item_totals_shipping_row( $total_rows, $tax_display );
  1763. $this->add_order_item_totals_fee_rows( $total_rows, $tax_display );
  1764. $this->add_order_item_totals_tax_rows( $total_rows, $tax_display );
  1765. $this->add_order_item_totals_payment_method_row( $total_rows, $tax_display );
  1766. $this->add_order_item_totals_refund_rows( $total_rows, $tax_display );
  1767. $this->add_order_item_totals_total_row( $total_rows, $tax_display );
  1768. return apply_filters( 'woocommerce_get_order_item_totals', $total_rows, $this, $tax_display );
  1769. }
  1770. }