WC_Order_Data_Store_CPT

WC Order Data Store: Stored in CPT.

Defined (1)

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

/includes/data-stores/class-wc-order-data-store-cpt.php  
  1. class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implements WC_Object_Data_Store_Interface, WC_Order_Data_Store_Interface { 
  2.  
  3. /** 
  4. * Data stored in meta keys, but not considered "meta" for an order. 
  5. * @since 3.0.0 
  6. * @var array 
  7. */ 
  8. protected $internal_meta_keys = array( 
  9. '_customer_user',  
  10. '_order_key',  
  11. '_order_currency',  
  12. '_billing_first_name',  
  13. '_billing_last_name',  
  14. '_billing_company',  
  15. '_billing_address_1',  
  16. '_billing_address_2',  
  17. '_billing_city',  
  18. '_billing_state',  
  19. '_billing_postcode',  
  20. '_billing_country',  
  21. '_billing_email',  
  22. '_billing_phone',  
  23. '_shipping_first_name',  
  24. '_shipping_last_name',  
  25. '_shipping_company',  
  26. '_shipping_address_1',  
  27. '_shipping_address_2',  
  28. '_shipping_city',  
  29. '_shipping_state',  
  30. '_shipping_postcode',  
  31. '_shipping_country',  
  32. '_completed_date',  
  33. '_paid_date',  
  34. '_edit_lock',  
  35. '_edit_last',  
  36. '_cart_discount',  
  37. '_cart_discount_tax',  
  38. '_order_shipping',  
  39. '_order_shipping_tax',  
  40. '_order_tax',  
  41. '_order_total',  
  42. '_payment_method',  
  43. '_payment_method_title',  
  44. '_transaction_id',  
  45. '_customer_ip_address',  
  46. '_customer_user_agent',  
  47. '_created_via',  
  48. '_order_version',  
  49. '_prices_include_tax',  
  50. '_date_completed',  
  51. '_date_paid',  
  52. '_payment_tokens',  
  53. '_billing_address_index',  
  54. '_shipping_address_index',  
  55. '_recorded_sales',  
  56. '_recorded_coupon_usage_counts',  
  57. '_shipping_method',  
  58. ); 
  59.  
  60. /** 
  61. * Method to create a new order in the database. 
  62. * @param WC_Order $order 
  63. */ 
  64. public function create( &$order ) { 
  65. $order->set_order_key( 'wc_' . apply_filters( 'woocommerce_generate_order_key', uniqid( 'order_' ) ) ); 
  66. parent::create( $order ); 
  67. do_action( 'woocommerce_new_order', $order->get_id() ); 
  68.  
  69. /** 
  70. * Read order data. Can be overridden by child classes to load other props. 
  71. * @param WC_Order 
  72. * @param object $post_object 
  73. * @since 3.0.0 
  74. */ 
  75. protected function read_order_data( &$order, $post_object ) { 
  76. parent::read_order_data( $order, $post_object ); 
  77. $id = $order->get_id(); 
  78. $date_completed = get_post_meta( $id, '_date_completed', true ); 
  79. $date_paid = get_post_meta( $id, '_date_paid', true ); 
  80.  
  81. if ( ! $date_completed ) { 
  82. $date_completed = get_post_meta( $id, '_completed_date', true ); 
  83.  
  84. if ( ! $date_paid ) { 
  85. $date_paid = get_post_meta( $id, '_paid_date', true ); 
  86.  
  87. $order->set_props( array( 
  88. 'order_key' => get_post_meta( $id, '_order_key', true ),  
  89. 'customer_id' => get_post_meta( $id, '_customer_user', true ),  
  90. 'billing_first_name' => get_post_meta( $id, '_billing_first_name', true ),  
  91. 'billing_last_name' => get_post_meta( $id, '_billing_last_name', true ),  
  92. 'billing_company' => get_post_meta( $id, '_billing_company', true ),  
  93. 'billing_address_1' => get_post_meta( $id, '_billing_address_1', true ),  
  94. 'billing_address_2' => get_post_meta( $id, '_billing_address_2', true ),  
  95. 'billing_city' => get_post_meta( $id, '_billing_city', true ),  
  96. 'billing_state' => get_post_meta( $id, '_billing_state', true ),  
  97. 'billing_postcode' => get_post_meta( $id, '_billing_postcode', true ),  
  98. 'billing_country' => get_post_meta( $id, '_billing_country', true ),  
  99. 'billing_email' => get_post_meta( $id, '_billing_email', true ),  
  100. 'billing_phone' => get_post_meta( $id, '_billing_phone', true ),  
  101. 'shipping_first_name' => get_post_meta( $id, '_shipping_first_name', true ),  
  102. 'shipping_last_name' => get_post_meta( $id, '_shipping_last_name', true ),  
  103. 'shipping_company' => get_post_meta( $id, '_shipping_company', true ),  
  104. 'shipping_address_1' => get_post_meta( $id, '_shipping_address_1', true ),  
  105. 'shipping_address_2' => get_post_meta( $id, '_shipping_address_2', true ),  
  106. 'shipping_city' => get_post_meta( $id, '_shipping_city', true ),  
  107. 'shipping_state' => get_post_meta( $id, '_shipping_state', true ),  
  108. 'shipping_postcode' => get_post_meta( $id, '_shipping_postcode', true ),  
  109. 'shipping_country' => get_post_meta( $id, '_shipping_country', true ),  
  110. 'payment_method' => get_post_meta( $id, '_payment_method', true ),  
  111. 'payment_method_title' => get_post_meta( $id, '_payment_method_title', true ),  
  112. 'transaction_id' => get_post_meta( $id, '_transaction_id', true ),  
  113. 'customer_ip_address' => get_post_meta( $id, '_customer_ip_address', true ),  
  114. 'customer_user_agent' => get_post_meta( $id, '_customer_user_agent', true ),  
  115. 'created_via' => get_post_meta( $id, '_created_via', true ),  
  116. 'date_completed' => $date_completed,  
  117. 'date_paid' => $date_paid,  
  118. 'cart_hash' => get_post_meta( $id, '_cart_hash', true ),  
  119. 'customer_note' => $post_object->post_excerpt,  
  120. ) ); 
  121.  
  122. /** 
  123. * Method to update an order in the database. 
  124. * @param WC_Order $order 
  125. */ 
  126. public function update( &$order ) { 
  127. // Before updating, ensure date paid is set if missing. 
  128. if ( ! $order->get_date_paid( 'edit' ) && version_compare( $order->get_version( 'edit' ), '3.0', '<' ) && $order->has_status( apply_filters( 'woocommerce_payment_complete_order_status', $order->needs_processing() ? 'processing' : 'completed', $order->get_id(), $order ) ) ) { 
  129. $order->set_date_paid( $order->get_date_created( 'edit' ) ); 
  130.  
  131. // Update the order. 
  132. parent::update( $order ); 
  133.  
  134. do_action( 'woocommerce_update_order', $order->get_id() ); 
  135.  
  136. /** 
  137. * Helper method that updates all the post meta for an order based on it's settings in the WC_Order class. 
  138. * @param WC_Order 
  139. * @since 3.0.0 
  140. */ 
  141. protected function update_post_meta( &$order ) { 
  142. $updated_props = array(); 
  143. $id = $order->get_id(); 
  144. $meta_key_to_props = array( 
  145. '_order_key' => 'order_key',  
  146. '_customer_user' => 'customer_id',  
  147. '_payment_method' => 'payment_method',  
  148. '_payment_method_title' => 'payment_method_title',  
  149. '_transaction_id' => 'transaction_id',  
  150. '_customer_ip_address' => 'customer_ip_address',  
  151. '_customer_user_agent' => 'customer_user_agent',  
  152. '_created_via' => 'created_via',  
  153. '_date_completed' => 'date_completed',  
  154. '_date_paid' => 'date_paid',  
  155. '_cart_hash' => 'cart_hash',  
  156. ); 
  157.  
  158. $props_to_update = $this->get_props_to_update( $order, $meta_key_to_props ); 
  159.  
  160. foreach ( $props_to_update as $meta_key => $prop ) { 
  161. $value = $order->{"get_$prop"}( 'edit' ); 
  162.  
  163. if ( 'date_paid' === $prop ) { 
  164. // In 3.0.x we store this as a UTC timestamp. 
  165. update_post_meta( $id, $meta_key, ! is_null( $value ) ? $value->getTimestamp() : '' ); 
  166.  
  167. // In 2.6.x date_paid was stored as _paid_date in local mysql format. 
  168. update_post_meta( $id, '_paid_date', ! is_null( $value ) ? $value->date( 'Y-m-d H:i:s' ) : '' ); 
  169.  
  170. } elseif ( 'date_completed' === $prop ) { 
  171. // In 3.0.x we store this as a UTC timestamp. 
  172. update_post_meta( $id, $meta_key, ! is_null( $value ) ? $value->getTimestamp() : '' ); 
  173.  
  174. // In 2.6.x date_paid was stored as _paid_date in local mysql format. 
  175. update_post_meta( $id, '_completed_date', ! is_null( $value ) ? $value->date( 'Y-m-d H:i:s' ) : '' ); 
  176.  
  177. } else { 
  178. update_post_meta( $id, $meta_key, $value ); 
  179.  
  180. $updated_props[] = $prop; 
  181.  
  182. $address_props = array( 
  183. 'billing' => array( 
  184. '_billing_first_name' => 'billing_first_name',  
  185. '_billing_last_name' => 'billing_last_name',  
  186. '_billing_company' => 'billing_company',  
  187. '_billing_address_1' => 'billing_address_1',  
  188. '_billing_address_2' => 'billing_address_2',  
  189. '_billing_city' => 'billing_city',  
  190. '_billing_state' => 'billing_state',  
  191. '_billing_postcode' => 'billing_postcode',  
  192. '_billing_country' => 'billing_country',  
  193. '_billing_email' => 'billing_email',  
  194. '_billing_phone' => 'billing_phone',  
  195. ),  
  196. 'shipping' => array( 
  197. '_shipping_first_name' => 'shipping_first_name',  
  198. '_shipping_last_name' => 'shipping_last_name',  
  199. '_shipping_company' => 'shipping_company',  
  200. '_shipping_address_1' => 'shipping_address_1',  
  201. '_shipping_address_2' => 'shipping_address_2',  
  202. '_shipping_city' => 'shipping_city',  
  203. '_shipping_state' => 'shipping_state',  
  204. '_shipping_postcode' => 'shipping_postcode',  
  205. '_shipping_country' => 'shipping_country',  
  206. ),  
  207. ); 
  208.  
  209. foreach ( $address_props as $props_key => $props ) { 
  210. $props_to_update = $this->get_props_to_update( $order, $props ); 
  211. foreach ( $props_to_update as $meta_key => $prop ) { 
  212. $value = $order->{"get_$prop"}( 'edit' ); 
  213. update_post_meta( $id, $meta_key, $value ); 
  214. $updated_props[] = $prop; 
  215. $updated_props[] = $props_key; 
  216.  
  217. parent::update_post_meta( $order ); 
  218.  
  219. // If address changed, store concatenated version to make searches faster. 
  220. if ( in_array( 'billing', $updated_props ) || ! metadata_exists( 'post', $id, '_billing_address_index' ) ) { 
  221. update_post_meta( $id, '_billing_address_index', implode( ' ', $order->get_address( 'billing' ) ) ); 
  222. if ( in_array( 'shipping', $updated_props ) || ! metadata_exists( 'post', $id, '_shipping_address_index' ) ) { 
  223. update_post_meta( $id, '_shipping_address_index', implode( ' ', $order->get_address( 'shipping' ) ) ); 
  224.  
  225. // If customer changed, update any downloadable permissions. 
  226. if ( in_array( 'customer_user', $updated_props ) || in_array( 'billing_email', $updated_props ) ) { 
  227. $data_store = WC_Data_Store::load( 'customer-download' ); 
  228. $data_store->update_user_by_order_id( $id, $order->get_customer_id(), $order->get_billing_email() ); 
  229.  
  230. do_action( 'woocommerce_order_object_updated_props', $order, $updated_props ); 
  231.  
  232. /** 
  233. * Excerpt for post. 
  234. * @param WC_Order $order 
  235. * @return string 
  236. */ 
  237. protected function get_post_excerpt( $order ) { 
  238. return $order->get_customer_note(); 
  239.  
  240. /** 
  241. * Get amount already refunded. 
  242. * @param WC_Order 
  243. * @return string 
  244. */ 
  245. public function get_total_refunded( $order ) { 
  246. global $wpdb; 
  247.  
  248. $total = $wpdb->get_var( $wpdb->prepare( " 
  249. SELECT SUM( postmeta.meta_value ) 
  250. FROM $wpdb->postmeta AS postmeta 
  251. INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d ) 
  252. WHERE postmeta.meta_key = '_refund_amount' 
  253. AND postmeta.post_id = posts.ID 
  254. ", $order->get_id() ) ); 
  255.  
  256. return $total; 
  257.  
  258. /** 
  259. * Get the total tax refunded. 
  260. * @param WC_Order 
  261. * @return float 
  262. */ 
  263. public function get_total_tax_refunded( $order ) { 
  264. global $wpdb; 
  265.  
  266. $total = $wpdb->get_var( $wpdb->prepare( " 
  267. SELECT SUM( order_itemmeta.meta_value ) 
  268. FROM {$wpdb->prefix}woocommerce_order_itemmeta AS order_itemmeta 
  269. INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d ) 
  270. INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON ( order_items.order_id = posts.ID AND order_items.order_item_type = 'tax' ) 
  271. WHERE order_itemmeta.order_item_id = order_items.order_item_id 
  272. AND order_itemmeta.meta_key IN ('tax_amount', 'shipping_tax_amount') 
  273. ", $order->get_id() ) ); 
  274.  
  275. return abs( $total ); 
  276.  
  277. /** 
  278. * Get the total shipping refunded. 
  279. * @param WC_Order 
  280. * @return float 
  281. */ 
  282. public function get_total_shipping_refunded( $order ) { 
  283. global $wpdb; 
  284.  
  285. $total = $wpdb->get_var( $wpdb->prepare( " 
  286. SELECT SUM( order_itemmeta.meta_value ) 
  287. FROM {$wpdb->prefix}woocommerce_order_itemmeta AS order_itemmeta 
  288. INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d ) 
  289. INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON ( order_items.order_id = posts.ID AND order_items.order_item_type = 'shipping' ) 
  290. WHERE order_itemmeta.order_item_id = order_items.order_item_id 
  291. AND order_itemmeta.meta_key IN ('cost') 
  292. ", $order->get_id() ) ); 
  293.  
  294. return abs( $total ); 
  295.  
  296. /** 
  297. * Finds an Order ID based on an order key. 
  298. * @param string $order_key An order key has generated by 
  299. * @return int The ID of an order, or 0 if the order could not be found 
  300. */ 
  301. public function get_order_id_by_order_key( $order_key ) { 
  302. global $wpdb; 
  303. return $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '_order_key' AND meta_value = %s", $order_key ) ); 
  304.  
  305. /** 
  306. * Return count of orders with a specific status. 
  307. * @param string $status 
  308. * @return int 
  309. */ 
  310. public function get_order_count( $status ) { 
  311. global $wpdb; 
  312. return absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( * ) FROM {$wpdb->posts} WHERE post_type = 'shop_order' AND post_status = %s", $status ) ) ); 
  313.  
  314. /** 
  315. * Get all orders matching the passed in args. 
  316. * @see wc_get_orders() 
  317. * @param array $args 
  318. * @return array of orders 
  319. */ 
  320. public function get_orders( $args = array() ) { 
  321. /** 
  322. * Generate WP_Query args. This logic will change if orders are moved to 
  323. * custom tables in the future. 
  324. */ 
  325. $wp_query_args = array( 
  326. 'post_type' => $args['type'] ? $args['type'] : 'shop_order',  
  327. 'post_status' => $args['status'],  
  328. 'posts_per_page' => $args['limit'],  
  329. 'meta_query' => array(),  
  330. 'fields' => 'ids',  
  331. 'orderby' => $args['orderby'],  
  332. 'order' => $args['order'],  
  333. ); 
  334.  
  335. if ( ! is_null( $args['parent'] ) ) { 
  336. $wp_query_args['post_parent'] = absint( $args['parent'] ); 
  337.  
  338. if ( ! is_null( $args['offset'] ) ) { 
  339. $wp_query_args['offset'] = absint( $args['offset'] ); 
  340. } else { 
  341. $wp_query_args['paged'] = absint( $args['page'] ); 
  342.  
  343. if ( isset( $args['customer'] ) && '' !== $args['customer'] ) { 
  344. $values = is_array( $args['customer'] ) ? $args['customer'] : array( $args['customer'] ); 
  345. $wp_query_args['meta_query'][] = $this->get_orders_generate_customer_meta_query( $values ); 
  346.  
  347. if ( ! empty( $args['exclude'] ) ) { 
  348. $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); 
  349.  
  350. if ( ! $args['paginate'] ) { 
  351. $wp_query_args['no_found_rows'] = true; 
  352.  
  353. if ( ! empty( $args['date_before'] ) ) { 
  354. $wp_query_args['date_query']['before'] = $args['date_before']; 
  355.  
  356. if ( ! empty( $args['date_after'] ) ) { 
  357. $wp_query_args['date_query']['after'] = $args['date_after']; 
  358.  
  359. // Get results. 
  360. $orders = new WP_Query( apply_filters( 'woocommerce_order_data_store_cpt_get_orders_query', $wp_query_args, $args, $this ) ); 
  361.  
  362. if ( 'objects' === $args['return'] ) { 
  363. $return = array_map( 'wc_get_order', $orders->posts ); 
  364. } else { 
  365. $return = $orders->posts; 
  366.  
  367. if ( $args['paginate'] ) { 
  368. return (object) array( 
  369. 'orders' => $return,  
  370. 'total' => $orders->found_posts,  
  371. 'max_num_pages' => $orders->max_num_pages,  
  372. ); 
  373. } else { 
  374. return $return; 
  375.  
  376. /** 
  377. * Generate meta query for wc_get_orders. 
  378. * @param array $values 
  379. * @param string $relation 
  380. * @return array 
  381. */ 
  382. private function get_orders_generate_customer_meta_query( $values, $relation = 'or' ) { 
  383. $meta_query = array( 
  384. 'relation' => strtoupper( $relation ),  
  385. 'customer_emails' => array( 
  386. 'key' => '_billing_email',  
  387. 'value' => array(),  
  388. 'compare' => 'IN',  
  389. ),  
  390. 'customer_ids' => array( 
  391. 'key' => '_customer_user',  
  392. 'value' => array(),  
  393. 'compare' => 'IN',  
  394. ),  
  395. ); 
  396. foreach ( $values as $value ) { 
  397. if ( is_array( $value ) ) { 
  398. $meta_query[] = $this->get_orders_generate_customer_meta_query( $value, 'and' ); 
  399. } elseif ( is_email( $value ) ) { 
  400. $meta_query['customer_emails']['value'][] = sanitize_email( $value ); 
  401. } else { 
  402. $meta_query['customer_ids']['value'][] = strval( absint( $value ) ); 
  403.  
  404. if ( empty( $meta_query['customer_emails']['value'] ) ) { 
  405. unset( $meta_query['customer_emails'] ); 
  406. unset( $meta_query['relation'] ); 
  407.  
  408. if ( empty( $meta_query['customer_ids']['value'] ) ) { 
  409. unset( $meta_query['customer_ids'] ); 
  410. unset( $meta_query['relation'] ); 
  411.  
  412. return $meta_query; 
  413.  
  414. /** 
  415. * Get unpaid orders after a certain date,  
  416. * @param int timestamp $date 
  417. * @return array 
  418. */ 
  419. public function get_unpaid_orders( $date ) { 
  420. global $wpdb; 
  421.  
  422. $unpaid_orders = $wpdb->get_col( $wpdb->prepare( " 
  423. SELECT posts.ID 
  424. FROM {$wpdb->posts} AS posts 
  425. WHERE posts.post_type IN ('" . implode( "', '", wc_get_order_types() ) . "') 
  426. AND posts.post_status = 'wc-pending' 
  427. AND posts.post_modified < %s 
  428. ", date( 'Y-m-d H:i:s', absint( $date ) ) ) ); 
  429.  
  430. return $unpaid_orders; 
  431.  
  432. /** 
  433. * Search order data for a term and return ids. 
  434. * @param string $term 
  435. * @return array of ids 
  436. */ 
  437. public function search_orders( $term ) { 
  438. global $wpdb; 
  439.  
  440. /** 
  441. * Searches on meta data can be slow - this lets you choose what fields to search. 
  442. * 3.0.0 added _billing_address and _shipping_address meta which contains all address data to make this faster. 
  443. * This however won't work on older orders unless updated, so search a few others (expand this using the filter if needed). 
  444. * @var array 
  445. */ 
  446. $search_fields = array_map( 'wc_clean', apply_filters( 'woocommerce_shop_order_search_fields', array( 
  447. '_billing_address_index',  
  448. '_shipping_address_index',  
  449. '_billing_last_name',  
  450. '_billing_email',  
  451. ) ) ); 
  452. $order_ids = array(); 
  453.  
  454. if ( is_numeric( $term ) ) { 
  455. $order_ids[] = absint( $term ); 
  456.  
  457. if ( ! empty( $search_fields ) ) { 
  458. $order_ids = array_unique( array_merge( 
  459. $order_ids,  
  460. $wpdb->get_col( 
  461. $wpdb->prepare( "SELECT DISTINCT p1.post_id FROM {$wpdb->postmeta} p1 WHERE p1.meta_value LIKE '%%%s%%'", $wpdb->esc_like( wc_clean( $term ) ) ) . " AND p1.meta_key IN ('" . implode( "', '", array_map( 'esc_sql', $search_fields ) ) . "')" 
  462. ),  
  463. $wpdb->get_col( 
  464. $wpdb->prepare( " 
  465. SELECT order_id 
  466. FROM {$wpdb->prefix}woocommerce_order_items as order_items 
  467. WHERE order_item_name LIKE '%%%s%%' 
  468. ",  
  469. $wpdb->esc_like( wc_clean( $term ) ) 
  470. ) ); 
  471.  
  472. return apply_filters( 'woocommerce_shop_order_search_results', $order_ids, $term, $search_fields ); 
  473.  
  474. /** 
  475. * Gets information about whether permissions were generated yet. 
  476. * @param WC_Order|int $order 
  477. * @return bool 
  478. */ 
  479. public function get_download_permissions_granted( $order ) { 
  480. $order_id = WC_Order_Factory::get_order_id( $order ); 
  481. return wc_string_to_bool( get_post_meta( $order_id, '_download_permissions_granted', true ) ); 
  482.  
  483. /** 
  484. * Stores information about whether permissions were generated yet. 
  485. * @param WC_Order|int $order 
  486. * @param bool $set 
  487. */ 
  488. public function set_download_permissions_granted( $order, $set ) { 
  489. $order_id = WC_Order_Factory::get_order_id( $order ); 
  490. update_post_meta( $order_id, '_download_permissions_granted', wc_bool_to_string( $set ) ); 
  491.  
  492. /** 
  493. * Gets information about whether sales were recorded. 
  494. * @param WC_Order|int $order 
  495. * @return bool 
  496. */ 
  497. public function get_recorded_sales( $order ) { 
  498. $order_id = WC_Order_Factory::get_order_id( $order ); 
  499. return wc_string_to_bool( get_post_meta( $order_id, '_recorded_sales', true ) ); 
  500.  
  501. /** 
  502. * Stores information about whether sales were recorded. 
  503. * @param WC_Order|int $order 
  504. * @param bool $set 
  505. */ 
  506. public function set_recorded_sales( $order, $set ) { 
  507. $order_id = WC_Order_Factory::get_order_id( $order ); 
  508. update_post_meta( $order_id, '_recorded_sales', wc_bool_to_string( $set ) ); 
  509.  
  510. /** 
  511. * Gets information about whether coupon counts were updated. 
  512. * @param WC_Order|int $order 
  513. * @return bool 
  514. */ 
  515. public function get_recorded_coupon_usage_counts( $order ) { 
  516. $order_id = WC_Order_Factory::get_order_id( $order ); 
  517. return wc_string_to_bool( get_post_meta( $order_id, '_recorded_coupon_usage_counts', true ) ); 
  518.  
  519. /** 
  520. * Stores information about whether coupon counts were updated. 
  521. * @param WC_Order|int $order 
  522. * @param bool $set 
  523. */ 
  524. public function set_recorded_coupon_usage_counts( $order, $set ) { 
  525. $order_id = WC_Order_Factory::get_order_id( $order ); 
  526. update_post_meta( $order_id, '_recorded_coupon_usage_counts', wc_bool_to_string( $set ) ); 
  527.  
  528. /** 
  529. * Gets information about whether stock was reduced. 
  530. * @param WC_Order|int $order 
  531. * @return bool 
  532. */ 
  533. public function get_stock_reduced( $order ) { 
  534. $order_id = WC_Order_Factory::get_order_id( $order ); 
  535. return wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ); 
  536.  
  537. /** 
  538. * Stores information about whether stock was reduced. 
  539. * @param WC_Order|int $order 
  540. * @param bool $set 
  541. */ 
  542. public function set_stock_reduced( $order, $set ) { 
  543. $order_id = WC_Order_Factory::get_order_id( $order ); 
  544. update_post_meta( $order_id, '_order_stock_reduced', wc_bool_to_string( $set ) ); 
  545.  
  546. /** 
  547. * Get the order type based on Order ID. 
  548. * @since 3.0.0 
  549. * @param int $order_id 
  550. * @return string 
  551. */ 
  552. public function get_order_type( $order_id ) { 
  553. return get_post_type( $order_id );