Esempio n. 1
1
 /**
  * Update a order status
  *
  * @return void
  */
 function change_order_status()
 {
     check_ajax_referer('dokan_change_status');
     $order_id = intval($_POST['order_id']);
     $order_status = $_POST['order_status'];
     $order = new WC_Order($order_id);
     $order->update_status($order_status);
     $statuses = wc_get_order_statuses();
     $status_label = isset($statuses[$order_status]) ? $statuses[$order_status] : $order_status;
     $status_class = dokan_get_order_status_class($order_status);
     echo '<label class="dokan-label dokan-label-' . $status_class . '">' . $status_label . '</label>';
     exit;
 }
 /**
  * Get settings array
  *
  * @return array
  */
 public function get_settings()
 {
     global $woocommerce, $wp_roles;
     $statuses = wc_crm_get_statuses_slug();
     $settings = array();
     $filters = array('name' => __('Filters', 'wc_crm'), 'desc_tip' => 'Choose which filters you would like to display on the Customers page.', 'id' => 'wc_crm_filters', 'class' => 'chosen_select', 'type' => 'multiselect', 'options' => array('user_roles' => __('User Roles', 'wc_crm'), 'last_order' => __('Last Order', 'wc_crm'), 'state' => __('State', 'wc_crm'), 'city' => __('City', 'wc_crm'), 'country' => __('Country', 'wc_crm'), 'customer_name' => __('Customer Name', 'wc_crm'), 'products' => __('Products', 'wc_crm'), 'products_variations' => __('Products Variations', 'wc_crm'), 'order_status' => __('Order Status', 'wc_crm'), 'customer_status' => __('Customer Status', 'wc_crm'), 'products_categories' => __('Product Categories', 'wc_crm')), 'defa');
     if (class_exists('WC_Brands_Admin')) {
         $filters['options']['products_brands'] = __('Product Brands', 'wc_crm');
     }
     $settings[] = array('title' => __('General Options', 'woocommerce'), 'type' => 'title', 'desc' => '', 'id' => 'general_crm_options');
     $settings[] = array('name' => __('Username', 'wc_crm'), 'desc_tip' => __('Choose what the username is when customers are added.', 'wc_crm'), 'id' => 'wc_crm_username_add_customer', 'type' => 'select', 'class' => 'wc-enhanced-select', 'options' => array(1 => __('First & last name e.g. johnsmith', 'wc_crm'), 2 => __('Hyphen separated e.g. john-smith', 'wc_crm'), 3 => __('Email address', 'wc_crm')), 'autoload' => true);
     $settings[] = $filters;
     $settings[] = array('name' => __('Value', 'wc_crm'), 'desc_tip' => __('Choose which statuses the customer orders must be before appearing in the Value column.', 'wc_crm'), 'id' => 'wc_crm_total_value', 'class' => 'chosen_select', 'type' => 'multiselect', 'options' => wc_get_order_statuses());
     $settings[] = array('title' => __('Automatic Emails', 'wc_crm'), 'desc' => __('Check this box to send an email with username and password when creating a new customer.', 'wc_crm'), 'id' => 'wc_crm_automatic_emails_new_customer', 'default' => 'yes', 'type' => 'checkbox', 'checkboxgroup' => 'start');
     if (class_exists('WC_Subscriptions')) {
         $settings[] = array('title' => __('Subscribers', 'wc_crm'), 'desc' => __('Check this box to show column indicating whether customer is an active subscriber.', 'wc_crm'), 'id' => 'wc_crm_show_subscribers_column', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'start');
     }
     if (class_exists('Groups_WordPress') && class_exists('Groups_WS')) {
         $settings[] = array('title' => __('Groups Integration', 'wc_crm'), 'desc' => __('Check this box to show column indicating which group is the customer a member of.', 'wc_crm'), 'id' => 'wc_crm_show_groups_wc_column', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'start');
     }
     $settings[] = array('type' => 'sectionend', 'id' => 'general_crm_options');
     $settings[] = array('title' => __('Fetch Customers', 'wc_crm'), 'type' => 'title', 'desc' => __('The following options affects how the customers in the customers table should be fetched.', 'wc_crm'), 'id' => 'crm_fetch_customers');
     $settings[] = array('name' => __('User Roles', 'wc_crm'), 'desc_tip' => 'Choose which User Roles of the customers/users that will be shown in the customers table.', 'id' => 'wc_crm_user_roles', 'type' => 'multiselect', 'class' => 'chosen_select', 'options' => $wp_roles->role_names);
     $settings[] = array('title' => __('Guest Customers', 'woocommerce'), 'desc' => 'Select whether Guest customers appear on the customers table.', 'id' => 'wc_crm_guest_customers', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'start');
     $settings[] = array('name' => __('Customer Name Format', 'wc_crm'), 'desc_tip' => __('Choose the format of the names displayed on the Customers page.', 'wc_crm'), 'id' => 'wc_crm_customer_name', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'fl', 'options' => array('fl' => __('First Last', 'wc_crm'), 'lf' => __('Last, First', 'wc_crm')));
     $settings[] = array('type' => 'sectionend', 'id' => 'crm_fetch_customers');
     $settings[] = array('title' => __('Default Status', 'wc_crm'), 'type' => 'title', 'desc' => __('The following options determine the default status for the customers when added to this site.', 'wc_crm'), 'id' => 'crm_default_customer_status');
     $settings[] = array('name' => __('Manually Added', 'wc_crm'), 'desc_tip' => __('Added manually via this plugin.', 'wc_crm'), 'id' => 'wc_crm_default_status_crm', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'Lead', 'options' => $statuses);
     $settings[] = array('name' => __('Purchased Customers', 'wc_crm'), 'desc_tip' => __('Added automatically via purchases made.', 'wc_crm'), 'id' => 'wc_crm_default_status_store', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'Customer', 'options' => $statuses);
     $settings[] = array('name' => __('Registration Page', 'wc_crm'), 'desc_tip' => __('Added via the account registration page.', 'wc_crm'), 'id' => 'wc_crm_default_status_account', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'Prospect', 'options' => $statuses);
     $settings[] = array('type' => 'sectionend', 'id' => 'crm_default_customer_status');
     return apply_filters('woocommerce_customer_relationship_general_settings_fields', $settings);
 }
Esempio n. 3
0
/**
 * Get the nice name for an order status
 *
 * @since  2.2
 * @param  string $status
 * @return string
 */
