PageRenderTime 114ms CodeModel.GetById 60ms app.highlight 12ms RepoModel.GetById 39ms app.codeStats 0ms

/templates/cart/totals.php

https://github.com/alexcsandru/woocommerce
PHP | 195 lines | 127 code | 59 blank | 9 comment | 30 complexity | c2908cc14c9113067ed4ba6a0950d000 MD5 | raw file
  1<?php
  2/**
  3 * Cart totals
  4 *
  5 * @author 		WooThemes
  6 * @package 	WooCommerce/Templates
  7 * @version     2.0.0
  8 */
  9
 10if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 11
 12global $woocommerce;
 13
 14$available_methods = $woocommerce->shipping->get_available_shipping_methods();
 15?>
 16<div class="cart_totals <?php if ( $woocommerce->customer->has_calculated_shipping() ) echo 'calculated_shipping'; ?>">
 17
 18	<?php do_action( 'woocommerce_before_cart_totals' ); ?>
 19
 20	<?php if ( ! $woocommerce->shipping->enabled || $available_methods || ! $woocommerce->customer->get_shipping_country() || ! $woocommerce->customer->has_calculated_shipping() ) : ?>
 21
 22		<h2><?php _e( 'Cart Totals', 'woocommerce' ); ?></h2>
 23
 24		<table cellspacing="0">
 25			<tbody>
 26
 27				<tr class="cart-subtotal">
 28					<th><strong><?php _e( 'Cart Subtotal', 'woocommerce' ); ?></strong></th>
 29					<td><strong><?php echo $woocommerce->cart->get_cart_subtotal(); ?></strong></td>
 30				</tr>
 31
 32				<?php if ( $woocommerce->cart->get_discounts_before_tax() ) : ?>
 33
 34					<tr class="discount">
 35						<th><?php _e( 'Cart Discount', 'woocommerce' ); ?> <a href="<?php echo add_query_arg( 'remove_discounts', '1', $woocommerce->cart->get_cart_url() ) ?>"><?php _e( '[Remove]', 'woocommerce' ); ?></a></th>
 36						<td>-<?php echo $woocommerce->cart->get_discounts_before_tax(); ?></td>
 37					</tr>
 38
 39				<?php endif; ?>
 40
 41				<?php if ( $woocommerce->cart->needs_shipping() && $woocommerce->cart->show_shipping() && ( $available_methods || get_option( 'woocommerce_enable_shipping_calc' ) == 'yes' ) ) : ?>
 42
 43					<?php do_action( 'woocommerce_cart_totals_before_shipping' ); ?>
 44
 45					<tr class="shipping">
 46						<th><?php _e( 'Shipping', 'woocommerce' ); ?></th>
 47						<td><?php woocommerce_get_template( 'cart/shipping-methods.php', array( 'available_methods' => $available_methods ) ); ?></td>
 48					</tr>
 49
 50					<?php do_action( 'woocommerce_cart_totals_after_shipping' ); ?>
 51
 52				<?php endif ?>
 53
 54				<?php foreach ( $woocommerce->cart->get_fees() as $fee ) : ?>
 55
 56					<tr class="fee fee-<?php echo $fee->id ?>">
 57						<th><?php echo $fee->name ?></th>
 58						<td><?php
 59							if ( $woocommerce->cart->tax_display_cart == 'excl' )
 60								echo woocommerce_price( $fee->amount );
 61							else
 62								echo woocommerce_price( $fee->amount + $fee->tax );
 63						?></td>
 64					</tr>
 65
 66				<?php endforeach; ?>
 67
 68				<?php
 69					// Show the tax row if showing prices exclusive of tax only
 70					if ( $woocommerce->cart->tax_display_cart == 'excl' ) {
 71						$taxes = $woocommerce->cart->get_formatted_taxes();
 72
 73						if ( sizeof( $taxes ) > 0 ) {
 74
 75							$has_compound_tax = false;
 76
 77							foreach ( $taxes as $key => $tax ) {
 78								if ( $woocommerce->cart->tax->is_compound( $key ) ) {
 79									$has_compound_tax = true;
 80									continue;
 81								}
 82
 83								echo '<tr class="tax-rate tax-rate-' . $key . '">
 84									<th>' . $woocommerce->cart->tax->get_rate_label( $key ) . '</th>
 85									<td>' . $tax . '</td>
 86								</tr>';
 87							}
 88
 89							if ( $has_compound_tax ) {
 90
 91								echo '<tr class="order-subtotal">
 92									<th><strong>' . __( 'Subtotal', 'woocommerce' ) . '</strong></th>
 93									<td><strong>' . $woocommerce->cart->get_cart_subtotal( true ) . '</strong></td>
 94								</tr>';
 95							}
 96
 97							foreach ( $taxes as $key => $tax ) {
 98								if ( ! $woocommerce->cart->tax->is_compound( $key ) )
 99									continue;
100
101								echo '<tr class="tax-rate tax-rate-' . $key . '">
102									<th>' . $woocommerce->cart->tax->get_rate_label( $key ) . '</th>
103									<td>' . $tax . '</td>
104								</tr>';
105							}
106
107						} elseif ( $woocommerce->cart->get_cart_tax() > 0 ) {
108
109							echo '<tr class="tax">
110								<th>' . __( 'Tax', 'woocommerce' ) . '</th>
111								<td>' . $woocommerce->cart->get_cart_tax() . '</td>
112							</tr>';
113						}
114					}
115				?>
116
117				<?php if ( $woocommerce->cart->get_discounts_after_tax() ) : ?>
118
119					<tr class="discount">
120						<th><?php _e( 'Order Discount', 'woocommerce' ); ?> <a href="<?php echo add_query_arg( 'remove_discounts', '2', $woocommerce->cart->get_cart_url() ) ?>"><?php _e( '[Remove]', 'woocommerce' ); ?></a></th>
121						<td>-<?php echo $woocommerce->cart->get_discounts_after_tax(); ?></td>
122					</tr>
123
124				<?php endif; ?>
125
126				<?php do_action( 'woocommerce_cart_totals_before_order_total' ); ?>
127
128				<tr class="total">
129					<th><strong><?php _e( 'Order Total', 'woocommerce' ); ?></strong></th>
130					<td>
131						<strong><?php echo $woocommerce->cart->get_total(); ?></strong>
132						<?php
133							// If prices are tax inclusive, show taxes here
134							if (  $woocommerce->cart->tax_display_cart == 'incl' ) {
135								$tax_string_array = array();
136								$taxes = $woocommerce->cart->get_formatted_taxes();
137
138								if ( sizeof( $taxes ) > 0 )
139									foreach ( $taxes as $key => $tax )
140										$tax_string_array[] = sprintf( '%s %s', $tax, $woocommerce->cart->tax->get_rate_label( $key ) );
141								elseif ( $woocommerce->cart->get_cart_tax() )
142									$tax_string_array[] = sprintf( '%s tax', $tax );
143
144								if ( ! empty( $tax_string_array ) ) {
145									echo '<small class="includes_tax">' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) . '</small>';
146								}
147							}
148						?>
149					</td>
150				</tr>
151
152				<?php do_action( 'woocommerce_cart_totals_after_order_total' ); ?>
153
154			</tbody>
155		</table>
156
157		<?php if ( $woocommerce->cart->get_cart_tax() ) : ?>
158
159			<p><small><?php
160
161				$estimated_text = ( $woocommerce->customer->is_customer_outside_base() && ! $woocommerce->customer->has_calculated_shipping() ) ? sprintf( ' ' . __( ' (taxes estimated for %s)', 'woocommerce' ), $woocommerce->countries->estimated_for_prefix() . __( $woocommerce->countries->countries[ $woocommerce->countries->get_base_country() ], 'woocommerce' ) ) : '';
162
163				printf( __( 'Note: Shipping and taxes are estimated%s and will be updated during checkout based on your billing and shipping information.', 'woocommerce' ), $estimated_text );
164
165			?></small></p>
166
167		<?php endif; ?>
168
169	<?php elseif( $woocommerce->cart->needs_shipping() ) : ?>
170
171		<?php if ( ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) : ?>
172
173			<div class="woocommerce-info">
174
175				<p><?php _e( 'No shipping methods were found; please recalculate your shipping and enter your state/county and zip/postcode to ensure there are no other available methods for your location.', 'woocommerce' ); ?></p>
176
177			</div>
178
179		<?php else : ?>
180
181			<div class="woocommerce-error">
182
183				<p><?php printf( __( 'Sorry, it seems that there are no available shipping methods for your location (%s).', 'woocommerce' ), $woocommerce->countries->countries[ $woocommerce->customer->get_shipping_country() ] ); ?></p>
184
185				<p><?php _e( 'If you require assistance or wish to make alternate arrangements please contact us.', 'woocommerce' ); ?></p>
186
187			</div>
188
189		<?php endif; ?>
190
191	<?php endif; ?>
192
193	<?php do_action( 'woocommerce_after_cart_totals' ); ?>
194
195</div>