PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / lib / frontend / walker / class-quadmenu-item-cart.php

class-quadmenu-item-cart.php in QuadMenu – Mega Menu 3.3.8, at lib/frontend/walker/class-quadmenu-item-cart.php

134 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace QuadLayers\QuadMenu\Frontend\Walker;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7 use QuadLayers\QuadMenu\Frontend\Walker\QuadMenu_Item;
8
9 /**
10 * QuadMenuItemCart Class
11 */
12 class QuadMenu_Item_Cart extends QuadMenu_Item {
13
14 protected $type = 'cart';
15 public $count = 0;
16
17 function init() {
18
19 $this->item->url = '';
20 $this->args->has_title = false;
21
22 if ( empty( $this->item->title ) ) {
23 $this->item->title = esc_html__( 'Your cart', 'quadmenu' );
24 }
25
26 if ( function_exists( 'is_woocommerce' ) && ! is_cart() && ! is_checkout() ) {
27 $this->args->has_dropdown = $this->has_children = $this->args->has_caret = true;
28 }
29 }
30
31 function get_end_el() {
32 if ( ! class_exists( 'WooCommerce' ) ) {
33 return '';
34 }
35 }
36
37 function get_start_el() {
38
39 if ( ! class_exists( 'WooCommerce' ) ) {
40 return '';
41 }
42
43 $item_output = '';
44
45 $this->add_item_classes();
46
47 $this->add_item_classes_prefix();
48
49 $this->add_item_classes_quadmenu();
50
51 $this->add_item_classes_cart();
52
53 $id = $this->get_item_id();
54
55 $class = $this->get_item_classes();
56
57 $item_output .= '<li' . $id . $class . '>';
58
59 $this->add_link_atts();
60
61 $this->add_link_atts_toggle();
62
63 $this->add_link_atts_cart();
64
65 $item_output .= $this->get_link();
66
67 $item_output .= $this->get_dropdown_wrap_start();
68
69 $item_output .= $this->widget();
70
71 $item_output .= $this->get_dropdown_wrap_end();
72
73 return $item_output;
74 }
75
76 function add_item_classes_cart() {
77
78 $this->count = is_object( WC()->cart ) ? WC()->cart->get_cart_contents_count() : 0;
79
80 if ( empty( $this->count ) ) {
81 $this->item_classes[] = 'quadmenu-cart-empty';
82 } else {
83 $this->item->url = wc_get_cart_url();
84 }
85 }
86
87 function add_link_atts_cart() {
88
89 $this->item_atts['data-cart-url'] = wc_get_cart_url();
90
91 $this->item_atts['data-cart-qty'] = esc_attr( $this->count );
92
93 if ( ! empty( $this->args->navbar_animation_cart ) ) {
94 $this->item_atts['data-cart-animation'] = join( ' ', array_map( 'sanitize_html_class', (array) $this->args->navbar_animation_cart ) );
95 }
96 }
97
98 function get_icon() {
99 ob_start();
100 ?>
101 <span class="quadmenu-cart-magic">
102 <span class="quadmenu-icon <?php echo esc_attr( $this->item->icon ); ?><?php // echo esc_attr($this->item->animation->icon); ?>"></span>
103 <span class="quadmenu-cart-qty"><?php echo esc_html( $this->count ); ?></span>
104 </span>
105 <span class="quadmenu-cart-total"><?php echo is_object( WC()->cart ) ? WC()->cart->get_cart_total() : 0; ?></span>
106 <?php
107 return ob_get_clean();
108 }
109
110 function widget() {
111 ob_start();
112 ?>
113 <?php $this->get_cart_icon(); ?>
114 <?php the_widget( 'WC_Widget_Cart', 'title=' ); ?>
115 <?php $this->get_cart_text(); ?>
116 <?php
117 return ob_get_clean();
118 }
119
120 function get_cart_text() {
121 if ( ! empty( $this->item->cart_text ) ) {
122 ?>
123 <div class="quadmenu-bottom-text"><?php echo $this->item->cart_text; ?></div>
124 <?php
125 }
126 }
127
128 function get_cart_icon() {
129 ?>
130 <span class="quadmenu-empty-icon quadmenu-icon <?php echo esc_attr( $this->item->icon ); ?>"></span>
131 <?php
132 }
133 }
134