function wc_get_order_status_name($status)
{
    $statuses = wc_get_order_statuses();
    $status = 'wc-' === substr($status, 0, 3) ? substr($status, 3) : $status;
    $status = isset($statuses['wc-' . $status]) ? $statuses['wc-' . $status] : $status;
    return $status;
}
 function init_form_fields()
 {
     global $woocommerce;
     require_once $woocommerce->plugin_path() . '/includes/wc-order-functions.php';
     $this->form_fields = array('enabled' => array('title' => 'Habilitar/Deshabilitar', 'type' => 'checkbox', 'label' => 'Habilitar modulo de pago TodoPago', 'default' => 'no'), 'title' => array('title' => 'Título', 'type' => 'text', 'description' => 'Título que el usuario ve durante el checkout', 'default' => 'TodoPago'), 'description' => array('title' => 'Descripción', 'type' => 'textarea', 'description' => 'Descripción que el usuario ve durante el checkout', 'default' => 'Paga de manera segura mediante TodoPago<br>Solo para la república argentina'), 'ambiente' => array('title' => 'Ambiente', 'type' => 'select', 'description' => 'Seleccione el ambiente con el que desea trabajar', 'options' => array('test' => 'developers', 'prod' => 'produccion')), 'tipo_segmento' => array('title' => 'Tipo de Segmento', 'type' => 'select', 'description' => 'Seleccione el tipo de segmento con el que desea trabajar', 'options' => array('retail' => 'Retail')), 'deadline' => array('title' => 'Deadline', 'type' => 'text', 'description' => 'Dias maximos para la entrega'), 'titulo_testing' => array('title' => 'Ambiente de Developers', 'type' => 'title', 'description' => 'Datos correspondientes al ambiente de developers', 'id' => 'testing_options'), 'http_header_test' => array('title' => 'HTTP Header', 'type' => 'text', 'description' => 'Header en formato JSON. Ejemplo: <br>
                       {"Authorization":"PRISMA 912EC803B2CE49E4A541068D12345678"}'), 'security_test' => array('title' => 'Security', 'type' => 'text', 'description' => 'Código provisto por Todo Pago'), 'merchant_id_test' => array('title' => 'Merchant ID', 'type' => 'text', 'description' => 'Nombre de comercio provisto por Todo Pago'), 'titulo_produccion' => array('title' => 'Ambiente de Producción', 'type' => 'title', 'description' => 'Datos correspondientes al ambiente de producción', 'id' => 'produccion_options'), 'http_header_prod' => array('title' => 'HTTP Header', 'type' => 'text', 'description' => 'Header en formato JSON. Ejemplo: <br>
                       {"Authorization":"PRISMA 912EC803B2CE49E4A541068D12345678"}'), 'security_prod' => array('title' => 'Security', 'type' => 'text', 'description' => 'Código provisto por Todo Pago'), 'merchant_id_prod' => array('title' => 'Merchant ID', 'type' => 'text', 'description' => 'Nombre de comercio provisto por Todo Pago'), 'titulo_estados_pedidos' => array('title' => 'Estados del Pedido', 'type' => 'title', 'description' => 'Datos correspondientes al estado de los pedidos', 'id' => 'estados_pedido_options'), 'estado_inicio' => array('title' => 'Estado cuando la transacción ha<br>sido iniciada', 'type' => 'select', 'options' => wc_get_order_statuses(), 'default' => 'wc-pending', 'description' => 'Valor por defecto: Pendiente de pago'), 'estado_aprobacion' => array('title' => 'Estado cuando la transacción ha<br>sido aprobada', 'type' => 'select', 'options' => wc_get_order_statuses(), 'default' => 'wc-completed', 'description' => 'Valor por defecto: Completado'), 'estado_rechazo' => array('title' => 'Estado cuando la transacción ha<br>sido rechazada', 'type' => 'select', 'options' => wc_get_order_statuses(), 'default' => 'wc-failed', 'description' => 'Valor por defecto: Falló'), 'estado_offline' => array('title' => 'Estado cuando la transacción ha<br>sido offline', 'type' => 'select', 'options' => wc_get_order_statuses()));
 }
Esempio n. 5
0
 /**
  * Test wc_orders_count().
  * @since 2.4
  */
 public function test_wc_orders_count()
 {
     foreach (wc_get_order_statuses() as $status) {
         $this->assertEquals(0, wc_orders_count($status));
     }
     // Invalid status returns 0
     $this->assertEquals(0, wc_orders_count('unkown-status'));
 }
 public function orders_dashboard_model($dashboard_model)
 {
     // $dashboard_model[$this->dashboard_key]['tables']['posts']['where']['post_status'] = array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed');
     $dashboard_model[$this->dashboard_key]['tables']['posts']['where']['post_type'] = 'shop_order';
     $post_type_col_index = sm_multidimesional_array_search('posts_post_status', 'index', $dashboard_model[$this->dashboard_key]['columns']);
     $dashboard_model[$this->dashboard_key]['columns'][$post_type_col_index]['values'] = wc_get_order_statuses();
     return $dashboard_model;
 }
Esempio n. 7
0
/**
 * Show sub-orders on a parent order if available
 *
 * @param WC_Order $parent_order
 * @return void
 */
function dokan_order_show_suborders($parent_order)
{
    $sub_orders = get_children(array('post_parent' => $parent_order->id, 'post_type' => 'shop_order', 'post_status' => array('wc-pending', 'wc-completed', 'wc-processing', 'wc-on-hold')));
    if (!$sub_orders) {
        return;
    }
    $statuses = wc_get_order_statuses();
    dokan_get_template_part('sub-orders', '', array('sub_orders' => $sub_orders, 'statuses' => $statuses));
}
 /**
  * get_order_statuses.
  */
 function get_order_statuses()
 {
     $result = array();
     $statuses = function_exists('wc_get_order_statuses') ? wc_get_order_statuses() : array();
     foreach ($statuses as $status => $status_name) {
         $result[substr($status, 3)] = $statuses[$status];
     }
     return $result;
 }
 /**
  * @param $order_id
  * @param $old_status
  * @param $new_status
  *
  * @return bool|void
  */
 public function handle_status_change($order_id, $old_status, $new_status)
 {
     $statuses = wc_get_order_statuses();
     // if we don't get a wc-prefixed status.
     $status = 'wc-' === substr($new_status, 0, 3) ? substr($new_status, 3) : $new_status;
     if (isset($statuses['wc-' . $status]) && 'wc-' . $status === $this->settings->onstatus) {
         return $this->process_items($order_id);
     }
     return false;
 }
 /**
  * Returns the order status key for the $status given.
  * Order status keys have changed in WC 2.2 and this is provided to make
  * it easier to handle.
  * 
  * @param string $status key, one of 'pending', 'failed', 'on-hold', 'processing', 'completed', 'refunded', 'cancelled'
  * @return string status key for current WC
  */
 public static function get_order_status($status)
 {
     $result = $status;
     if (function_exists('wc_get_order_statuses')) {
         // only from WC 2.2
         if (in_array('wc-' . $status, array_keys(wc_get_order_statuses()))) {
             $result = 'wc-' . $status;
         }
     }
     return $result;
 }
 /**
  * Get all the settings for this plugin for @see woocommerce_admin_fields() function.
  *
  * @return array Array of settings for @see woocommerce_admin_fields() function.
  */
 public static function wc_onc_get_settings()
 {
     $wc_onc_settings = array();
     $wc_onc_order_statuses = wc_get_order_statuses();
     $wc_onc_settings[] = array('name' => __('Order Note Colors', 'colored-order-notes-for-woocommerce'), 'type' => 'title', 'desc' => 'Here you can specify the bacground color for order note based on order status', 'id' => 'wc_settings_order_note_colors');
     /* This loop will provide color setting option for all default + custom order status */
     foreach ($wc_onc_order_statuses as $wc_onc_order_status) {
         $wc_onc_order_status_id = strtolower("onc_" . str_replace(' ', '_', $wc_onc_order_status));
         $wc_onc_settings[] = array('name' => __($wc_onc_order_status, 'colored-order-notes-for-woocommerce'), 'type' => 'color', 'id' => $wc_onc_order_status_id);
     }
     $wc_onc_settings[] = array('type' => 'sectionend', 'id' => 'wc_settings_order_note_colors_end');
     return apply_filters('wc_settings_tab_order_note_color_settings', $wc_onc_settings);
 }
Esempio n. 12
0
/**
 * Create a new order programmatically.
 *
 * Returns a new order object on success which can then be used to add additional data.
 *
 * @param  array $args
 *
 * @return WC_Order|WP_Error WC_Order on success, WP_Error on failure.
 */
function wc_create_order($args = array())
{
    $default_args = array('status' => '', 'customer_id' => null, 'customer_note' => null, 'order_id' => 0, 'created_via' => '', 'cart_hash' => '', 'parent' => 0);
    $args = wp_parse_args($args, $default_args);
    $order_data = array();
    if ($args['order_id'] > 0) {
        $updating = true;
        $order_data['ID'] = $args['order_id'];
    } else {
        $updating = false;
        $order_data['post_type'] = 'shop_order';
        $order_data['post_status'] = 'wc-' . apply_filters('woocommerce_default_order_status', 'pending');
        $order_data['ping_status'] = 'closed';
        $order_data['post_author'] = 1;
        $order_data['post_password'] = uniqid('order_');
        $order_data['post_title'] = sprintf(__('Order &ndash; %s', 'woocommerce'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce')));
        $order_data['post_parent'] = absint($args['parent']);
    }
    if ($args['status']) {
        if (!in_array('wc-' . $args['status'], array_keys(wc_get_order_statuses()))) {
            return new WP_Error('woocommerce_invalid_order_status', __('Invalid order status', 'woocommerce'));
        }
        $order_data['post_status'] = 'wc-' . $args['status'];
    }
    if (!is_null($args['customer_note'])) {
        $order_data['post_excerpt'] = $args['customer_note'];
    }
    if ($updating) {
        $order_id = wp_update_post($order_data);
    } else {
        $order_id = wp_insert_post(apply_filters('woocommerce_new_order_data', $order_data), true);
    }
    if (is_wp_error($order_id)) {
        return $order_id;
    }
    if (!$updating) {
        update_post_meta($order_id, '_order_key', 'wc_' . apply_filters('woocommerce_generate_order_key', uniqid('order_')));
        update_post_meta($order_id, '_order_currency', get_woocommerce_currency());
        update_post_meta($order_id, '_prices_include_tax', get_option('woocommerce_prices_include_tax'));
        update_post_meta($order_id, '_customer_ip_address', WC_Geolocation::get_ip_address());
        update_post_meta($order_id, '_customer_user_agent', isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
        update_post_meta($order_id, '_customer_user', 0);
        update_post_meta($order_id, '_created_via', sanitize_text_field($args['created_via']));
        update_post_meta($order_id, '_cart_hash', sanitize_text_field($args['cart_hash']));
    }
    if (is_numeric($args['customer_id'])) {
        update_post_meta($order_id, '_customer_user', $args['customer_id']);
    }
    update_post_meta($order_id, '_order_version', WC_VERSION);
    return wc_get_order($order_id);
}
 /**
  * column_default function.
  *
  * @param WP_User $user
  * @param string $column_name
  * @return string
  */
 public function column_default($user, $column_name)
 {
     global $wpdb;
     if ('orders' == $column_name) {
         if (!($count = get_user_meta($user->ID, '_order_count', true))) {
             global $wpdb;
             $count = $wpdb->get_var("SELECT COUNT(*)\r\n\t\t\t\t\tFROM {$wpdb->posts} as posts\r\n\r\n\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id\r\n\r\n\t\t\t\t\tWHERE   meta.meta_key       = '_customer_user'\r\n\t\t\t\t\tAND     posts.post_type     IN ('" . implode("','", wc_get_order_types('order-count')) . "')\r\n\t\t\t\t\tAND     posts.post_status   IN ('" . implode("','", array_keys(wc_get_order_statuses())) . "')\r\n\t\t\t\t\tAND     posts.post_parent   = 0\r\n\t\t\t\t\tAND     meta_value          = {$user->ID}\r\n\t\t\t\t");
             update_user_meta($user->ID, '_order_count', absint($count));
         }
         $result = absint($count);
     } else {
         $result = parent::column_default($user, $column_name);
     }
     return $result;
 }
Esempio n. 14
0
 public function get_order_statuses_id_to_name()
 {
     $result = array();
     if (function_exists('wc_get_order_statuses')) {
         $result['version'] = 2.2;
         //[slug] => name
         $result['statuses'] = wc_get_order_statuses();
     } else {
         $args = array('hide_empty' => false, 'fields' => 'id=>name');
         $result['version'] = 2.1;
         //[id] => name
         $result['statuses'] = get_terms('shop_order_status', $args);
     }
     return $result;
 }
 /**
  * Mark an order with a status
  *
  * TODO: Remove once 2.2 compatibility is dropped {@link https://github.com/woothemes/woocommerce/pull/6791}
  *
  * @since 1.0.0
  */
 public static function mark_order_status()
 {
     if (!current_user_can('edit_shop_orders')) {
         wp_die(__('You do not have sufficient permissions to access this page.', WC_Order_Status_Manager::TEXT_DOMAIN), '', array('response' => 403));
     }
     if (!check_admin_referer('wc-order-status-manager-mark-order-status')) {
         wp_die(__('You have taken too long. Please go back and retry.', WC_Order_Status_Manager::TEXT_DOMAIN), '', array('response' => 403));
     }
     $status = isset($_GET['status']) ? esc_attr($_GET['status']) : '';
     $order_statuses = wc_get_order_statuses();
     if (!$status || !isset($order_statuses['wc-' . $status])) {
         die;
     }
     $order_id = isset($_GET['order_id']) && (int) $_GET['order_id'] ? (int) $_GET['order_id'] : '';
     if (!$order_id) {
         die;
     }
     $order = wc_get_order($order_id);
     $order->update_status($status);
     wp_safe_redirect(wp_get_referer() ? wp_get_referer() : admin_url('edit.php?post_type=shop_order'));
     die;
 }
    /**
     * column_default function.
     *
     * @param mixed  $user
     * @param string $column_name
     * @return int|string
     * @todo Inconsistent return types, and void return at the end. Needs a rewrite.
     */
    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;
                break;
            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 '-';
                }
                break;
            case 'email':
                return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>';
            case 'spent':
                if (!($spent = get_user_meta($user->ID, '_money_spent', true))) {
                    $spent = $wpdb->get_var("SELECT SUM(meta2.meta_value)\n\t\t\t\t\t\tFROM {$wpdb->posts} as posts\n\n\t\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta2 ON posts.ID = meta2.post_id\n\n\t\t\t\t\t\tWHERE   meta.meta_key       = '_customer_user'\n\t\t\t\t\t\tAND     meta.meta_value     = {$user->ID}\n\t\t\t\t\t\tAND     posts.post_type     IN ('" . implode("','", wc_get_order_types('reports')) . "')\n\t\t\t\t\t\tAND     posts.post_status   = 'wc-completed'\n\t\t\t\t\t\tAND     meta2.meta_key      = '_order_total'\n\t\t\t\t\t");
                    update_user_meta($user->ID, '_money_spent', $spent);
                }
                return wc_price($spent);
                break;
            case 'orders':
                if (!($count = get_user_meta($user->ID, '_order_count', true))) {
                    $count = $wpdb->get_var("SELECT COUNT(*)\n\t\t\t\t\t\tFROM {$wpdb->posts} as posts\n\n\t\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id\n\n\t\t\t\t\t\tWHERE   meta.meta_key       = '_customer_user'\n\t\t\t\t\t\tAND     posts.post_type     IN ('" . implode("','", wc_get_order_types('order-count')) . "')\n\t\t\t\t\t\tAND     posts.post_status   = 'wc-completed'\n\t\t\t\t\t\tAND     meta_value          = {$user->ID}\n\t\t\t\t\t");
                    update_user_meta($user->ID, '_order_count', $count);
                }
                return absint($count);
                break;
            case 'last_order':
                $order_ids = get_posts(array('posts_per_page' => 1, 'post_type' => 'shop_order', 'orderby' => 'date', 'order' => 'desc', 'post_status' => array_keys(wc_get_order_statuses()), 'meta_query' => array(array('key' => '_customer_user', 'value' => $user->ID)), 'fields' => 'ids'));
                if ($order_ids) {
                    $order = wc_get_order($order_ids[0]);
                    echo '<a href="' . admin_url('post.php?post=' . $order->id . '&action=edit') . '">' . $order->get_order_number() . '</a> &ndash; ' . date_i18n(get_option('date_format'), strtotime($order->order_date));
                } else {
                    echo '-';
                }
                break;
            case 'user_actions':
                ?>
<p>
					<?php 
                do_action('woocommerce_admin_user_actions_start', $user);
                $actions = array();
                $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");
                $order_ids = get_posts(array('posts_per_page' => 1, 'post_type' => wc_get_order_types(), 'post_status' => array_keys(wc_get_order_statuses()), 'meta_query' => array(array('key' => '_customer_user', 'value' => array(0, ''), 'compare' => 'IN'), array('key' => '_billing_email', 'value' => $user->user_email)), 'fields' => 'ids'));
                if ($order_ids) {
                    $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 
                break;
        }
    }
    /**
     * Output the metabox
     */
    public static function output($post)
    {
        global $theorder;
        if (!is_object($theorder)) {
            $theorder = wc_get_order($post->ID);
        }
        $order = $theorder;
        self::init_address_fields();
        if (WC()->payment_gateways()) {
            $payment_gateways = WC()->payment_gateways->payment_gateways();
        } else {
            $payment_gateways = array();
        }
        $payment_method = !empty($order->payment_method) ? $order->payment_method : '';
        wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce');
        ?>
		<style type="text/css">
			#post-body-content, #titlediv { display:none }
		</style>
		<div class="panel-wrap woocommerce">
			<input name="post_title" type="hidden" value="<?php 
        echo empty($post->post_title) ? 'Order' : esc_attr($post->post_title);
        ?>
" />
			<input name="post_status" type="hidden" value="<?php 
        echo esc_attr($post->post_status);
        ?>
" />
			<div id="order_data" class="panel">

				<h2><?php 
        printf(__('Order #%s Details', 'woocommerce'), esc_html($order->get_order_number()));
        ?>
</h2>
				<p class="order_number"><?php 
        if ($payment_method) {
            printf(__('Payment via %s', 'woocommerce'), isset($payment_gateways[$payment_method]) ? esc_html($payment_gateways[$payment_method]->get_title()) : esc_html($payment_method));
            if ($transaction_id = $order->get_transaction_id()) {
                if (isset($payment_gateways[$payment_method]) && ($url = $payment_gateways[$payment_method]->get_transaction_url($order))) {
                    echo ' (<a href="' . esc_url($url) . '" target="_blank">' . esc_html($transaction_id) . '</a>)';
                } else {
                    echo ' (' . esc_html($transaction_id) . ')';
                }
            }
            echo '. ';
        }
        if ($ip_address = get_post_meta($post->ID, '_customer_ip_address', true)) {
            echo __('Customer IP', 'woocommerce') . ': ' . esc_html($ip_address);
        }
        ?>
</p>

				<div class="order_data_column_container">
					<div class="order_data_column">
						<h4><?php 
        _e('General Details', 'woocommerce');
        ?>
</h4>

						<p class="form-field form-field-wide"><label for="order_date"><?php 
        _e('Order date:', 'woocommerce');
        ?>
</label>
							<input type="text" class="date-picker" name="order_date" id="order_date" maxlength="10" value="<?php 
        echo date_i18n('Y-m-d', strtotime($post->post_date));
        ?>
" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />@<input type="text" class="hour" placeholder="<?php 
        _e('h', 'woocommerce');
        ?>
" name="order_date_hour" id="order_date_hour" maxlength="2" size="2" value="<?php 
        echo date_i18n('H', strtotime($post->post_date));
        ?>
" pattern="\-?\d+(\.\d{0,})?" />:<input type="text" class="minute" placeholder="<?php 
        _e('m', 'woocommerce');
        ?>
" name="order_date_minute" id="order_date_minute" maxlength="2" size="2" value="<?php 
        echo date_i18n('i', strtotime($post->post_date));
        ?>
" pattern="\-?\d+(\.\d{0,})?" />
						</p>

						<p class="form-field form-field-wide"><label for="order_status"><?php 
        _e('Order status:', 'woocommerce');
        ?>
</label>
						<select id="order_status" name="order_status" class="wc-enhanced-select">
							<?php 
        $statuses = wc_get_order_statuses();
        foreach ($statuses as $status => $status_name) {
            echo '<option value="' . esc_attr($status) . '" ' . selected($status, 'wc-' . $order->get_status(), false) . '>' . esc_html($status_name) . '</option>';
        }
        ?>
						</select></p>

						<p class="form-field form-field-wide wc-customer-user">
							<label for="customer_user"><?php 
        _e('Customer:', 'woocommerce');
        ?>
 <?php 
        if (!empty($order->customer_user)) {
            $args = array('post_status' => 'all', 'post_type' => 'shop_order', '_customer_user' => absint($order->customer_user));
            printf('<a href="%s">%s &rarr;</a>', esc_url(add_query_arg($args, admin_url('edit.php'))), __('View other orders', 'woocommerce'));
        }
        ?>
</label>
							<?php 
        $user_string = '';
        $user_id = '';
        if (!empty($order->customer_user)) {
            $user_id = absint($order->customer_user);
            $user = get_user_by('id', $user_id);
            $user_string = esc_html($user->display_name) . ' (#' . absint($user->ID) . ' &ndash; ' . esc_html($user->user_email);
        }
        ?>
							<input type="hidden" class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php 
        _e('Guest', 'woocommerce');
        ?>
" data-selected="<?php 
        echo htmlspecialchars($user_string);
        ?>
" value="<?php 
        echo $user_id;
        ?>
" data-allow_clear="true" />
						</p>
						<?php 
        do_action('woocommerce_admin_order_data_after_order_details', $order);
        ?>
					</div>
					<div class="order_data_column">
						<h4><?php 
        _e('Billing Details', 'woocommerce');
        ?>
 <a class="edit_address" href="#"><img src="<?php 
        echo WC()->plugin_url();
        ?>
/assets/images/icons/edit.png" alt="<?php 
        _e('Edit', 'woocommerce');
        ?>
" width="14" /></a></h4>
						<?php 
        // Display values
        echo '<div class="address">';
        if ($order->get_formatted_billing_address()) {
            echo '<p><strong>' . __('Address', 'woocommerce') . ':</strong>' . wp_kses($order->get_formatted_billing_address(), array('br' => array())) . '</p>';
        } else {
            echo '<p class="none_set"><strong>' . __('Address', 'woocommerce') . ':</strong> ' . __('No billing address set.', 'woocommerce') . '</p>';
        }
        foreach (self::$billing_fields as $key => $field) {
            if (isset($field['show']) && false === $field['show']) {
                continue;
            }
            $field_name = 'billing_' . $key;
            if ($order->{$field_name}) {
                echo '<p><strong>' . esc_html($field['label']) . ':</strong> ' . make_clickable(esc_html($order->{$field_name})) . '</p>';
            }
        }
        echo '</div>';
        // Display form
        echo '<div class="edit_address"><p><button class="button load_customer_billing">' . __('Load billing address', 'woocommerce') . '</button></p>';
        foreach (self::$billing_fields as $key => $field) {
            if (!isset($field['type'])) {
                $field['type'] = 'text';
            }
            if (!isset($field['id'])) {
                $field['id'] = '_billing_' . $key;
            }
            switch ($field['type']) {
                case 'select':
                    woocommerce_wp_select($field);
                    break;
                default:
                    woocommerce_wp_text_input($field);
                    break;
            }
        }
        ?>
							<p class="form-field form-field-wide">
								<label><?php 
        _e('Payment Method:', 'woocommerce');
        ?>
</label>
								<select name="_payment_method" id="_payment_method" class="first">
									<option value=""><?php 
        _e('N/A', 'woocommerce');
        ?>
</option>
									<?php 
        $found_method = false;
        foreach ($payment_gateways as $gateway) {
            if ($gateway->enabled == "yes") {
                echo '<option value="' . esc_attr($gateway->id) . '" ' . selected($payment_method, $gateway->id, false) . '>' . esc_html($gateway->get_title()) . '</option>';
                if ($payment_method == $gateway->id) {
                    $found_method = true;
                }
            }
        }
        if (!$found_method && !empty($payment_method)) {
            echo '<option value="' . esc_attr($payment_method) . '" selected="selected">' . __('Other', 'woocommerce') . '</option>';
        } else {
            echo '<option value="other">' . __('Other', 'woocommerce') . '</option>';
        }
        ?>
								</select>
							</p>
							<?php 
        woocommerce_wp_text_input(array('id' => '_transaction_id', 'label' => __('Transaction ID', 'woocommerce')));
        echo '</div>';
        do_action('woocommerce_admin_order_data_after_billing_address', $order);
        ?>
					</div>
					<div class="order_data_column">

						<h4><?php 
        _e('Shipping Details', 'woocommerce');
        ?>
 <a class="edit_address" href="#"><img src="<?php 
        echo WC()->plugin_url();
        ?>
/assets/images/icons/edit.png" alt="<?php 
        _e('Edit', 'woocommerce');
        ?>
" width="14" /></a></h4>
						<?php 
        // Display values
        echo '<div class="address">';
        if ($order->get_formatted_shipping_address()) {
            echo '<p><strong>' . __('Address', 'woocommerce') . ':</strong>' . wp_kses($order->get_formatted_shipping_address(), array('br' => array())) . '</p>';
        } else {
            echo '<p class="none_set"><strong>' . __('Address', 'woocommerce') . ':</strong> ' . __('No shipping address set.', 'woocommerce') . '</p>';
        }
        if (self::$shipping_fields) {
            foreach (self::$shipping_fields as $key => $field) {
                if (isset($field['show']) && false === $field['show']) {
                    continue;
                }
                $field_name = 'shipping_' . $key;
                if (!empty($order->{$field_name})) {
                    echo '<p><strong>' . esc_html($field['label']) . ':</strong> ' . make_clickable(esc_html($order->{$field_name})) . '</p>';
                }
            }
        }
        if (apply_filters('woocommerce_enable_order_notes_field', 'yes' == get_option('woocommerce_enable_order_comments', 'yes')) && $post->post_excerpt) {
            echo '<p><strong>' . __('Customer Note', 'woocommerce') . ':</strong> ' . nl2br(esc_html($post->post_excerpt)) . '</p>';
        }
        echo '</div>';
        // Display form
        echo '<div class="edit_address"><p><button class="button load_customer_shipping">' . __('Load shipping address', 'woocommerce') . '</button> <button class="button billing-same-as-shipping">' . __('Copy from billing', 'woocommerce') . '</button></p>';
        if (self::$shipping_fields) {
            foreach (self::$shipping_fields as $key => $field) {
                if (!isset($field['type'])) {
                    $field['type'] = 'text';
                }
                if (!isset($field['id'])) {
                    $field['id'] = '_shipping_' . $key;
                }
                switch ($field['type']) {
                    case 'select':
                        woocommerce_wp_select($field);
                        break;
                    default:
                        woocommerce_wp_text_input($field);
                        break;
                }
            }
        }
        if (apply_filters('woocommerce_enable_order_notes_field', 'yes' == get_option('woocommerce_enable_order_comments', 'yes'))) {
            ?>
								<p class="form-field form-field-wide"><label for="excerpt"><?php 
            _e('Customer Note:', 'woocommerce');
            ?>
</label>
								<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php 
            _e('Customer\'s notes about the order', 'woocommerce');
            ?>
"><?php 
            echo wp_kses_post($post->post_excerpt);
            ?>
</textarea></p>
								<?php 
        }
        echo '</div>';
        do_action('woocommerce_admin_order_data_after_shipping_address', $order);
        ?>
					</div>
				</div>
				<div class="clear"></div>
			</div>
		</div>
		<?php 
    }
 /**
  * Get order statuses.
  *
  * @return array
  */
 protected function get_order_statuses()
 {
     $order_statuses = array();
     foreach (array_keys(wc_get_order_statuses()) as $status) {
         $order_statuses[] = str_replace('wc-', '', $status);
     }
     return $order_statuses;
 }
Esempio n. 19
0
/**
 * Get total orders by customer.
 * @param  int $user_id
 * @return int
 */
function wc_get_customer_order_count($user_id)
{
    if (!($count = get_user_meta($user_id, '_order_count', true))) {
        global $wpdb;
        $count = $wpdb->get_var("SELECT COUNT(*)\n\t\t\tFROM {$wpdb->posts} as posts\n\n\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id\n\n\t\t\tWHERE   meta.meta_key       = '_customer_user'\n\t\t\tAND     posts.post_type     IN ('" . implode("','", wc_get_order_types('order-count')) . "')\n\t\t\tAND     posts.post_status   IN ('" . implode("','", array_keys(wc_get_order_statuses())) . "')\n\t\t\tAND     meta_value          = {$user_id}\n\t\t");
        update_user_meta($user_id, '_order_count', absint($count));
    }
    return absint($count);
}
Esempio n. 20
0
<?php

/**
 * My Orders
 *
 * Shows recent orders on the account page
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     2.2.0
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
$customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array('numberposts' => $order_count, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_type' => wc_get_order_types('view-orders'), 'post_status' => array_keys(wc_get_order_statuses()))));
if ($customer_orders) {
    ?>

	<h2><?php 
    echo apply_filters('woocommerce_my_account_my_orders_title', __('Recent Quote Requests', 'woocommerce'));
    ?>
</h2>

	<table class="shop_table shop_table_responsive my_account_orders">

		<thead>
			<tr>
				<th class="order-number"><span class="nobr"><?php 
    _e('Order', 'woocommerce');
    ?>
 /**
  * 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 = $wpdb->get_col($wpdb->prepare("SELECT id\n\t\t\t\t\t\tFROM {$wpdb->posts} AS posts\n\t\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id\n\t\t\t\t\t\tWHERE meta.meta_key = '_customer_user'\n\t\t\t\t\t\tAND   meta.meta_value = '%s'\n\t\t\t\t\t\tAND   posts.post_type = 'shop_order'\n\t\t\t\t\t\tAND   posts.post_status IN ( '" . implode("','", array_keys(wc_get_order_statuses())) . "' )\n\t\t\t\t\t", $id));
     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));
 }
Esempio n. 22
0
/**
 * Get info about customer's last order.
 *
 * @since 2.6.0
 * @param int $customer_id Customer ID.
 * @return WC_Order Order object if successful or false.
 */
function wc_get_customer_last_order($customer_id)
{
    global $wpdb;
    $customer_id = absint($customer_id);
    $id = $wpdb->get_var("SELECT id\n\t\tFROM {$wpdb->posts} AS posts\n\t\tLEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id\n\t\tWHERE meta.meta_key = '_customer_user'\n\t\tAND   meta.meta_value = {$customer_id}\n\t\tAND   posts.post_type = 'shop_order'\n\t\tAND   posts.post_status IN ( '" . implode("','", array_keys(wc_get_order_statuses())) . "' )\n\t\tORDER BY posts.ID DESC\n\t");
    return wc_get_order($id);
}
/**
 * Return the orders count of a specific order status.
 *
 * @access public
 * @return int
 */
function wc_orders_count($status)
{
    $count = 0;
    $order_statuses = array_keys(wc_get_order_statuses());
    if (!in_array('wc-' . $status, $order_statuses)) {
        return 0;
    }
    foreach (wc_get_order_types('order-count') as $type) {
        $this_count = wp_count_posts($type, 'readable');
        $count += isset($this_count->{'wc-' . $status}) ? $this_count->{'wc-' . $status} : 0;
    }
    return $count;
}
 /**
  * Updates status of order
  *
  * @param string $new_status Status to change the order to. No internal wc- prefix is required.
  * @param string $note (default: '') Optional note to add
  * @param bool $manual is this a manual order status change?
  */
 public function update_status($new_status, $note = '', $manual = false)
 {
     if (!$this->id) {
         return;
     }
     // Standardise status names.
     $new_status = 'wc-' === substr($new_status, 0, 3) ? substr($new_status, 3) : $new_status;
     $old_status = $this->get_status();
     // Only update if they differ - and ensure post_status is a 'wc' status.
     if ($new_status !== $old_status || !in_array($this->post_status, array_keys(wc_get_order_statuses()))) {
         // Update the order
         wp_update_post(array('ID' => $this->id, 'post_status' => 'wc-' . $new_status));
         $this->post_status = 'wc-' . $new_status;
         $this->add_order_note(trim($note . ' ' . sprintf(__('Order status changed from %s to %s.', 'woocommerce'), wc_get_order_status_name($old_status), wc_get_order_status_name($new_status))), 0, $manual);
         // Status was changed
         do_action('woocommerce_order_status_' . $new_status, $this->id);
         do_action('woocommerce_order_status_' . $old_status . '_to_' . $new_status, $this->id);
         do_action('woocommerce_order_status_changed', $this->id, $old_status, $new_status);
         switch ($new_status) {
             case 'completed':
                 // Record the sales
                 $this->record_product_sales();
                 // Increase coupon usage counts
                 $this->increase_coupon_usage_counts();
                 // Record the completed date of the order
                 update_post_meta($this->id, '_completed_date', current_time('mysql'));
                 // Update reports
                 wc_delete_shop_order_transients($this->id);
                 break;
             case 'processing':
             case 'on-hold':
                 // Record the sales
                 $this->record_product_sales();
                 // Increase coupon usage counts
                 $this->increase_coupon_usage_counts();
                 // Update reports
                 wc_delete_shop_order_transients($this->id);
                 break;
             case 'cancelled':
                 // If the order is cancelled, restore used coupons
                 $this->decrease_coupon_usage_counts();
                 // Update reports
                 wc_delete_shop_order_transients($this->id);
                 break;
         }
     }
 }
Esempio n. 25
0
/**
 * Get customer available downloads
 *
 * @param int $customer_id Customer/User ID
 * @return array
 */
function wc_get_customer_available_downloads($customer_id)
{
    global $wpdb;
    $downloads = array();
    $_product = null;
    $order = null;
    $file_number = 0;
    // Get results from valid orders only
    $results = $wpdb->get_results($wpdb->prepare("\n\t\tSELECT permissions.*\n\t\tFROM {$wpdb->prefix}woocommerce_downloadable_product_permissions as permissions\n\t\tLEFT JOIN {$wpdb->posts} as posts ON permissions.order_id = posts.ID\n\t\tWHERE user_id = %d\n\t\tAND permissions.order_id > 0\n\t\tAND posts.post_status IN ( '" . implode("','", array_keys(wc_get_order_statuses())) . "' )\n\t\tAND\n\t\t\t(\n\t\t\t\tpermissions.downloads_remaining > 0\n\t\t\t\tOR\n\t\t\t\tpermissions.downloads_remaining = ''\n\t\t\t)\n\t\tAND\n\t\t\t(\n\t\t\t\tpermissions.access_expires IS NULL\n\t\t\t\tOR\n\t\t\t\tpermissions.access_expires >= %s\n\t\t\t)\n\t\tGROUP BY permissions.download_id\n\t\tORDER BY permissions.order_id, permissions.product_id, permissions.permission_id;\n\t\t", $customer_id, date('Y-m-d', current_time('timestamp'))));
    if ($results) {
        foreach ($results as $result) {
            if (!$order || $order->id != $result->order_id) {
                // new order
                $order = wc_get_order($result->order_id);
                $_product = null;
            }
            // Downloads permitted?
            if (!$order->is_download_permitted()) {
                continue;
            }
            if (!$_product || $_product->id != $result->product_id) {
                // new product
                $file_number = 0;
                $_product = wc_get_product($result->product_id);
            }
            // Check product exists and has the file
            if (!$_product || !$_product->exists() || !$_product->has_file($result->download_id)) {
                continue;
            }
            $download_file = $_product->get_file($result->download_id);
            // Download name will be 'Product Name' for products with a single downloadable file, and 'Product Name - File X' for products with multiple files
            $download_name = apply_filters('woocommerce_downloadable_product_name', $_product->get_title() . ' &ndash; ' . $download_file['name'], $_product, $result->download_id, $file_number);
            $downloads[] = array('download_url' => add_query_arg(array('download_file' => $result->product_id, 'order' => $result->order_key, 'email' => $result->user_email, 'key' => $result->download_id), home_url('/')), 'download_id' => $result->download_id, 'product_id' => $result->product_id, 'download_name' => $download_name, 'order_id' => $order->id, 'order_key' => $order->order_key, 'downloads_remaining' => $result->downloads_remaining, 'file' => $download_file);
            $file_number++;
        }
    }
    return $downloads;
}
 /**
  * Helper method to get order post objects
  *
  * @since 2.1
  * @param array $args request arguments for filtering query
  * @return WP_Query
  */
 protected function query_orders($args)
 {
     // set base query arguments
     $query_args = array('fields' => 'ids', 'post_type' => $this->post_type, 'post_status' => array_keys(wc_get_order_statuses()));
     // add status argument
     if (!empty($args['status'])) {
         $statuses = 'wc-' . str_replace(',', ',wc-', $args['status']);
         $statuses = explode(',', $statuses);
         $query_args['post_status'] = $statuses;
         unset($args['status']);
     }
     $query_args = $this->merge_query_args($query_args, $args);
     return new WP_Query($query_args);
 }
Esempio n. 27
0
 /**
  * Set order status.
  * @since 2.7.0
  * @param string $new_status Status to change the order to. No internal wc- prefix is required.
  * @return array details of change
  */
 public function set_status($new_status)
 {
     $old_status = $this->get_status();
     $new_status = 'wc-' === substr($new_status, 0, 3) ? substr($new_status, 3) : $new_status;
     // Only allow valid new status
     if (!in_array('wc-' . $new_status, array_keys(wc_get_order_statuses()))) {
         $new_status = 'pending';
     }
     $this->data['status'] = 'wc-' . $new_status;
     // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
     if ($old_status && !in_array('wc-' . $old_status, array_keys(wc_get_order_statuses()))) {
         $old_status = 'pending';
     }
     return array('from' => $old_status, 'to' => $new_status);
 }
 function column_group_terms($item)
 {
     if ($item['group_type'] == 'dynamic') {
         $output = '';
         if (!empty($item['group_last_order_from'])) {
             switch ($item['group_last_order']) {
                 case 'between':
                     if (strtotime($item['group_last_order_from']) !== false && strtotime($item['group_last_order_to']) !== false) {
                         $output .= 'Date ' . $item['group_last_order'] . ' ' . $item['group_last_order_from'] . ' to ' . $item['group_last_order_to'] . '<br />';
                     }
                     break;
                 default:
                     if (strtotime($item['group_last_order_from']) !== false) {
                         $output .= 'Date ' . $item['group_last_order'] . ' ' . $item['group_last_order_from'] . '<br />';
                     }
                     break;
             }
         }
         if (!empty($item['group_user_role'])) {
             $output .= 'User role is ' . $item['group_user_role'] . '<br />';
         }
         if (!empty($item['group_customer_status'])) {
             $group_customer_status = unserialize($item['group_customer_status']);
             if (!empty($group_customer_status)) {
                 if (count($group_customer_status) > 1 || !empty($group_customer_status[0])) {
                     $output .= sprintf(__('Customer status is %s'), implode(', ', $group_customer_status)) . '<br />';
                 }
             }
         }
         if (!empty($item['group_product_categories'])) {
             $group_product_categories = unserialize($item['group_product_categories']);
             if (!empty($group_product_categories)) {
                 if (count($group_product_categories) > 1 || !empty($group_product_categories[0])) {
                     $cat_names = array();
                     foreach ($group_product_categories as $cat) {
                         $term = get_term_by('id', $cat, 'product_cat');
                         $cat_names[] = $term->name;
                     }
                     $output .= sprintf(__('Product category is %s'), implode(', ', $cat_names)) . '<br />';
                 }
             }
         }
         if (!empty($item['group_order_status'])) {
             $group_order_status = unserialize($item['group_order_status']);
             if (!empty($group_order_status)) {
                 if (count($group_order_status) > 1 || !empty($group_order_status[0])) {
                     $wc_statuses = wc_get_order_statuses();
                     $staus_names = array();
                     foreach ($group_order_status as $status) {
                         $staus_names[] = $wc_statuses[$status];
                     }
                     $output .= sprintf(__('Order status is %s'), implode(', ', $staus_names)) . '<br />';
                 }
             }
         }
         if (!empty($item['group_total_spent'])) {
             $output .= 'Total spent is ' . convert_group_total_spent_mark($item['group_total_spent_mark']) . ' ' . woocommerce_price($item['group_total_spent']) . '<br />';
         }
         return $output;
     }
 }
Esempio n. 29
0
 /**
  * Return the number of orders this customer has.
  * @since 2.7.0
  * @return integer
  */
 public function get_order_count()
 {
     global $wpdb;
     $count = $wpdb->get_var("SELECT COUNT(*)\n\t\t\tFROM {$wpdb->posts} as posts\n\t\t\tLEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id\n\t\t\tWHERE   meta.meta_key = '_customer_user'\n\t\t\tAND     posts.post_type = 'shop_order'\n\t\t\tAND     posts.post_status IN ( '" . implode("','", array_map('esc_sql', array_keys(wc_get_order_statuses()))) . "' )\n\t\t\tAND     meta_value = '" . esc_sql($this->get_id()) . "'\n\t\t");
     return absint($count);
 }
Esempio n. 30
0
	function woo_ce_return_count( $export_type = '', $args = array() ) {

		global $wpdb;

		$count_sql = null;
		$woocommerce_version = woo_get_woo_version();

		switch( $export_type ) {

			case 'product':
				$post_type = array( 'product', 'product_variation' );
				$args = array(
					'post_type' => $post_type,
					'posts_per_page' => 1,
					'fields' => 'ids',
					'suppress_filters' => 1
				);
				$count_query = new WP_Query( $args );
				$count = $count_query->found_posts;
				break;

			case 'category':
				$term_taxonomy = 'product_cat';
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'tag':
				$term_taxonomy = 'product_tag';
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'brand':
				$term_taxonomy = apply_filters( 'woo_ce_brand_term_taxonomy', 'product_brand' );
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'order':
				$post_type = 'shop_order';
				// Check if this is a WooCommerce 2.2+ instance (new Post Status)
				if( version_compare( $woocommerce_version, '2.2' ) >= 0 )
					$post_status = ( function_exists( 'wc_get_order_statuses' ) ? apply_filters( 'woo_ce_order_post_status', array_keys( wc_get_order_statuses() ) ) : 'any' );
				else
					$post_status = apply_filters( 'woo_ce_order_post_status', woo_ce_post_statuses() );
				$args = array(
					'post_type' => $post_type,
					'posts_per_page' => 1,
					'post_status' => $post_status,
					'fields' => 'ids'
				);
				$count_query = new WP_Query( $args );
				$count = $count_query->found_posts;
				break;

			case 'customer':
				if( $users = woo_ce_return_count( 'user' ) > 1000 ) {
					$count = sprintf( '~%s+', 1000 );
				} else {
					$post_type = 'shop_order';
					$args = array(
						'post_type' => $post_type,
						'posts_per_page' => -1,
						'fields' => 'ids'
					);
					// Check if this is a WooCommerce 2.2+ instance (new Post Status)
					if( version_compare( $woocommerce_version, '2.2' ) >= 0 ) {
						$args['post_status'] = apply_filters( 'woo_ce_customer_post_status', array( 'wc-pending', 'wc-on-hold', 'wc-processing', 'wc-completed' ) );
					} else {
						$args['post_status'] = apply_filters( 'woo_ce_customer_post_status', woo_ce_post_statuses() );
						$args['tax_query'] = array(
							array(
								'taxonomy' => 'shop_order_status',
								'field' => 'slug',
								'terms' => array( 'pending', 'on-hold', 'processing', 'completed' )
							),
						);
					}
					$order_ids = new WP_Query( $args );
					$count = $order_ids->found_posts;
					if( $count > 100 ) {
						$count = sprintf( '~%s', $count );
					} else {
						$customers = array();
						if( $order_ids->posts ) {
							foreach( $order_ids->posts as $order_id ) {
								$email = get_post_meta( $order_id, '_billing_email', true );
								if( !in_array( $email, $customers ) )
									$customers[$order_id] = $email;
								unset( $email );
							}
							$count = count( $customers );
						}
					}
				}
/*
				if( false ) {
					$orders = get_posts( $args );
					if( $orders ) {
						$customers = array();
						foreach( $orders as $order ) {
							$order->email = get_post_meta( $order->ID, '_billing_email', true );
							if( empty( $order->email ) ) {
								if( $order->user_id = get_post_meta( $order->ID, '_customer_user', true ) ) {
									$user = get_userdata( $order->user_id );
									if( $user )
										$order->email = $user->user_email;
									unset( $user );
								} else {
									$order->email = '-';
								}
							}
							if( !in_array( $order->email, $customers ) ) {
								$customers[$order->ID] = $order->email;
								$count++;
							}
						}
						unset( $orders, $order );
					}
				}
*/
				break;

			case 'user':
				if( $users = count_users() )
					$count = $users['total_users'];
				break;

			case 'coupon':
				$post_type = 'shop_coupon';
				if( post_type_exists( $post_type ) )
					$count = wp_count_posts( $post_type );
				break;

			case 'subscription':
				$count = 0;
				// Check that WooCommerce Subscriptions exists
				if( class_exists( 'WC_Subscriptions' ) ) {
					if( method_exists( 'WC_Subscriptions', 'is_large_site' ) ) {
						// Does this store have roughly more than 3000 Subscriptions
						if( false === WC_Subscriptions::is_large_site() ) {
							if( class_exists( 'WC_Subscriptions_Manager' ) ) {
								// Check that the get_all_users_subscriptions() function exists
								if( method_exists( 'WC_Subscriptions_Manager', 'get_all_users_subscriptions' ) ) {
									if( $subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions() ) {
										foreach( $subscriptions as $key => $user_subscription ) {
											if( !empty( $user_subscription ) ) {
												foreach( $user_subscription as $subscription )
													$count++;
											}
										}
										unset( $subscriptions, $subscription, $user_subscription );
									}
								}
							}
						} else {
							if( method_exists( 'WC_Subscriptions', 'get_total_subscription_count' ) )
								$count = WC_Subscriptions::get_total_subscription_count();
							else
								$count = "~2500";
						}
					}
				}
				break;

			case 'product_vendor':
				$term_taxonomy = 'shop_vendor';
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'commission':
				$post_type = 'shop_commission';
				if( post_type_exists( $post_type ) )
					$count = wp_count_posts( $post_type );
				break;

			case 'shipping_class':
				$term_taxonomy = 'product_shipping_class';
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'attribute':
				$attributes = ( function_exists( 'wc_get_attribute_taxonomies' ) ? wc_get_attribute_taxonomies() : array() );
				$count = count( $attributes );
				break;

		}
		if( isset( $count ) || $count_sql ) {
			if( isset( $count ) ) {
				if( is_object( $count ) ) {
					$count = (array)$count;
					$count = (int)array_sum( $count );
				}
				return $count;
			} else {
				if( $count_sql )
					$count = $wpdb->get_var( $count_sql );
				else
					$count = 0;
			}
			return $count;
		} else {
			return 0;
		}

	}