Optimisations + order details template

This commit is contained in:
Mike Jolley 2011-12-09 21:47:12 +00:00
parent 111f444da7
commit dae7cf35a2
7 changed files with 157 additions and 175 deletions

View File

@ -293,7 +293,6 @@ class woocommerce_product {
$this->get_post_data(); $this->get_post_data();
return apply_filters('woocommerce_product_title', apply_filters('the_title', $this->post->post_title), $this); return apply_filters('woocommerce_product_title', apply_filters('the_title', $this->post->post_title), $this);
} }
/** Get the add to url */ /** Get the add to url */
function add_to_cart_url() { function add_to_cart_url() {
@ -315,9 +314,8 @@ class woocommerce_product {
/** Returns whether or not the product is stock managed */ /** Returns whether or not the product is stock managed */
function managing_stock() { function managing_stock() {
if (get_option('woocommerce_manage_stock')=='yes') : if (!isset($this->manage_stock) || $this->manage_stock=='no') return false;
if (isset($this->manage_stock) && $this->manage_stock=='yes') return true; if (get_option('woocommerce_manage_stock')=='yes') return true;
endif;
return false; return false;
} }
@ -460,12 +458,11 @@ class woocommerce_product {
/** Returns whether or not the product is on sale */ /** Returns whether or not the product is on sale */
function is_on_sale() { function is_on_sale() {
if ( $this->has_child() ) : if ($this->has_child()) :
foreach ($this->get_children() as $child_id) : foreach ($this->get_children() as $child_id) :
$sale_price = get_post_meta( $child_id, 'sale_price', true ); $sale_price = get_post_meta( $child_id, 'sale_price', true );
$regular_price = get_post_meta( $child_id, 'price', true ); if ( $sale_price >= 0 ) return true;
if ( $sale_price > 0 && $sale_price < $regular_price ) return true;
endforeach; endforeach;
else : else :

View File

@ -0,0 +1,129 @@
<?php
/**
* Order Details
*/
global $woocommerce, $order_id;
$order = &new woocommerce_order( $order_id );
?>
<h2><?php _e('Order Details', 'woothemes'); ?></h2>
<table class="shop_table">
<thead>
<tr>
<th><?php _e('Product', 'woothemes'); ?></th>
<th><?php _e('Qty', 'woothemes'); ?></th>
<th><?php _e('Totals', 'woothemes'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row" colspan="2"><?php _e('Cart Subtotal:', 'woothemes'); ?></th>
<td><?php echo $order->get_subtotal_to_display(); ?></td>
</tr>
<?php if ($order->get_cart_discount() > 0) : ?><tr>
<th scope="row" colspan="2"><?php _e('Cart Discount:', 'woothemes'); ?></th>
<td><?php echo woocommerce_price($order->get_cart_discount()); ?></td>
</tr><?php endif; ?>
<?php if ($order->get_shipping() > 0) : ?><tr>
<th scope="row" colspan="2"><?php _e('Shipping:', 'woothemes'); ?></th>
<td><?php echo $order->get_shipping_to_display(); ?></td>
</tr><?php endif; ?>
<?php if ($order->get_total_tax() > 0) : ?><tr>
<th scope="row" colspan="2"><?php echo $woocommerce->countries->tax_or_vat(); ?></th>
<td><?php echo woocommerce_price($order->get_total_tax()); ?></td>
</tr><?php endif; ?>
<?php if ($order->get_order_discount() > 0) : ?><tr>
<th scope="row" colspan="2"><?php _e('Order Discount:', 'woothemes'); ?></th>
<td><?php echo woocommerce_price($order->get_order_discount()); ?></td>
</tr><?php endif; ?>
<tr>
<th scope="row" colspan="2"><?php _e('Order Total:', 'woothemes'); ?></th>
<td><?php echo woocommerce_price($order->get_order_total()); ?></td>
</tr>
<?php if ($order->customer_note) : ?>
<tr>
<td><?php _e('Note:', 'woothemes'); ?></td>
<td colspan="2"><?php echo wpautop(wptexturize($order->customer_note)); ?></td>
</tr>
<?php endif; ?>
</tfoot>
<tbody>
<?php
if (sizeof($order->items)>0) :
foreach($order->items as $item) :
if (isset($item['variation_id']) && $item['variation_id'] > 0) :
$_product = &new woocommerce_product_variation( $item['variation_id'] );
else :
$_product = &new woocommerce_product( $item['id'] );
endif;
echo '
<tr>
<td class="product-name">'.$item['name'];
$item_meta = &new order_item_meta( $item['item_meta'] );
$item_meta->display();
echo ' </td>
<td>'.$item['qty'].'</td>
<td>';
if ($order->display_cart_ex_tax || !$order->prices_include_tax) :
if ($order->prices_include_tax) $ex_tax_label = 1; else $ex_tax_label = 0;
echo woocommerce_price( $order->get_row_cost( $item, false ), array('ex_tax_label' => $ex_tax_label ));
else :
echo woocommerce_price( $order->get_row_cost( $item, true ) );
endif;
echo '</td>
</tr>';
endforeach;
endif;
?>
</tbody>
</table>
<header>
<h2><?php _e('Customer details', 'woothemes'); ?></h2>
</header>
<dl>
<?php
if ($order->billing_email) echo '<dt>'.__('Email:', 'woothemes').'</dt><dd>'.$order->billing_email.'</dd>';
if ($order->billing_phone) echo '<dt>'.__('Telephone:', 'woothemes').'</dt><dd>'.$order->billing_phone.'</dd>';
?>
</dl>
<div class="col2-set addresses">
<div class="col-1">
<header class="title">
<h3><?php _e('Shipping Address', 'woothemes'); ?></h3>
</header>
<address><p>
<?php
if (!$order->formatted_shipping_address) _e('N/A', 'woothemes'); else echo $order->formatted_shipping_address;
?>
</p></address>
</div><!-- /.col-1 -->
<div class="col-2">
<header class="title">
<h3><?php _e('Billing Address', 'woothemes'); ?></h3>
</header>
<address><p>
<?php
if (!$order->formatted_billing_address) _e('N/A', 'woothemes'); else echo $order->formatted_billing_address;
?>
</p></address>
</div><!-- /.col-2 -->
</div><!-- /.col2-set -->
<div class="clear"></div>

View File

@ -64,17 +64,7 @@ class WooCommerce_Widget_Cart extends WP_Widget {
echo '</ul>'; echo '</ul>';
if (sizeof($woocommerce->cart->get_cart())>0) : if (sizeof($woocommerce->cart->get_cart())>0) :
echo '<p class="total"><strong>'; echo '<p class="total"><strong>' . __('Subtotal', 'woothemes') . ':</strong> '. $woocommerce->cart->get_cart_total() . '</p>';
if (get_option('js_prices_include_tax')=='yes') :
_e('Total', 'woothemes');
else :
_e('Subtotal', 'woothemes');
endif;
echo ':</strong> '.$woocommerce->cart->get_cart_total();
echo '</p>';
do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); do_action( 'woocommerce_widget_shopping_cart_before_buttons' );

View File

@ -7,13 +7,15 @@
* @author WooThemes * @author WooThemes
*/ */
if (is_active_widget( false, false, 'woocommerce_layered_nav', 'true' ) && !is_admin()) :
add_action('init', 'woocommerce_layered_nav_init', 1);
add_filter('loop_shop_post_in', 'woocommerce_layered_nav_query');
endif;
/** /**
* Layered Nav Init * Layered Nav Init
*/ */
if (!is_admin()) add_action('init', 'woocommerce_layered_nav_init', 1);
function woocommerce_layered_nav_init() { function woocommerce_layered_nav_init() {
global $_chosen_attributes, $woocommerce; global $_chosen_attributes, $woocommerce;
$_chosen_attributes = array(); $_chosen_attributes = array();
@ -44,10 +46,7 @@ function woocommerce_layered_nav_init() {
/** /**
* Layered Nav post filter * Layered Nav post filter
*/ */
add_filter('loop_shop_post_in', 'woocommerce_layered_nav_query');
function woocommerce_layered_nav_query( $filtered_posts ) { function woocommerce_layered_nav_query( $filtered_posts ) {
global $_chosen_attributes, $woocommerce; global $_chosen_attributes, $woocommerce;
if (sizeof($_chosen_attributes)>0) : if (sizeof($_chosen_attributes)>0) :

View File

@ -8,12 +8,15 @@
* @category Widgets * @category Widgets
* @author WooThemes * @author WooThemes
*/ */
if (is_active_widget( false, false, 'woocommerce_price_filter', 'true' ) && !is_admin()) :
add_action('init', 'woocommerce_price_filter_init');
add_filter('loop_shop_post_in', 'woocommerce_price_filter');
endif;
/** /**
* Price filter Init * Price filter Init
*/ */
add_action('init', 'woocommerce_price_filter_init');
function woocommerce_price_filter_init() { function woocommerce_price_filter_init() {
unset($_SESSION['min_price']); unset($_SESSION['min_price']);
@ -31,8 +34,6 @@ function woocommerce_price_filter_init() {
/** /**
* Price Filter post filter * Price Filter post filter
*/ */
add_filter('loop_shop_post_in', 'woocommerce_price_filter');
function woocommerce_price_filter( $filtered_posts ) { function woocommerce_price_filter( $filtered_posts ) {
if (isset($_GET['max_price']) && isset($_GET['min_price'])) : if (isset($_GET['max_price']) && isset($_GET['min_price'])) :

View File

@ -88,14 +88,6 @@ function woocommerce_email_content_type($content_type){
} }
/**
* Fix recieve password mail links
**/
function woocommerce_retrieve_password_message($content){
return htmlspecialchars($content);
}
/** /**
* Hooks for emails * Hooks for emails
**/ **/

View File

@ -476,7 +476,6 @@ if (!function_exists('woocommerce_get_product_thumbnail')) {
**/ **/
if (!function_exists('woocommerce_output_related_products')) { if (!function_exists('woocommerce_output_related_products')) {
function woocommerce_output_related_products() { function woocommerce_output_related_products() {
// 2 Related Products in 2 columns
woocommerce_related_products( 2, 2 ); woocommerce_related_products( 2, 2 );
} }
} }
@ -502,8 +501,8 @@ if (!function_exists('woocommerce_related_products')) {
query_posts($args); query_posts($args);
woocommerce_get_template_part( 'loop', 'shop' ); woocommerce_get_template_part( 'loop', 'shop' );
echo '</div>'; echo '</div>';
wp_reset_query();
endif; endif;
wp_reset_query();
} }
} }
@ -616,8 +615,6 @@ if (!function_exists('woocommerce_breadcrumb')) {
elseif ( is_tax('product_cat') ) : elseif ( is_tax('product_cat') ) :
//echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . ucwords(get_option('woocommerce_shop_slug')) . '</a>' . $after . $delimiter;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$parents = array(); $parents = array();
@ -771,7 +768,6 @@ if (!function_exists('woocommerce_breadcrumb')) {
echo $wrap_after; echo $wrap_after;
endif; endif;
} }
} }
@ -834,9 +830,9 @@ function woocommerce_order_review() {
* Adds a demo store banner to the site if enabled * Adds a demo store banner to the site if enabled
**/ **/
function woocommerce_demo_store() { function woocommerce_demo_store() {
if (get_option('woocommerce_demo_store')=='yes') : if (get_option('woocommerce_demo_store')=='no') return;
echo '<p class="demo_store">'.__('This is a demo store for testing purposes &mdash; no orders shall be fulfilled.', 'woothemes').'</p>';
endif; echo apply_filters('woocommerce_demo_store', '<p class="demo_store">'.__('This is a demo store for testing purposes &mdash; no orders shall be fulfilled.', 'woothemes').'</p>' );
} }
/** /**
@ -940,138 +936,16 @@ function woocommerce_subcategory_thumbnail( $category ) {
} }
/** /**
* Display an orders details in a table * Displays order details in a table
**/ **/
function woocommerce_order_details_table( $order_id ) { function woocommerce_order_details_table( $id ) {
global $woocommerce; global $woocommerce, $order_id;
if (!$order_id) return; if (!$id) return;
$order = &new woocommerce_order( $order_id ); $order_id = $id;
?>
<h2><?php _e('Order Details', 'woothemes'); ?></h2> woocommerce_get_template('order/order-details-table.php', false);
<table class="shop_table">
<thead>
<tr>
<th><?php _e('Product', 'woothemes'); ?></th>
<th><?php _e('Qty', 'woothemes'); ?></th>
<th><?php _e('Totals', 'woothemes'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row" colspan="2"><?php _e('Cart Subtotal:', 'woothemes'); ?></th>
<td><?php echo $order->get_subtotal_to_display(); ?></td>
</tr>
<?php if ($order->get_cart_discount() > 0) : ?><tr>
<th scope="row" colspan="2"><?php _e('Cart Discount:', 'woothemes'); ?></th>
<td><?php echo woocommerce_price($order->get_cart_discount()); ?></td>
</tr><?php endif; ?>
<?php if ($order->get_shipping() > 0) : ?><tr>
<th scope="row" colspan="2"><?php _e('Shipping:', 'woothemes'); ?></th>
<td><?php echo $order->get_shipping_to_display(); ?></td>
</tr><?php endif; ?>
<?php if ($order->get_total_tax() > 0) : ?><tr>
<th scope="row" colspan="2"><?php echo $woocommerce->countries->tax_or_vat(); ?></th>
<td><?php echo woocommerce_price($order->get_total_tax()); ?></td>
</tr><?php endif; ?>
<?php if ($order->get_order_discount() > 0) : ?><tr>
<th scope="row" colspan="2"><?php _e('Order Discount:', 'woothemes'); ?></th>
<td><?php echo woocommerce_price($order->get_order_discount()); ?></td>
</tr><?php endif; ?>
<tr>
<th scope="row" colspan="2"><?php _e('Order Total:', 'woothemes'); ?></th>
<td><?php echo woocommerce_price($order->get_order_total()); ?></td>
</tr>
<?php if ($order->customer_note) : ?>
<tr>
<td><?php _e('Note:', 'woothemes'); ?></td>
<td colspan="2"><?php echo wpautop(wptexturize($order->customer_note)); ?></td>
</tr>
<?php endif; ?>
</tfoot>
<tbody>
<?php
if (sizeof($order->items)>0) :
foreach($order->items as $item) :
if (isset($item['variation_id']) && $item['variation_id'] > 0) :
$_product = &new woocommerce_product_variation( $item['variation_id'] );
else :
$_product = &new woocommerce_product( $item['id'] );
endif;
echo '
<tr>
<td class="product-name">'.$item['name'];
$item_meta = &new order_item_meta( $item['item_meta'] );
$item_meta->display();
echo ' </td>
<td>'.$item['qty'].'</td>
<td>';
if (!isset($item['base_cost'])) $item['base_cost'] = $item['cost'];
if ($order->display_cart_ex_tax || !$order->prices_include_tax) :
if ($order->prices_include_tax) $ex_tax_label = 1; else $ex_tax_label = 0;
echo woocommerce_price( $item['base_cost']*$item['qty'], array('ex_tax_label' => $ex_tax_label ));
else :
echo woocommerce_price( round(($item['base_cost']*$item['qty']) * (($item['taxrate']/100) + 1), 2) );
endif;
echo '</td>
</tr>';
endforeach;
endif;
?>
</tbody>
</table>
<header>
<h2><?php _e('Customer details', 'woothemes'); ?></h2>
</header>
<dl>
<?php
if ($order->billing_email) echo '<dt>'.__('Email:', 'woothemes').'</dt><dd>'.$order->billing_email.'</dd>';
if ($order->billing_phone) echo '<dt>'.__('Telephone:', 'woothemes').'</dt><dd>'.$order->billing_phone.'</dd>';
?>
</dl>
<div class="col2-set addresses">
<div class="col-1">
<header class="title">
<h3><?php _e('Shipping Address', 'woothemes'); ?></h3>
</header>
<address><p>
<?php
if (!$order->formatted_shipping_address) _e('N/A', 'woothemes'); else echo $order->formatted_shipping_address;
?>
</p></address>
</div><!-- /.col-1 -->
<div class="col-2">
<header class="title">
<h3><?php _e('Billing Address', 'woothemes'); ?></h3>
</header>
<address><p>
<?php
if (!$order->formatted_billing_address) _e('N/A', 'woothemes'); else echo $order->formatted_billing_address;
?>
</p></address>
</div><!-- /.col-2 -->
</div><!-- /.col2-set -->
<div class="clear"></div>
<?php
} }
/** /**