Advertisement
nshelper

Untitled

Sep 22nd, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  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.  
  20. defined( 'ABSPATH' ) || exit;
  21.  
  22. do_action( 'woocommerce_before_mini_cart' ); ?>
  23.  
  24. <?php if ( ! WC()->cart->is_empty() ) : ?>
  25.  
  26. <ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">
  27. <?php
  28. do_action( 'woocommerce_before_mini_cart_contents' );
  29.  
  30. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  31.  
  32. do_action( 'woocommerce/cart_loop/start', $cart_item );
  33.  
  34. $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
  35. $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
  36.  
  37. if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
  38. $product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
  39. $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
  40. $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
  41. $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
  42. ?>
  43. <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 ) ); ?>">
  44. <?php
  45. echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  46. 'woocommerce_cart_item_remove_link',
  47. sprintf(
  48. '<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>',
  49. esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
  50. esc_attr__( 'Remove this item', 'woocommerce' ),
  51. esc_attr( $product_id ),
  52. esc_attr( $cart_item_key ),
  53. esc_attr( $_product->get_sku() )
  54. ),
  55. $cart_item_key
  56. );
  57. ?>
  58. <?php if ( empty( $product_permalink ) ) : ?>
  59. <?php echo $thumbnail . wp_kses_post( $product_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
  60. <?php else : ?>
  61. <a href="<?php echo esc_url( $product_permalink ); ?>">
  62. <?php echo $thumbnail . wp_kses_post( $product_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
  63. </a>
  64. <?php endif; ?>
  65. <?php echo wc_get_formatted_cart_item_data( $cart_item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
  66. <?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 ?>
  67. </li>
  68. <?php
  69. }
  70.  
  71. do_action( 'woocommerce/cart_loop/end', $cart_item );
  72. }
  73.  
  74. do_action( 'woocommerce_mini_cart_contents' );
  75. ?>
  76. </ul>
  77.  
  78. <p class="woocommerce-mini-cart__total total">
  79. <?php
  80. /**
  81. * Hook: woocommerce_widget_shopping_cart_total.
  82. *
  83. * @hooked woocommerce_widget_shopping_cart_subtotal - 10
  84. */
  85. do_action( 'woocommerce_widget_shopping_cart_total' );
  86. ?>
  87. </p>
  88.  
  89. <?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
  90.  
  91. <p class="woocommerce-mini-cart__buttons buttons"><?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?></p>
  92.  
  93. <?php do_action( 'woocommerce_widget_shopping_cart_after_buttons' ); ?>
  94.  
  95. <?php else : ?>
  96.  
  97. <p class="woocommerce-mini-cart__empty-message"><?php esc_html_e( 'No products in the cart.', 'woocommerce' ); ?></p>
  98.  
  99. <?php endif; ?>
  100.  
  101. <?php do_action( 'woocommerce_after_mini_cart' ); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement