PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms 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
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Cart totals
  4. *
  5. * @author WooThemes
  6. * @package WooCommerce/Templates
  7. * @version 2.0.0
  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. <?php do_action( 'woocommerce_cart_totals_before_shipping' ); ?>
  31. <tr class="shipping">
  32. <th><?php _e( 'Shipping', 'woocommerce' ); ?></th>
  33. <td><?php woocommerce_get_template( 'cart/shipping-methods.php', array( 'available_methods' => $available_methods ) ); ?></td>
  34. </tr>
  35. <?php do_action( 'woocommerce_cart_totals_after_shipping' ); ?>
  36. <?php endif ?>
  37. <?php foreach ( $woocommerce->cart->get_fees() as $fee ) : ?>
  38. <tr class="fee fee-<?php echo $fee->id ?>">
  39. <th><?php echo $fee->name ?></th>
  40. <td><?php
  41. if ( $woocommerce->cart->tax_display_cart == 'excl' )
  42. echo woocommerce_price( $fee->amount );
  43. else
  44. echo woocommerce_price( $fee->amount + $fee->tax );
  45. ?></td>
  46. </tr>
  47. <?php endforeach; ?>
  48. <?php
  49. // Show the tax row if showing prices exclusive of tax only
  50. if ( $woocommerce->cart->tax_display_cart == 'excl' ) {
  51. $taxes = $woocommerce->cart->get_formatted_taxes();
  52. if ( sizeof( $taxes ) > 0 ) {
  53. $has_compound_tax = false;
  54. foreach ( $taxes as $key => $tax ) {
  55. if ( $woocommerce->cart->tax->is_compound( $key ) ) {
  56. $has_compound_tax = true;
  57. continue;
  58. }
  59. echo '<tr class="tax-rate tax-rate-' . $key . '">
  60. <th>' . $woocommerce->cart->tax->get_rate_label( $key ) . '</th>
  61. <td>' . $tax . '</td>
  62. </tr>';
  63. }
  64. if ( $has_compound_tax ) {
  65. echo '<tr class="order-subtotal">
  66. <th><strong>' . __( 'Subtotal', 'woocommerce' ) . '</strong></th>
  67. <td><strong>' . $woocommerce->cart->get_cart_subtotal( true ) . '</strong></td>
  68. </tr>';
  69. }
  70. foreach ( $taxes as $key => $tax ) {
  71. if ( ! $woocommerce->cart->tax->is_compound( $key ) )
  72. continue;
  73. echo '<tr class="tax-rate tax-rate-' . $key . '">
  74. <th>' . $woocommerce->cart->tax->get_rate_label( $key ) . '</th>
  75. <td>' . $tax . '</td>
  76. </tr>';
  77. }
  78. } elseif ( $woocommerce->cart->get_cart_tax() > 0 ) {
  79. echo '<tr class="tax">
  80. <th>' . __( 'Tax', 'woocommerce' ) . '</th>
  81. <td>' . $woocommerce->cart->get_cart_tax() . '</td>
  82. </tr>';
  83. }
  84. }
  85. ?>
  86. <?php if ( $woocommerce->cart->get_discounts_after_tax() ) : ?>
  87. <tr class="discount">
  88. <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>
  89. <td>-<?php echo $woocommerce->cart->get_discounts_after_tax(); ?></td>
  90. </tr>
  91. <?php endif; ?>
  92. <?php do_action( 'woocommerce_cart_totals_before_order_total' ); ?>
  93. <tr class="total">
  94. <th><strong><?php _e( 'Order Total', 'woocommerce' ); ?></strong></th>
  95. <td>
  96. <strong><?php echo $woocommerce->cart->get_total(); ?></strong>
  97. <?php
  98. // If prices are tax inclusive, show taxes here
  99. if ( $woocommerce->cart->tax_display_cart == 'incl' ) {
  100. $tax_string_array = array();
  101. $taxes = $woocommerce->cart->get_formatted_taxes();
  102. if ( sizeof( $taxes ) > 0 )
  103. foreach ( $taxes as $key => $tax )
  104. $tax_string_array[] = sprintf( '%s %s', $tax, $woocommerce->cart->tax->get_rate_label( $key ) );
  105. elseif ( $woocommerce->cart->get_cart_tax() )
  106. $tax_string_array[] = sprintf( '%s tax', $tax );
  107. if ( ! empty( $tax_string_array ) ) {
  108. echo '<small class="includes_tax">' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) . '</small>';
  109. }
  110. }
  111. ?>
  112. </td>
  113. </tr>
  114. <?php do_action( 'woocommerce_cart_totals_after_order_total' ); ?>
  115. </tbody>
  116. </table>
  117. <?php if ( $woocommerce->cart->get_cart_tax() ) : ?>
  118. <p><small><?php
  119. $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' ) ) : '';
  120. printf( __( 'Note: Shipping and taxes are estimated%s and will be updated during checkout based on your billing and shipping information.', 'woocommerce' ), $estimated_text );
  121. ?></small></p>
  122. <?php endif; ?>
  123. <?php elseif( $woocommerce->cart->needs_shipping() ) : ?>
  124. <?php if ( ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) : ?>
  125. <div class="woocommerce-info">
  126. <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>
  127. </div>
  128. <?php else : ?>
  129. <div class="woocommerce-error">
  130. <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>
  131. <p><?php _e( 'If you require assistance or wish to make alternate arrangements please contact us.', 'woocommerce' ); ?></p>
  132. </div>
  133. <?php endif; ?>
  134. <?php endif; ?>
  135. <?php do_action( 'woocommerce_after_cart_totals' ); ?>
  136. </div>