cart-empty.php
2 years ago
cart-item-data.php
2 years ago
cart-shipping.php
2 years ago
cart-totals.php
2 years ago
cart.php
2 months ago
cross-sells.php
1 year ago
mini-cart.php
1 year ago
proceed-to-checkout-button.php
2 years ago
shipping-calculator.php
1 year ago
cart.php
219 lines
| 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://woocommerce.com/document/template-structure/ |
| 14 | * @package WooCommerce\Templates |
| 15 | * @version 10.8.0 |
| 16 | */ |
| 17 | |
| 18 | defined( 'ABSPATH' ) || exit; |
| 19 | |
| 20 | do_action( 'woocommerce_before_cart' ); ?> |
| 21 | |
| 22 | <form class="woocommerce-cart-form" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post"> |
| 23 | <?php do_action( 'woocommerce_before_cart_table' ); ?> |
| 24 | |
| 25 | <table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents" cellspacing="0"> |
| 26 | <thead> |
| 27 | <tr> |
| 28 | <th class="product-remove"><span class="screen-reader-text"><?php esc_html_e( 'Remove item', 'woocommerce' ); ?></span></th> |
| 29 | <th class="product-thumbnail"><span class="screen-reader-text"><?php esc_html_e( 'Thumbnail image', 'woocommerce' ); ?></span></th> |
| 30 | <th scope="col" class="product-name"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th> |
| 31 | <th scope="col" class="product-price"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th> |
| 32 | <th scope="col" class="product-quantity"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></th> |
| 33 | <th scope="col" class="product-subtotal"><?php esc_html_e( 'Subtotal', 'woocommerce' ); ?></th> |
| 34 | </tr> |
| 35 | </thead> |
| 36 | <tbody> |
| 37 | <?php do_action( 'woocommerce_before_cart_contents' ); ?> |
| 38 | |
| 39 | <?php |
| 40 | foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 41 | $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
| 42 | $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); |
| 43 | |
| 44 | /** |
| 45 | * Filter whether this cart item is visible in the cart. |
| 46 | * |
| 47 | * @since 2.1.0 |
| 48 | * @param bool $visible Whether the cart item is visible. Default true. |
| 49 | * @param array $cart_item The cart item data. |
| 50 | * @param string $cart_item_key The cart item key. |
| 51 | */ |
| 52 | $visible = apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ); |
| 53 | |
| 54 | if ( $_product instanceof WC_Product && $_product->exists() && $cart_item['quantity'] > 0 && $visible ) { |
| 55 | /** |
| 56 | * Filter the product name. |
| 57 | * |
| 58 | * @since 2.1.0 |
| 59 | * @param string $product_name Name of the product in the cart. |
| 60 | * @param array $cart_item The product in the cart. |
| 61 | * @param string $cart_item_key Key for the product in the cart. |
| 62 | */ |
| 63 | $product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ); |
| 64 | $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key ); |
| 65 | ?> |
| 66 | <tr class="woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> |
| 67 | |
| 68 | <td class="product-remove"> |
| 69 | <?php |
| 70 | echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 71 | 'woocommerce_cart_item_remove_link', |
| 72 | sprintf( |
| 73 | '<a role="button" href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>', |
| 74 | esc_url( wc_get_cart_remove_url( $cart_item_key ) ), |
| 75 | /* translators: %s is the product name */ |
| 76 | esc_attr( sprintf( __( 'Remove %s from cart', 'woocommerce' ), wp_strip_all_tags( $product_name ) ) ), |
| 77 | esc_attr( $product_id ), |
| 78 | esc_attr( $_product->get_sku() ) |
| 79 | ), |
| 80 | $cart_item_key |
| 81 | ); |
| 82 | ?> |
| 83 | </td> |
| 84 | |
| 85 | <td class="product-thumbnail"> |
| 86 | <?php |
| 87 | /** |
| 88 | * Filter the product thumbnail displayed in the WooCommerce cart. |
| 89 | * |
| 90 | * This filter allows developers to customize the HTML output of the product |
| 91 | * thumbnail. It passes the product image along with cart item data |
| 92 | * for potential modifications before being displayed in the cart. |
| 93 | * |
| 94 | * @param string $thumbnail The HTML for the product image. |
| 95 | * @param array $cart_item The cart item data. |
| 96 | * @param string $cart_item_key Unique key for the cart item. |
| 97 | * |
| 98 | * @since 2.1.0 |
| 99 | */ |
| 100 | $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); |
| 101 | |
| 102 | if ( ! $product_permalink ) { |
| 103 | echo $thumbnail; // PHPCS: XSS ok. |
| 104 | } else { |
| 105 | printf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $thumbnail ); // PHPCS: XSS ok. |
| 106 | } |
| 107 | ?> |
| 108 | </td> |
| 109 | |
| 110 | <td scope="row" role="rowheader" class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>"> |
| 111 | <?php |
| 112 | if ( ! $product_permalink ) { |
| 113 | echo wp_kses_post( $product_name . ' ' ); |
| 114 | } else { |
| 115 | /** |
| 116 | * This filter is documented above. |
| 117 | * |
| 118 | * @since 2.1.0 |
| 119 | */ |
| 120 | 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 ) ); |
| 121 | } |
| 122 | |
| 123 | do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key ); |
| 124 | |
| 125 | // Meta data. |
| 126 | echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok. |
| 127 | |
| 128 | // Backorder notification. |
| 129 | if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) { |
| 130 | echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>', $product_id ) ); |
| 131 | } |
| 132 | ?> |
| 133 | </td> |
| 134 | |
| 135 | <td class="product-price" data-title="<?php esc_attr_e( 'Price', 'woocommerce' ); ?>"> |
| 136 | <?php |
| 137 | echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); // PHPCS: XSS ok. |
| 138 | ?> |
| 139 | </td> |
| 140 | |
| 141 | <td class="product-quantity" data-title="<?php esc_attr_e( 'Quantity', 'woocommerce' ); ?>"> |
| 142 | <?php |
| 143 | if ( $_product->is_sold_individually() ) { |
| 144 | $min_quantity = 1; |
| 145 | $max_quantity = 1; |
| 146 | } else { |
| 147 | $min_quantity = 0; |
| 148 | $max_quantity = $_product->get_max_purchase_quantity(); |
| 149 | } |
| 150 | |
| 151 | $product_quantity = woocommerce_quantity_input( |
| 152 | array( |
| 153 | 'input_name' => "cart[{$cart_item_key}][qty]", |
| 154 | 'input_value' => $cart_item['quantity'], |
| 155 | 'max_value' => $max_quantity, |
| 156 | 'min_value' => $min_quantity, |
| 157 | 'product_name' => $product_name, |
| 158 | ), |
| 159 | $_product, |
| 160 | false |
| 161 | ); |
| 162 | |
| 163 | echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item ); // PHPCS: XSS ok. |
| 164 | ?> |
| 165 | </td> |
| 166 | |
| 167 | <td class="product-subtotal" data-title="<?php esc_attr_e( 'Subtotal', 'woocommerce' ); ?>"> |
| 168 | <?php |
| 169 | echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); // PHPCS: XSS ok. |
| 170 | ?> |
| 171 | </td> |
| 172 | </tr> |
| 173 | <?php |
| 174 | } |
| 175 | } |
| 176 | ?> |
| 177 | |
| 178 | <?php do_action( 'woocommerce_cart_contents' ); ?> |
| 179 | |
| 180 | <tr> |
| 181 | <td colspan="6" class="actions"> |
| 182 | |
| 183 | <?php if ( wc_coupons_enabled() ) { ?> |
| 184 | <div class="coupon"> |
| 185 | <label for="coupon_code" class="screen-reader-text"><?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<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_html_e( 'Apply coupon', 'woocommerce' ); ?></button> |
| 186 | <?php do_action( 'woocommerce_cart_coupon' ); ?> |
| 187 | </div> |
| 188 | <?php } ?> |
| 189 | |
| 190 | <button type="submit" class="button<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'woocommerce' ); ?>"><?php esc_html_e( 'Update cart', 'woocommerce' ); ?></button> |
| 191 | |
| 192 | <?php do_action( 'woocommerce_cart_actions' ); ?> |
| 193 | |
| 194 | <?php wp_nonce_field( 'woocommerce-cart', 'woocommerce-cart-nonce' ); ?> |
| 195 | </td> |
| 196 | </tr> |
| 197 | |
| 198 | <?php do_action( 'woocommerce_after_cart_contents' ); ?> |
| 199 | </tbody> |
| 200 | </table> |
| 201 | <?php do_action( 'woocommerce_after_cart_table' ); ?> |
| 202 | </form> |
| 203 | |
| 204 | <?php do_action( 'woocommerce_before_cart_collaterals' ); ?> |
| 205 | |
| 206 | <div class="cart-collaterals"> |
| 207 | <?php |
| 208 | /** |
| 209 | * Cart collaterals hook. |
| 210 | * |
| 211 | * @hooked woocommerce_cross_sell_display |
| 212 | * @hooked woocommerce_cart_totals - 10 |
| 213 | */ |
| 214 | do_action( 'woocommerce_cart_collaterals' ); |
| 215 | ?> |
| 216 | </div> |
| 217 | |
| 218 | <?php do_action( 'woocommerce_after_cart' ); ?> |
| 219 |