mini-cart.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Mini-cart
  4. *
  5. * Contains the markup for the mini-cart, used by the cart widget.
  6. *
  7. * This template can be overridden by copying it to yourtheme/woocommerce/cart/mini-cart.php.
  8. *
  9. * HOWEVER, on occasion WooCommerce will need to update template files and you
  10. * (the theme developer) will need to copy the new files to your theme to
  11. * maintain compatibility. We try to do this as little as possible, but it does
  12. * happen. When this occurs the version of the template file will be bumped and
  13. * the readme will list any important changes.
  14. *
  15. * @see https://docs.woocommerce.com/document/template-structure/
  16. * @author WooThemes
  17. * @package WooCommerce/Templates
  18. * @version 3.3.0
  19. */
  20. if ( ! defined( 'ABSPATH' ) ) {
  21. exit;
  22. }
  23. do_action( 'woocommerce_before_mini_cart' ); ?>
  24. <?php if ( ! WC()->cart->is_empty() ) : ?>
  25. <ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">
  26. <?php
  27. do_action( 'woocommerce_before_mini_cart_contents' );
  28. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  29. $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
  30. $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
  31. if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
  32. $product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
  33. $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
  34. $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
  35. $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
  36. ?>
  37. <li class="woocommerce-mini-cart-item <?php echo esc_attr( apply_filters( 'woocommerce_mini_cart_item_class', 'mini_cart_item', $cart_item, $cart_item_key ) ); ?>">
  38. <?php
  39. echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
  40. '<a href="%s" class="remove remove_from_cart_button" aria-label="%s" data-product_id="%s" data-cart_item_key="%s" data-product_sku="%s">&times;</a>',
  41. esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
  42. __( 'Remove this item', 'woocommerce' ),
  43. esc_attr( $product_id ),
  44. esc_attr( $cart_item_key ),
  45. esc_attr( $_product->get_sku() )
  46. ), $cart_item_key );
  47. ?>
  48. <?php if ( empty( $product_permalink ) ) : ?>
  49. <?php echo $thumbnail . $product_name . '&nbsp;'; ?>
  50. <?php else : ?>
  51. <a href="<?php echo esc_url( $product_permalink ); ?>">
  52. <?php echo $thumbnail . $product_name . '&nbsp;'; ?>
  53. </a>
  54. <?php endif; ?>
  55. <?php echo wc_get_formatted_cart_item_data( $cart_item ); ?>
  56. <?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s &times; %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>
  57. </li>
  58. <?php
  59. }
  60. }
  61. do_action( 'woocommerce_mini_cart_contents' );
  62. ?>
  63. </ul>
  64. <p class="woocommerce-mini-cart__total total"><strong><?php _e( 'Subtotal', 'woocommerce' ); ?>:</strong> <?php echo WC()->cart->get_cart_subtotal(); ?></p>
  65. <?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
  66. <p class="woocommerce-mini-cart__buttons buttons"><?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?></p>
  67. <?php else : ?>
  68. <p class="woocommerce-mini-cart__empty-message"><?php _e( 'No products in the cart.', 'woocommerce' ); ?></p>
  69. <?php endif; ?>
  70. <?php do_action( 'woocommerce_after_mini_cart' ); ?>