PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/templates/cart/totals.php

https://github.com/CammoKing/woocommerce
PHP | 202 lines | 134 code | 59 blank | 9 comment | 35 complexity | 6d52839c3faef1c1a4dadb0ee8d946d8 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Cart totals
  4. *
  5. * @author WooThemes
  6. * @package WooCommerce/Templates
  7. * @version 1.6.4
  8. */
  9. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  10. global $woocommerce;
  11. $available_methods = $woocommerce->shipping->get_available_shipping_methods();
  12. ?>
  13. <div class="cart_totals <?php if ( $woocommerce->customer->has_calculated_shipping() ) echo 'calculated_shipping'; ?>">
  14. <?php do_action( 'woocommerce_before_cart_totals' ); ?>
  15. <?php if ( ! $woocommerce->shipping->enabled || $available_methods || ! $woocommerce->customer->get_shipping_country() || ! $woocommerce->customer->has_calculated_shipping() ) : ?>
  16. <h2><?php _e( 'Cart Totals', 'woocommerce' ); ?></h2>
  17. <table cellspacing="0">
  18. <tbody>
  19. <tr class="cart-subtotal">
  20. <th><strong><?php _e( 'Cart Subtotal', 'woocommerce' ); ?></strong></th>
  21. <td><strong><?php echo $woocommerce->cart->get_cart_subtotal(); ?></strong></td>
  22. </tr>
  23. <?php if ( $woocommerce->cart->get_discounts_before_tax() ) : ?>
  24. <tr class="discount">
  25. <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>
  26. <td>-<?php echo $woocommerce->cart->get_discounts_before_tax(); ?></td>
  27. </tr>
  28. <?php endif; ?>
  29. <?php if ( $woocommerce->cart->needs_shipping() && $woocommerce->cart->show_shipping() && ( $available_methods || get_option( 'woocommerce_enable_shipping_calc' ) == 'yes' ) ) : ?>
  30. <tr class="shipping">
  31. <th><?php _e( 'Shipping', 'woocommerce' ); ?></th>
  32. <td><?php woocommerce_get_template( 'cart/shipping-methods.php', array( 'available_methods' => $available_methods ) ); ?></td>
  33. </tr>
  34. <?php endif ?>
  35. <?php foreach ( $woocommerce->cart->get_fees() as $fee ) : ?>
  36. <tr class="fee fee-<?php echo $fee->id ?>">
  37. <th><?php echo $fee->name ?></th>
  38. <td><?php
  39. if ( $woocommerce->cart->display_totals_ex_tax || ! $woocommerce->cart->prices_include_tax )
  40. echo woocommerce_price( $fee->amount );
  41. else
  42. echo woocommerce_price( $fee->amount + $fee->tax );
  43. ?></td>
  44. </tr>
  45. <?php endforeach; ?>
  46. <?php
  47. // Show the tax row if showing prices exclusive of tax only
  48. if ( $woocommerce->cart->display_totals_ex_tax || ! $woocommerce->cart->prices_include_tax ) {
  49. if ( $woocommerce->cart->get_cart_tax() ) {
  50. $taxes = $woocommerce->cart->get_formatted_taxes();
  51. if ( sizeof( $taxes ) > 0 ) {
  52. $has_compound_tax = false;
  53. foreach ( $taxes as $key => $tax ) {
  54. if ( $woocommerce->cart->tax->is_compound( $key ) ) {
  55. $has_compound_tax = true;
  56. continue;
  57. }
  58. echo '<tr class="tax-rate tax-rate-' . $key . '">
  59. <th>' . $woocommerce->cart->tax->get_rate_label( $key ) . '</th>
  60. <td>' . $tax . '</td>
  61. </tr>';
  62. }
  63. if ( $has_compound_tax ) {
  64. echo '<tr class="order-subtotal">
  65. <th><strong>' . __( 'Subtotal', 'woocommerce' ) . '</strong></th>
  66. <td><strong>' . $woocommerce->cart->get_cart_subtotal( true ) . '</strong></td>
  67. </tr>';
  68. }
  69. foreach ( $taxes as $key => $tax ) {
  70. if ( ! $woocommerce->cart->tax->is_compound( $key ) )
  71. continue;
  72. echo '<tr class="tax-rate tax-rate-' . $key . '">
  73. <th>' . $woocommerce->cart->tax->get_rate_label( $key ) . '</th>
  74. <td>' . $tax . '</td>
  75. </tr>';
  76. }
  77. } else {
  78. echo '<tr class="tax">
  79. <th>' . __( 'Tax', 'woocommerce' ) . '</th>
  80. <td>' . $woocommerce->cart->get_cart_tax() . '</td>
  81. </tr>';
  82. }
  83. } elseif ( get_option( 'woocommerce_display_cart_taxes_if_zero' ) == 'yes' ) {
  84. echo '<tr class="tax">
  85. <th>' . __( 'Tax', 'woocommerce' ) . '</th>
  86. <td>' . __x( 'N/A', 'Relating to tax', 'woocommerce' ) . '</td>
  87. </tr>';
  88. }
  89. }
  90. ?>
  91. <?php if ( $woocommerce->cart->get_discounts_after_tax() ) : ?>
  92. <tr class="discount">
  93. <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>
  94. <td>-<?php echo $woocommerce->cart->get_discounts_after_tax(); ?></td>
  95. </tr>
  96. <?php endif; ?>
  97. <tr class="total">
  98. <th><strong><?php _e( 'Order Total', 'woocommerce' ); ?></strong></th>
  99. <td>
  100. <strong><?php echo $woocommerce->cart->get_total(); ?></strong>
  101. <?php
  102. // If prices are tax inclusive, show taxes here
  103. if ( ! $woocommerce->cart->display_totals_ex_tax && $woocommerce->cart->prices_include_tax ) {
  104. if ( $woocommerce->cart->get_cart_tax() ) {
  105. $tax_string_array = array();
  106. $taxes = $woocommerce->cart->get_formatted_taxes();
  107. if ( sizeof( $taxes ) > 0 )
  108. foreach ( $taxes as $key => $tax )
  109. $tax_string_array[] = sprintf( '%s %s', $tax, $woocommerce->cart->tax->get_rate_label( $key ) );
  110. else
  111. $tax_string_array[] = sprintf( '%s tax', $tax );
  112. if ( ! empty( $tax_string_array ) ) {
  113. echo '<small class="includes_tax">' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) . '</small>';
  114. }
  115. } elseif ( get_option( 'woocommerce_display_cart_taxes_if_zero' ) == 'yes' ) {
  116. echo '<small class="includes_tax">' . sprintf( __( '(Includes %s tax)', 'woocommerce' ), woocommerce_price( 0 ) ) . '</small>';
  117. }
  118. }
  119. ?>
  120. </td>
  121. </tr>
  122. </tbody>
  123. </table>
  124. <?php if ( $woocommerce->cart->get_cart_tax() ) : ?>
  125. <p><small><?php
  126. $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' ) ) : '';
  127. printf( __( 'Note: Shipping and taxes are estimated%s and will be updated during checkout based on your billing and shipping information.', 'woocommerce' ), $estimated_text );
  128. ?></small></p>
  129. <?php endif; ?>
  130. <?php elseif( $woocommerce->cart->needs_shipping() ) : ?>
  131. <?php if ( ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) : ?>
  132. <div class="woocommerce_info">
  133. <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>
  134. </div>
  135. <?php else : ?>
  136. <div class="woocommerce_error">
  137. <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>
  138. <p><?php _e( 'If you require assistance or wish to make alternate arrangements please contact us.', 'woocommerce' ); ?></p>
  139. </div>
  140. <?php endif; ?>
  141. <?php endif; ?>
  142. <?php do_action( 'woocommerce_after_cart_totals' ); ?>
  143. </div>