/templates/cart/mini-cart.php

  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 2.5.0 
  19. */ 
  20.  
  21. if ( ! defined( 'ABSPATH' ) ) { 
  22. exit; // Exit if accessed directly 
  23.  
  24. ?> 
  25.  
  26. <?php do_action( 'woocommerce_before_mini_cart' ); ?> 
  27.  
  28. <ul class="cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>"> 
  29.  
  30. <?php if ( ! WC()->cart->is_empty() ) : ?> 
  31.  
  32. <?php do_action( 'woocommerce_before_mini_cart_contents' ); ?> 
  33.  
  34. <?php 
  35. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { 
  36. $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); 
  37. $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); 
  38.  
  39. if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) { 
  40. $product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ); 
  41. $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); 
  42. $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); 
  43. $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key ); 
  44. ?> 
  45. <li class="<?php echo esc_attr( apply_filters( 'woocommerce_mini_cart_item_class', 'mini_cart_item', $cart_item, $cart_item_key ) ); ?>"> 
  46. <?php 
  47. echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( 
  48. '<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>',  
  49. esc_url( WC()->cart->get_remove_url( $cart_item_key ) ),  
  50. __( 'Remove this item', 'woocommerce' ),  
  51. esc_attr( $product_id ),  
  52. esc_attr( $_product->get_sku() ) 
  53. ), $cart_item_key ); 
  54. ?> 
  55. <?php if ( ! $_product->is_visible() ) : ?> 
  56. <?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . $product_name . ' '; ?> 
  57. <?php else : ?> 
  58. <a href="<?php echo esc_url( $product_permalink ); ?>"> 
  59. <?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . $product_name . ' '; ?> 
  60. </a> 
  61. <?php endif; ?> 
  62. <?php echo WC()->cart->get_item_data( $cart_item ); ?> 
  63.  
  64. <?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?> 
  65. </li> 
  66. <?php 
  67. ?> 
  68.  
  69. <?php do_action( 'woocommerce_mini_cart_contents' ); ?> 
  70.  
  71. <?php else : ?> 
  72.  
  73. <li class="empty"><?php _e( 'No products in the cart.', 'woocommerce' ); ?></li> 
  74.  
  75. <?php endif; ?> 
  76.  
  77. </ul><!-- end product list --> 
  78.  
  79. <?php if ( ! WC()->cart->is_empty() ) : ?> 
  80.  
  81. <p class="total"><strong><?php _e( 'Subtotal', 'woocommerce' ); ?>:</strong> <?php echo WC()->cart->get_cart_subtotal(); ?></p> 
  82.  
  83. <?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?> 
  84.  
  85. <p class="buttons"> 
  86. <?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?> 
  87. </p> 
  88.  
  89. <?php endif; ?> 
  90.  
  91. <?php do_action( 'woocommerce_after_mini_cart' ); ?> 
.