cart.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * Cart Page
  4. *
  5. * This template can be overridden by copying it to yourtheme/woocommerce/cart/cart.php.
  6. *
  7. * HOWEVER, on occasion WooCommerce will need to update template files and you
  8. * (the theme developer) will need to copy the new files to your theme to
  9. * maintain compatibility. We try to do this as little as possible, but it does
  10. * happen. When this occurs the version of the template file will be bumped and
  11. * the readme will list any important changes.
  12. *
  13. * @see https://docs.woocommerce.com/document/template-structure/
  14. * @package WooCommerce/Templates
  15. * @version 3.4.0
  16. */
  17. defined( 'ABSPATH' ) || exit;
  18. wc_print_notices();
  19. do_action( 'woocommerce_before_cart' ); ?>
  20. <form class="woocommerce-cart-form" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">
  21. <?php do_action( 'woocommerce_before_cart_table' ); ?>
  22. <table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents" cellspacing="0">
  23. <thead>
  24. <tr>
  25. <th class="product-remove">&nbsp;</th>
  26. <th class="product-thumbnail">&nbsp;</th>
  27. <th class="product-name"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th>
  28. <th class="product-price"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th>
  29. <th class="product-quantity"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></th>
  30. <th class="product-subtotal"><?php esc_html_e( 'Total', 'woocommerce' ); ?></th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. <?php do_action( 'woocommerce_before_cart_contents' ); ?>
  35. <?php
  36. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  37. $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
  38. $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
  39. if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
  40. $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
  41. ?>
  42. <tr class="woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>">
  43. <td class="product-remove">
  44. <?php
  45. // @codingStandardsIgnoreLine
  46. echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
  47. '<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">&times;</a>',
  48. esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
  49. __( 'Remove this item', 'woocommerce' ),
  50. esc_attr( $product_id ),
  51. esc_attr( $_product->get_sku() )
  52. ), $cart_item_key );
  53. ?>
  54. </td>
  55. <td class="product-thumbnail">
  56. <?php
  57. $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
  58. if ( ! $product_permalink ) {
  59. echo wp_kses_post( $thumbnail );
  60. } else {
  61. printf( '<a href="%s">%s</a>', esc_url( $product_permalink ), wp_kses_post( $thumbnail ) );
  62. }
  63. ?>
  64. </td>
  65. <td class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>">
  66. <?php
  67. if ( ! $product_permalink ) {
  68. echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . '&nbsp;' );
  69. } else {
  70. echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) );
  71. }
  72. do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key );
  73. // Meta data.
  74. echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok.
  75. // Backorder notification.
  76. if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
  77. echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>' ) );
  78. }
  79. ?>
  80. </td>
  81. <td class="product-price" data-title="<?php esc_attr_e( 'Price', 'woocommerce' ); ?>">
  82. <?php
  83. echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); // PHPCS: XSS ok.
  84. ?>
  85. </td>
  86. <td class="product-quantity" data-title="<?php esc_attr_e( 'Quantity', 'woocommerce' ); ?>">
  87. <?php
  88. if ( $_product->is_sold_individually() ) {
  89. $product_quantity = sprintf( '1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key );
  90. } else {
  91. $product_quantity = woocommerce_quantity_input( array(
  92. 'input_name' => "cart[{$cart_item_key}][qty]",
  93. 'input_value' => $cart_item['quantity'],
  94. 'max_value' => $_product->get_max_purchase_quantity(),
  95. 'min_value' => '0',
  96. 'product_name' => $_product->get_name(),
  97. ), $_product, false );
  98. }
  99. echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item ); // PHPCS: XSS ok.
  100. ?>
  101. </td>
  102. <td class="product-subtotal" data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>">
  103. <?php
  104. echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); // PHPCS: XSS ok.
  105. ?>
  106. </td>
  107. </tr>
  108. <?php
  109. }
  110. }
  111. ?>
  112. <?php do_action( 'woocommerce_cart_contents' ); ?>
  113. <tr>
  114. <td colspan="6" class="actions">
  115. <?php if ( wc_coupons_enabled() ) { ?>
  116. <div class="coupon">
  117. <label for="coupon_code"><?php esc_html_e( 'Coupon:', 'woocommerce' ); ?></label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" /> <button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?></button>
  118. <?php do_action( 'woocommerce_cart_coupon' ); ?>
  119. </div>
  120. <?php } ?>
  121. <button type="submit" class="button" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'woocommerce' ); ?>"><?php esc_html_e( 'Update cart', 'woocommerce' ); ?></button>
  122. <?php do_action( 'woocommerce_cart_actions' ); ?>
  123. <?php wp_nonce_field( 'woocommerce-cart', 'woocommerce-cart-nonce' ); ?>
  124. </td>
  125. </tr>
  126. <?php do_action( 'woocommerce_after_cart_contents' ); ?>
  127. </tbody>
  128. </table>
  129. <?php do_action( 'woocommerce_after_cart_table' ); ?>
  130. </form>
  131. <div class="cart-collaterals">
  132. <?php
  133. /**
  134. * Cart collaterals hook.
  135. *
  136. * @hooked woocommerce_cross_sell_display
  137. * @hooked woocommerce_cart_totals - 10
  138. */
  139. do_action( 'woocommerce_cart_collaterals' );
  140. ?>
  141. </div>
  142. <?php do_action( 'woocommerce_after_cart' ); ?>