Split order details into customer + item templates. Tidied up codebase/template based logic.

cc @jameskoster
This commit is contained in:
Mike Jolley 2015-05-01 14:50:18 +01:00
parent 77941a57c5
commit d6604cb668
3 changed files with 100 additions and 141 deletions

View File

@ -1835,31 +1835,43 @@ abstract class WC_Abstract_Order {
);
}
$total_rows['order_total'] = array(
'label' => __( 'Total:', 'woocommerce' ),
'value' => $this->get_formatted_order_total()
);
// Order total display
$order_total = $this->get_total();
$total_refunded = $this->get_total_refunded();
$total_string = '';
$tax_string = '';
// Tax for inclusive prices
if ( wc_tax_enabled() && 'incl' == $tax_display ) {
$tax_string_array = array();
if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
foreach ( $this->get_tax_totals() as $code => $tax ) {
$tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
$tax_amount = $total_refunded ? wc_price( WC_Tax::round( $tax->amount - $this->get_total_tax_refunded_by_rate_id( $tax->rate_id ) ), array( 'currency' => $this->get_order_currency() ) ) : $tax->formatted_amount;
$tax_string_array[] = sprintf( '%s %s', $tax_amount, $tax->label );
}
} else {
$tax_string_array[] = sprintf( '%s %s', wc_price( $this->get_total_tax(), array('currency' => $this->get_order_currency()) ), WC()->countries->tax_or_vat() );
$tax_string_array[] = sprintf( '%s %s', wc_price( $this->get_total_tax() - $this->get_total_tax_refunded(), array( 'currency' => $this->get_order_currency() ) ), WC()->countries->tax_or_vat() );
}
if ( ! empty( $tax_string_array ) ) {
$total_rows['order_total']['value'] .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
$tax_string = ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
}
}
if ( $total_refunded ) {
$total_string = '<del>' . strip_tags( $this->get_formatted_order_total() ) . '</del> <ins>';
$total_string .= wc_price( $order_total - $total_refunded, array( 'currency' => $this->get_order_currency() ) );
$total_string .= $tax_string;
$total_string .= '</ins>';
} else {
$total_string = $this->get_formatted_order_total() . $tax_string;
}
$total_rows['order_total'] = array(
'label' => __( 'Total:', 'woocommerce' ),
'value' => $total_string
);
return apply_filters( 'woocommerce_get_order_item_totals', $total_rows, $this );
}
@ -2533,11 +2545,14 @@ abstract class WC_Abstract_Order {
* @return boolean
*/
public function needs_shipping_address() {
if ( 'no' === get_option( 'woocommerce_calc_shipping' ) ) {
return false;
}
$hide = apply_filters( 'woocommerce_order_hide_shipping_address', array( 'local_pickup' ), $this );
$needs = false;
foreach ( $this->get_shipping_methods() as $shipping_method ) {
if ( ! in_array( $shipping_method['method_id'], $hide ) ) {
$needs = true;
break;

View File

@ -0,0 +1,68 @@
<?php
/**
* Order Customer Details
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.4.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<header><h2><?php _e( 'Customer Details', 'woocommerce' ); ?></h2></header>
<table class="shop_table shop_table_responsive customer_details">
<?php if ( $order->customer_note ) : ?>
<tr>
<th><?php _e( 'Note:', 'woocommerce' ); ?></th>
<td><?php echo wptexturize( $order->customer_note ); ?></td>
</tr>
<?php endif; ?>
<?php if ( $order->billing_email ) : ?>
<tr>
<th><?php _e( 'Email:', 'woocommerce' ); ?></th>
<td><?php echo esc_html( $order->billing_email ); ?></td>
</tr>
<?php endif; ?>
<?php if ( $order->billing_phone ) : ?>
<tr>
<th><?php _e( 'Telephone:', 'woocommerce' ); ?></th>
<td><?php echo esc_html( $order->billing_phone ); ?></td>
</tr>
<?php endif; ?>
<?php do_action( 'woocommerce_order_details_after_customer_details', $order ); ?>
</table>
<?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() ) : ?>
<div class="col2-set addresses">
<div class="col-1">
<?php endif; ?>
<header class="title">
<h3><?php _e( 'Billing Address', 'woocommerce' ); ?></h3>
</header>
<address>
<?php echo ( $address = $order->get_formatted_billing_address() ) ? $address : __( 'N/A', 'woocommerce' ); ?>
</address>
<?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() ) : ?>
</div><!-- /.col-1 -->
<div class="col-2">
<header class="title">
<h3><?php _e( 'Shipping Address', 'woocommerce' ); ?></h3>
</header>
<address>
<?php echo ( $address = $order->get_formatted_shipping_address() ) ? $address : __( 'N/A', 'woocommerce' ); ?>
</address>
</div><!-- /.col-2 -->
</div><!-- /.col2-set -->
<?php endif; ?>

View File

@ -35,143 +35,19 @@ $order = wc_get_order( $order_id );
<?php do_action( 'woocommerce_order_items_table', $order ); ?>
</tbody>
<tfoot>
<?php
$has_refund = false;
if ( $total_refunded = $order->get_total_refunded() ) {
$has_refund = true;
}
if ( $totals = $order->get_order_item_totals() ) {
foreach ( $totals as $key => $total ) {
$value = $total['value'];
// Check for refund
if ( $has_refund && $key === 'order_total' ) {
$refunded_tax_del = '';
$refunded_tax_ins = '';
// Tax for inclusive prices
if ( wc_tax_enabled() && 'incl' == $order->tax_display_cart ) {
$tax_del_array = array();
$tax_ins_array = array();
if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
foreach ( $order->get_tax_totals() as $code => $tax ) {
$tax_del_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
$tax_ins_array[] = sprintf( '%s %s', wc_price( $tax->amount - $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ), array( 'currency' => $order->get_order_currency() ) ), $tax->label );
}
} else {
$tax_del_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax(), array( 'currency' => $order->get_order_currency() ) ), WC()->countries->tax_or_vat() );
$tax_ins_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax() - $order->get_total_tax_refunded(), array( 'currency' => $order->get_order_currency() ) ), WC()->countries->tax_or_vat() );
}
if ( ! empty( $tax_del_array ) ) {
$refunded_tax_del .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_del_array ) );
}
if ( ! empty( $tax_ins_array ) ) {
$refunded_tax_ins .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_ins_array ) );
}
}
$value = '<del>' . strip_tags( $order->get_formatted_order_total() ) . $refunded_tax_del . '</del> <ins>' . wc_price( $order->get_total() - $total_refunded, array( 'currency' => $order->get_order_currency() ) ) . $refunded_tax_ins . '</ins>';
}
<?php
foreach ( $order->get_order_item_totals() as $key => $total ) {
?>
<tr>
<th scope="row"><?php echo $total['label']; ?></th>
<td><?php echo $value; ?></td>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
}
}
// Check for refund
if ( $has_refund ) { ?>
<tr>
<th scope="row"><?php _e( 'Refunded:', 'woocommerce' ); ?></th>
<td>-<?php echo wc_price( $total_refunded, array( 'currency' => $order->get_order_currency() ) ); ?></td>
</tr>
<?php
}
// Check for customer note
if ( '' != $order->customer_note ) { ?>
<tr>
<th scope="row"><?php _e( 'Note:', 'woocommerce' ); ?></th>
<td><?php echo wptexturize( $order->customer_note ); ?></td>
</tr>
<?php } ?>
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_order_details_after_order_table', $order ); ?>
<header>
<h2><?php _e( 'Customer details', 'woocommerce' ); ?></h2>
</header>
<table class="shop_table shop_table_responsive customer_details">
<?php
if ( $order->billing_email ) {
echo '<tr><th>' . __( 'Email:', 'woocommerce' ) . '</th><td data-title="' . __( 'Email', 'woocommerce' ) . '">' . $order->billing_email . '</td></tr>';
}
if ( $order->billing_phone ) {
echo '<tr><th>' . __( 'Telephone:', 'woocommerce' ) . '</th><td data-title="' . __( 'Telephone', 'woocommerce' ) . '">' . $order->billing_phone . '</td></tr>';
}
// Additional customer details hook
do_action( 'woocommerce_order_details_after_customer_details', $order );
?>
</table>
<?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) : ?>
<div class="col2-set addresses">
<div class="col-1">
<?php endif; ?>
<header class="title">
<h3><?php _e( 'Billing Address', 'woocommerce' ); ?></h3>
</header>
<address>
<?php
if ( ! $order->get_formatted_billing_address() ) {
_e( 'N/A', 'woocommerce' );
} else {
echo $order->get_formatted_billing_address();
}
?>
</address>
<?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) : ?>
</div><!-- /.col-1 -->
<div class="col-2">
<header class="title">
<h3><?php _e( 'Shipping Address', 'woocommerce' ); ?></h3>
</header>
<address>
<?php
if ( ! $order->get_formatted_shipping_address() ) {
_e( 'N/A', 'woocommerce' );
} else {
echo $order->get_formatted_shipping_address();
}
?>
</address>
</div><!-- /.col-2 -->
</div><!-- /.col2-set -->
<?php endif; ?>
<div class="clear"></div>
<?php wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) ); ?>