Нет описания

mini-cart.php 4.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * @package WooCommerce\Templates
  17. * @version 5.2.0
  18. */
  19. defined( 'ABSPATH' ) || exit;
  20. do_action( 'woocommerce_before_mini_cart' ); ?>
  21. <?php if ( ! WC()->cart->is_empty() ) : ?>
  22. <ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">
  23. <?php
  24. do_action( 'woocommerce_before_mini_cart_contents' );
  25. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  26. $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
  27. $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
  28. if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
  29. $product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
  30. $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
  31. $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
  32. $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
  33. ?>
  34. <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 ) ); ?>">
  35. <?php
  36. echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  37. 'woocommerce_cart_item_remove_link',
  38. sprintf(
  39. '<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>',
  40. esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
  41. esc_attr__( 'Remove this item', 'woocommerce' ),
  42. esc_attr( $product_id ),
  43. esc_attr( $cart_item_key ),
  44. esc_attr( $_product->get_sku() )
  45. ),
  46. $cart_item_key
  47. );
  48. ?>
  49. <?php if ( empty( $product_permalink ) ) : ?>
  50. <?php echo $thumbnail . wp_kses_post( $product_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
  51. <?php else : ?>
  52. <a href="<?php echo esc_url( $product_permalink ); ?>">
  53. <?php echo $thumbnail . wp_kses_post( $product_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
  54. </a>
  55. <?php endif; ?>
  56. <?php echo wc_get_formatted_cart_item_data( $cart_item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
  57. <?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 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
  58. </li>
  59. <?php
  60. }
  61. }
  62. do_action( 'woocommerce_mini_cart_contents' );
  63. ?>
  64. </ul>
  65. <p class="woocommerce-mini-cart__total total">
  66. <?php
  67. /**
  68. * Hook: woocommerce_widget_shopping_cart_total.
  69. *
  70. * @hooked woocommerce_widget_shopping_cart_subtotal - 10
  71. */
  72. do_action( 'woocommerce_widget_shopping_cart_total' );
  73. ?>
  74. </p>
  75. <?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
  76. <p class="woocommerce-mini-cart__buttons buttons"><?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?></p>
  77. <?php do_action( 'woocommerce_widget_shopping_cart_after_buttons' ); ?>
  78. <?php else : ?>
  79. <p class="woocommerce-mini-cart__empty-message"><?php esc_html_e( 'No products in the cart.', 'woocommerce' ); ?></p>
  80. <?php endif; ?>
  81. <?php do_action( 'woocommerce_after_mini_cart' ); ?>