/** * Get the order refunds for an order * * @since 2.2 * @param string $order_id order ID * @param string|null $fields fields to include in response * @return array */ public function get_order_refunds($order_id, $fields = null) { // Ensure ID is valid order ID $order_id = $this->validate_request($order_id, $this->post_type, 'read'); if (is_wp_error($order_id)) { return $order_id; } $refund_items = wc_get_orders(array('type' => 'shop_order_refund', 'parent' => $order_id, 'limit' => -1, 'return' => 'ids')); $order_refunds = array(); foreach ($refund_items as $refund_id) { $order_refunds[] = current($this->get_order_refund($order_id, $refund_id, $fields)); } return array('order_refunds' => apply_filters('woocommerce_api_order_refunds_response', $order_refunds, $order_id, $fields, $refund_items, $this)); }
/** * Get order refunds. * @since 2.2 * @return array of WC_Order_Refund objects */ public function get_refunds() { if (empty($this->refunds) && !is_array($this->refunds)) { $this->refunds = wc_get_orders(array('type' => 'shop_order_refund', 'parent' => $this->id, 'limit' => -1)); } return $this->refunds; }
/** * Get past orders (by email) and update them. * * @param int $customer_id * @return int */ function wc_update_new_customer_past_orders($customer_id) { $linked = 0; $complete = 0; $customer = get_user_by('id', absint($customer_id)); $customer_orders = wc_get_orders(array('limit' => -1, 'customer' => array(array(0, $customer->user_email)), 'return' => 'ids')); if (!empty($customer_orders)) { foreach ($customer_orders as $order_id) { update_post_meta($order_id, '_customer_user', $customer->ID); do_action('woocommerce_update_new_customer_past_order', $order_id, $customer); if (get_post_status($order_id) === 'wc-completed') { $complete++; } $linked++; } } if ($complete) { update_user_meta($customer_id, 'paying_customer', 1); update_user_meta($customer_id, '_order_count', ''); update_user_meta($customer_id, '_money_spent', ''); } return $linked; }
/** * Get order refunds. * @since 2.2 * @return array of WC_Order_Refund objects */ public function get_refunds() { $this->refunds = wc_get_orders(array('type' => 'shop_order_refund', 'parent' => $this->get_id(), 'limit' => -1)); return $this->refunds; }
/** * Get the orders for a customer * * @since 2.1 * @param int $id the customer ID * @param string $fields fields to include in response * @return array */ public function get_customer_orders($id, $fields = null) { global $wpdb; $id = $this->validate_request($id, 'customer', 'read'); if (is_wp_error($id)) { return $id; } $order_ids = wc_get_orders(array('customer' => $id, 'limit' => -1, 'orderby' => 'date', 'order' => 'ASC', 'return' => 'ids')); if (empty($order_ids)) { return array('orders' => array()); } $orders = array(); foreach ($order_ids as $order_id) { $orders[] = current(WC()->api->WC_API_Orders->get_order($order_id, $fields)); } return array('orders' => apply_filters('woocommerce_api_customer_orders_response', $orders, $id, $fields, $order_ids, $this->server)); }
/** * My Account > Orders template. * * @param int $current_page Current page number. */ function woocommerce_account_orders($current_page) { $current_page = empty($current_page) ? 1 : absint($current_page); $customer_orders = wc_get_orders(apply_filters('woocommerce_my_account_my_orders_query', array('customer' => get_current_user_id(), 'page' => $current_page, 'paginate' => true))); wc_get_template('myaccount/orders.php', array('current_page' => absint($current_page), 'customer_orders' => $customer_orders, 'has_orders' => 0 < $customer_orders->total)); }
/** * Get column value. * * @param WP_User $user * @param string $column_name * @return string */ public function column_default($user, $column_name) { global $wpdb; switch ($column_name) { case 'customer_name': if ($user->last_name && $user->first_name) { return $user->last_name . ', ' . $user->first_name; } else { return '-'; } case 'username': return $user->user_login; case 'location': $state_code = get_user_meta($user->ID, 'billing_state', true); $country_code = get_user_meta($user->ID, 'billing_country', true); $state = isset(WC()->countries->states[$country_code][$state_code]) ? WC()->countries->states[$country_code][$state_code] : $state_code; $country = isset(WC()->countries->countries[$country_code]) ? WC()->countries->countries[$country_code] : $country_code; $value = ''; if ($state) { $value .= $state . ', '; } $value .= $country; if ($value) { return $value; } else { return '-'; } case 'email': return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>'; case 'spent': return wc_price(wc_get_customer_total_spent($user->ID)); case 'orders': return wc_get_customer_order_count($user->ID); case 'last_order': $orders = wc_get_orders(array('limit' => 1, 'status' => array('wc-completed', 'wc-processing'), 'customer' => $user->ID)); if (!empty($orders)) { $order = $orders[0]; return '<a href="' . admin_url('post.php?post=' . $order->id . '&action=edit') . '">' . _x('#', 'hash before order number', 'woocommerce') . $order->get_order_number() . '</a> – ' . date_i18n(get_option('date_format'), strtotime($order->order_date)); } else { return '-'; } break; case 'user_actions': ob_start(); ?> <p> <?php do_action('woocommerce_admin_user_actions_start', $user); $actions = array(); $actions['refresh'] = array('url' => wp_nonce_url(add_query_arg('refresh', $user->ID), 'refresh'), 'name' => __('Refresh stats', 'woocommerce'), 'action' => "refresh"); $actions['edit'] = array('url' => admin_url('user-edit.php?user_id=' . $user->ID), 'name' => __('Edit', 'woocommerce'), 'action' => "edit"); $actions['view'] = array('url' => admin_url('edit.php?post_type=shop_order&_customer_user='******'name' => __('View orders', 'woocommerce'), 'action' => "view"); $orders = wc_get_orders(array('limit' => 1, 'status' => array('wc-completed', 'wc-processing'), 'customer' => array(array(0, $user->user_email)))); if ($orders) { $actions['link'] = array('url' => wp_nonce_url(add_query_arg('link_orders', $user->ID), 'link_orders'), 'name' => __('Link previous orders', 'woocommerce'), 'action' => "link"); } $actions = apply_filters('woocommerce_admin_user_actions', $actions, $user); foreach ($actions as $action) { printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name'])); } do_action('woocommerce_admin_user_actions_end', $user); ?> </p><?php $user_actions = ob_get_contents(); ob_end_clean(); return $user_actions; } return ''; }