/** * Get email subject. * * @access public * @return string */ public function get_subject() { if ($this->object->has_status(wc_get_is_paid_statuses())) { return apply_filters('woocommerce_email_subject_customer_invoice_paid', $this->format_string($this->subject_paid), $this->object); } else { return apply_filters('woocommerce_email_subject_customer_invoice', $this->format_string($this->subject), $this->object); } }
/** * Returns if an order has been paid for based on the order status. * @since 2.5.0 * @return bool */ public function is_paid() { return apply_filters('woocommerce_order_is_paid', $this->has_status(wc_get_is_paid_statuses()), $this); }
/** * Return how much money this customer has spent. * * @since 2.7.0 * @param WC_Customer * @return float */ public function get_total_spent(&$customer) { $spent = get_user_meta($customer->get_id(), '_money_spent', true); if ('' === $spent) { global $wpdb; $statuses = array_map('esc_sql', wc_get_is_paid_statuses()); $spent = $wpdb->get_var("SELECT SUM(meta2.meta_value)\n\t\t\t\tFROM {$wpdb->posts} as posts\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta2 ON posts.ID = meta2.post_id\n\t\t\t\tWHERE meta.meta_key = '_customer_user'\n\t\t\t\tAND meta.meta_value = '" . esc_sql($customer->get_id()) . "'\n\t\t\t\tAND posts.post_type = 'shop_order'\n\t\t\t\tAND posts.post_status IN ( 'wc-" . implode("','wc-", $statuses) . "' )\n\t\t\t\tAND meta2.meta_key = '_order_total'\n\t\t\t"); if (!$spent) { $spent = 0; } update_user_meta($customer->get_id(), '_money_spent', $spent); } return wc_format_decimal($spent, 2); }
/** * Handle a completed payment. * @param WC_Order $order * @param array $posted */ protected function payment_status_completed($order, $posted) { if ($order->has_status(wc_get_is_paid_statuses())) { WC_Gateway_Paypal::log('Aborting, Order #' . $order->get_id() . ' is already complete.'); exit; } $this->validate_transaction_type($posted['txn_type']); $this->validate_currency($order, $posted['mc_currency']); $this->validate_amount($order, $posted['mc_gross']); $this->validate_receiver_email($order, $posted['receiver_email']); $this->save_paypal_meta_data($order, $posted); if ('completed' === $posted['payment_status']) { $this->payment_complete($order, !empty($posted['txn_id']) ? wc_clean($posted['txn_id']) : '', __('IPN payment completed', 'woocommerce')); if (!empty($posted['mc_fee'])) { // Log paypal transaction fee. update_post_meta($order->get_id(), 'PayPal Transaction Fee', wc_clean($posted['mc_fee'])); } } else { if ('authorization' === $posted['pending_reason']) { $this->payment_on_hold($order, __('Payment authorized. Change payment status to processing or complete to capture funds.', 'woocommerce')); } else { $this->payment_on_hold($order, sprintf(__('Payment pending (%s).', 'woocommerce'), $posted['pending_reason'])); } } }
/** * 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_map('wc_get_order_status_name', wc_get_is_paid_statuses()), 'customer' => $user->ID)); if (!empty($orders)) { $order = $orders[0]; return '<a href="' . admin_url('post.php?post=' . $order->get_id() . '&action=edit') . '">' . _x('#', 'hash before order number', 'woocommerce') . $order->get_order_number() . '</a> – ' . date_i18n(get_option('date_format'), $order->get_date_created()); } 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_map('wc_get_order_status_name', wc_get_is_paid_statuses()), '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 ''; }