Fix for manual order addition and other tweaks. Closes #345.

This commit is contained in:
Mike Jolley 2011-12-08 19:45:24 +00:00
parent 08b8e77da6
commit 1790bd09d5
6 changed files with 45 additions and 95 deletions

View File

@ -55,26 +55,28 @@ function woocommerce_content_right_now() {
}
function woocommerce_right_now() {
$woocommerce_orders = &new woocommerce_orders();
$pending_count = get_term_by( 'slug', 'pending', 'shop_order_status' )->count;
$completed_count = get_term_by( 'slug', 'completed', 'shop_order_status' )->count;
$on_hold_count = get_term_by( 'slug', 'on-hold', 'shop_order_status' )->count;
$processing_count = get_term_by( 'slug', 'processing', 'shop_order_status' )->count;
?>
</table>
<p class="sub woocommerce_sub"><?php _e('Orders', 'woothemes'); ?></p>
<table>
<tr>
<td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=pending"><span class="total-count"><?php echo $woocommerce_orders->pending_count; ?></span></a></td>
<td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=pending"><span class="total-count"><?php echo $pending_count; ?></span></a></td>
<td class="last t"><a class="pending" href="edit.php?post_type=shop_order&shop_order_status=pending"><?php _e('Pending', 'woothemes'); ?></a></td>
</tr>
<tr>
<td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=on-hold"><span class="total-count"><?php echo $woocommerce_orders->on_hold_count; ?></span></a></td>
<td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=on-hold"><span class="total-count"><?php echo $on_hold_count; ?></span></a></td>
<td class="last t"><a class="onhold" href="edit.php?post_type=shop_order&shop_order_status=on-hold"><?php _e('On-Hold', 'woothemes'); ?></a></td>
</tr>
<tr>
<td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=processing"><span class="total-count"><?php echo $woocommerce_orders->processing_count; ?></span></a></td>
<td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=processing"><span class="total-count"><?php echo $processing_count; ?></span></a></td>
<td class="last t"><a class="processing" href="edit.php?post_type=shop_order&shop_order_status=processing"><?php _e('Processing', 'woothemes'); ?></a></td>
</tr>
<tr>
<td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=completed"><span class="total-count"><?php echo $woocommerce_orders->completed_count; ?></span></a></td>
<td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=completed"><span class="total-count"><?php echo $completed_count; ?></span></a></td>
<td class="last t"><a class="complete" href="edit.php?post_type=shop_order&shop_order_status=completed"><?php _e('Completed', 'woothemes'); ?></a></td>
</tr>
<?php

View File

@ -2,7 +2,7 @@
/**
* Customer
*
* The WooCommerce custoemr class handles storage of the current customer's data, such as location.
* The WooCommerce customer class handles storage of the current customer's data, such as location.
*
* @class woocommerce_customer
* @package WooCommerce
@ -210,5 +210,5 @@ class woocommerce_customer {
return apply_filters('woocommerce_customer_get_downloadable_products', $downloads);
}
}

View File

@ -1,63 +0,0 @@
<?php
/**
* Orders
*
* The WooCommerce orders class loads orders and calculates counts
*
* @class woocommerce_orders
* @package WooCommerce
* @category Class
* @author WooThemes
*/
class woocommerce_orders {
var $orders;
var $count;
var $completed_count;
var $pending_count;
var $cancelled_count;
var $on_hold_count;
var $processing_count;
var $refunded_count;
/** Loads orders and counts them */
function woocommerce_orders() {
$this->orders = array();
// Get Counts
$this->pending_count = get_term_by( 'slug', 'pending', 'shop_order_status' )->count;
$this->completed_count = get_term_by( 'slug', 'completed', 'shop_order_status' )->count;
$this->cancelled_count = get_term_by( 'slug', 'cancelled', 'shop_order_status' )->count;
$this->on_hold_count = get_term_by( 'slug', 'on-hold', 'shop_order_status' )->count;
$this->refunded_count = get_term_by( 'slug', 'refunded', 'shop_order_status' )->count;
$this->processing_count = get_term_by( 'slug', 'processing', 'shop_order_status' )->count;
$this->count = wp_count_posts( 'shop_order' )->publish;
}
/**
* Loads a customers orders
*
* @param int $user_id ID of the user to load the orders for
* @param int $limit How many orders to load
*/
function get_customer_orders( $user_id, $limit = 5 ) {
$args = array(
'numberposts' => $limit,
'meta_key' => '_customer_user',
'meta_value' => $user_id,
'post_type' => 'shop_order',
'post_status' => 'publish'
);
$results = get_posts($args);
if ($results) :
foreach ($results as $result) :
$order = &new woocommerce_order();
$order->populate($result);
$this->orders[] = $order;
endforeach;
endif;
}
}

View File

@ -82,6 +82,10 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
== Changelog ==
= 1.3.2 =
* Fixed error when adding an order manaully
* Dumped the orders class (hardly used)
= 1.3.1 - 08/12/2011 =
* Many Minor bug fixes
* Ability to re-order payment gateways and choose a default

View File

@ -46,9 +46,15 @@ function woocommerce_my_account( $atts ) {
<h2><?php _e('Recent Orders', 'woothemes'); ?></h2>
<?php
$woocommerce_orders = &new woocommerce_orders();
$woocommerce_orders->get_customer_orders( get_current_user_id(), $recent_orders );
if ($woocommerce_orders->orders) :
$args = array(
'numberposts' => $recent_orders,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => 'shop_order',
'post_status' => 'publish'
);
$customer_orders = get_posts($args);
if ($customer_orders) :
?>
<table class="shop_table my_account_orders">
@ -63,7 +69,9 @@ function woocommerce_my_account( $atts ) {
</thead>
<tbody><?php
foreach ($woocommerce_orders->orders as $order) :
foreach ($customer_orders as $customer_order) :
$order = &new woocommerce_order();
$order->populate($customer_order);
?><tr class="order">
<td><?php echo $order->id; ?></td>
<td><time title="<?php echo esc_attr( strtotime($order->order_date) ); ?>"><?php echo date(get_option('date_format'), strtotime($order->order_date)); ?></time></td>

View File

@ -43,31 +43,30 @@ endif;
* Include core files
**/
if (defined('DOING_AJAX')) :
include_once( 'woocommerce_ajax.php' );
include_once( 'woocommerce_ajax.php' ); // Ajax functions for admin and the front-end
endif;
if ( !is_admin() || defined('DOING_AJAX') ) :
include_once( 'woocommerce_templates.php' );
include_once( 'woocommerce_template_actions.php' );
include_once( 'shortcodes/shortcodes-init.php' );
include_once( 'classes/woocommerce_query.class.php' );
add_action( 'init', 'include_template_functions', 99 );
include_once( 'woocommerce_template_actions.php' ); // Template actions used on the front-end
include_once( 'shortcodes/shortcodes-init.php' ); // Init the shortcodes
include_once( 'classes/woocommerce_query.class.php' ); // The main store queries
include_once( 'classes/cart.class.php' ); // The main cart class
include_once( 'classes/coupons.class.php' ); // Coupons class
include_once( 'classes/customer.class.php' ); // Customer class
add_action( 'init', 'include_template_functions', 99 ); // Defer loading template functions so functions are pluggable by themes
endif;
include_once( 'woocommerce_taxonomy.php' );
include_once( 'widgets/widgets-init.php' );
include_once( 'woocommerce_actions.php' );
include_once( 'woocommerce_emails.php' );
include_once( 'classes/cart.class.php' );
include_once( 'classes/countries.class.php' );
include_once( 'classes/coupons.class.php' );
include_once( 'classes/customer.class.php' );
include_once( 'classes/order.class.php' );
include_once( 'classes/orders.class.php' );
include_once( 'classes/product.class.php' );
include_once( 'classes/product_variation.class.php' );
include_once( 'classes/tax.class.php' );
include_once( 'classes/woocommerce.class.php' );
include_once( 'woocommerce_templates.php' ); // Loads template files - used in admin and front-end
include_once( 'woocommerce_taxonomy.php' ); // Defines post formats and taxonomies
include_once( 'widgets/widgets-init.php' ); // Widget classes
include_once( 'woocommerce_actions.php' ); // Contains action hooks and functions for various events
include_once( 'woocommerce_emails.php' ); // Email template handlers
include_once( 'classes/countries.class.php' ); // Defines countries and states
include_once( 'classes/order.class.php' ); // Single order class
include_once( 'classes/product.class.php' ); // Product class
include_once( 'classes/product_variation.class.php' ); // Product variation class
include_once( 'classes/tax.class.php' ); // Tax class - used in admin and on the front-end
include_once( 'classes/woocommerce.class.php' ); // Main WooCommerce class
/**
* Include shipping modules and gateways