Advertisement
nshelper

Untitled

Jan 10th, 2025
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 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 7.9.0
  18. */
  19.  
  20. defined( 'ABSPATH' ) || exit;
  21.  
  22. $items_to_show = apply_filters( 'woodmart_mini_cart_items_to_show', 30 );
  23.  
  24. do_action( 'woocommerce_before_mini_cart' ); ?>
  25.  
  26. <div class="shopping-cart-widget-body wd-scroll">
  27. <div class="wd-scroll-content">
  28.  
  29. <?php if ( ! WC()->cart->is_empty() ) : ?>
  30.  
  31. <ul class="cart_list product_list_widget woocommerce-mini-cart <?php echo esc_attr( $args['list_class'] ); ?>">
  32.  
  33. <?php
  34. do_action( 'woocommerce_before_mini_cart_contents' );
  35.  
  36. $_i = 0;
  37. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  38. do_action( 'woocommerce/cart_loop/start', $cart_item );
  39. $_i++;
  40. if( $_i > $items_to_show ) break;
  41.  
  42. $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
  43. $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
  44.  
  45. if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
  46. /**
  47. * This filter is documented in woocommerce/templates/cart/cart.php.
  48. *
  49. * @param string $product_name Name of the product in the cart.
  50. */
  51. $product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
  52.  
  53. $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
  54. $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
  55. ?>
  56. <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 ) ); ?>" data-key="<?php echo esc_attr( $cart_item_key ); ?>">
  57. <a href="<?php echo esc_url( $product_permalink ); ?>" class="cart-item-link wd-fill"><?php esc_html_e('Show', 'woocommerce'); ?></a>
  58. <?php
  59. echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
  60. '<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>',
  61. esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
  62. /* translators: %s is the product name */
  63. esc_attr( sprintf( __( 'Remove %s from cart', 'woocommerce' ), wp_strip_all_tags( $product_name ) ) ),
  64. esc_attr( $product_id ),
  65. esc_attr( $cart_item_key ),
  66. esc_attr( $_product->get_sku() )
  67. ), $cart_item_key );
  68. ?>
  69. <?php if ( empty( $product_permalink ) ) : ?>
  70. <?php echo apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); ?>
  71. <?php else : ?>
  72. <a href="<?php echo esc_url( $product_permalink ); ?>" class="cart-item-image">
  73. <?php echo apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); ?>
  74. </a>
  75. <?php endif; ?>
  76.  
  77. <div class="cart-info">
  78. <span class="wd-entities-title">
  79. <?php echo $product_name; ?>
  80. </span>
  81. <?php if ( woodmart_get_opt( 'show_sku_in_mini_cart' ) ) : ?>
  82. <div class="wd-product-sku">
  83. <span class="wd-label">
  84. <?php esc_html_e( 'SKU:', 'woodmart' ); ?>
  85. </span>
  86. <span>
  87. <?php if ( $_product->get_sku() ) : ?>
  88. <?php echo esc_html( $_product->get_sku() ); ?>
  89. <?php else : ?>
  90. <?php esc_html_e( 'N/A', 'woocommerce' ); ?>
  91. <?php endif; ?>
  92. </span>
  93. </div>
  94. <?php endif; ?>
  95. <?php
  96. echo wc_get_formatted_cart_item_data( $cart_item );
  97. ?>
  98.  
  99. <?php
  100. if ( ! $_product->is_sold_individually() && $_product->is_purchasable() && woodmart_get_opt( 'mini_cart_quantity' ) && apply_filters( 'woodmart_show_widget_cart_item_quantity', true, $cart_item_key ) ) {
  101. woocommerce_quantity_input(
  102. array(
  103. 'input_value' => $cart_item['quantity'],
  104. 'min_value' => 0,
  105. 'max_value' => $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(),
  106. ),
  107. $_product
  108. );
  109. }
  110. ?>
  111.  
  112. <?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 ); ?>
  113. </div>
  114.  
  115. </li>
  116. <?php
  117. }
  118. do_action( 'woocommerce/cart_loop/end', $cart_item );
  119. }
  120.  
  121. do_action( 'woocommerce_mini_cart_contents' );
  122.  
  123. ?>
  124. </ul><!-- end product list -->
  125.  
  126. <?php else : ?>
  127.  
  128. <div class="wd-empty-mini-cart">
  129. <p class="woocommerce-mini-cart__empty-message empty title"><?php esc_html_e( 'No products in the cart.', 'woocommerce' ); ?></p>
  130. <?php if ( wc_get_page_id( 'shop' ) > 0 ) : ?>
  131. <a class="btn btn-size-small btn-color-primary wc-backward" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>">
  132. <?php esc_html_e( 'Return To Shop', 'woodmart' ) ?>
  133. </a>
  134. <?php endif; ?>
  135. </div>
  136.  
  137. <?php endif; ?>
  138.  
  139. </div>
  140. </div>
  141.  
  142. <div class="shopping-cart-widget-footer<?php echo ( WC()->cart->is_empty() ? ' wd-cart-empty' : '' ); ?>">
  143. <?php if ( ! WC()->cart->is_empty() ) : ?>
  144.  
  145. <?php if ( function_exists( 'WC' ) && version_compare( WC()->version, '3.7.0', '<' ) ) : ?>
  146. <p class="woocommerce-mini-cart__total total"><strong><?php esc_html_e( 'Subtotal', 'woocommerce' ); ?>:</strong> <?php echo WC()->cart->get_cart_subtotal(); ?></p>
  147. <?php else : ?>
  148. <p class="woocommerce-mini-cart__total total">
  149. <?php
  150. /**
  151. * Woocommerce_widget_shopping_cart_total hook.
  152. *
  153. * @hooked woocommerce_widget_shopping_cart_subtotal - 10
  154. */
  155. do_action( 'woocommerce_widget_shopping_cart_total' );
  156. ?>
  157. </p>
  158. <?php endif; ?>
  159.  
  160. <?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
  161.  
  162. <p class="woocommerce-mini-cart__buttons buttons"><?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?></p>
  163.  
  164. <?php do_action( 'woocommerce_widget_shopping_cart_after_buttons' ); ?>
  165.  
  166. <?php endif; ?>
  167.  
  168. <?php do_action( 'woocommerce_after_mini_cart' ); ?>
  169. </div>
  170.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement