WooCommerce Menu Cart - Version 2.7.7

Version Description

  • Fix: include default classes when menu cart is the only item in the menu
  • Fix: cart existence check global usage only for old versions
  • Tested up to WooCommerce 3.9
Download this release

Release Info

Developer pomegranate
Plugin Icon 128x128 WooCommerce Menu Cart
Version 2.7.7
Comparing to
See all releases

Code changes from version 2.7.6 to 2.7.7

Files changed (2) hide show
  1. readme.txt +309 -304
  2. wp-menu-cart.php +618 -612
readme.txt CHANGED
@@ -1,305 +1,310 @@
1
- === WooCommerce Menu Cart ===
2
- Contributors: jprummer, pomegranate
3
- Donate link: https://www.wpovernight.com/
4
- Tags: woocommerce, menu, bar, cart, basket, header, shopping cart, navigation, edd, ecommerce, eshop, wp-ecommerce, jigoshop, wpec
5
- Requires at least: 3.4
6
- Tested up to: 5.3
7
- Requires PHP: 5.3
8
- Stable tag: 2.7.6
9
-
10
- Automatically displays a shopping cart in your menu bar. Works with WooCommerce, WP-Ecommerce, EDD, Eshop and Jigoshop
11
-
12
- == Description ==
13
-
14
- **Works with WooCommerce, WP-Ecommerce, EDD, Eshop and Jigoshop**
15
-
16
- This plugin installs a shopping cart button in the navigation bar. The plugin takes less than a minute to setup,
17
- and includes the following options:
18
-
19
- * Display cart icon, or only items/prices.
20
- * Display items only, price only, or both.
21
- * Display always, or only when there are items in the cart.
22
- * Float left, float right, or use your menu's default settings.
23
- * Customize your own CSS
24
-
25
- Pro Version Includes:
26
-
27
- * A choice of over 10 cart icons
28
- * A fully featured cart details flyout
29
- * Ability to add cart + flyout for unlimited menus
30
- * Ability to add a custom css class
31
- * Automatic updates on any great new features
32
- * Shortcode to display cart *anywhere* on your site
33
- * Quick and thorough support
34
-
35
- **Download the Pro version here - https://wpovernight.com/downloads/menu-cart-pro/**
36
-
37
- Finally, the cart automatically conforms to your site's styles, leaving you with no extra work.
38
-
39
- Compatibility:
40
-
41
- * WooCommerce
42
- * Easy Digital Downloads
43
- * Eshop
44
- * WP-Ecommerce
45
- * Jigoshop
46
-
47
- Translations:
48
-
49
- * Brazilian Portuguese
50
- * Danish
51
- * Dutch
52
- * Croatian
53
- * Czech
54
- * English
55
- * French
56
- * German
57
- * Greek
58
- * Hebrew
59
- * Hungarian
60
- * Italian
61
- * Norwegian
62
- * Persian
63
- * Polish
64
- * Portuguese
65
- * Russian
66
- * Spanish[1]
67
- * Swedish
68
- * Turkish
69
- * Vietnamese
70
-
71
- [1] WebHostingHub
72
- == Installation ==
73
-
74
- Delete any old installations of the plugin. Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
75
-
76
- Once the plugin is activated navigate to Settings > Menu Cart Setup. Select your options, save and you're ready to go. It's that easy!
77
-
78
- == Screenshots ==
79
-
80
- 1. Shows menu before and after Menu Cart.
81
- 2. 3 different display style options to choose from.
82
- 3. Shows settings page.
83
-
84
- == Frequently Asked Questions ==
85
-
86
- == Changelog ==
87
-
88
- = 2.7.6 =
89
- * Improved accessibility for screen readers (cart icon)
90
- * Tested up to WC3.8
91
- * Tested up to WP5.3
92
-
93
- = 2.7.5 =
94
- * Fix: check if woocommerce version constant is defined
95
- * Fix: Prevent fatal errors when switching eCommerce plugins
96
- * Fix: Persian translations
97
- * Fix: Notices when not using icon
98
- * Marked tested up to WC3.6
99
- * Marked tested up to WP5.2
100
-
101
- = 2.7.4 =
102
- * Tested up to WP5.1
103
-
104
- = 2.7.3 =
105
- * Fix: French plural forms rule (zero = single)
106
-
107
- = 2.7.2 =
108
- * Tested with WooCommerce 3.5
109
-
110
- = 2.7.1 =
111
-
112
- * fix label on price to display setting
113
- * Fix live updating cart for first product with 'Always display cart' setting enabled
114
-
115
- = 2.7.0 =
116
-
117
- * Feature: Full integration with wordpress.org language packs (finally!)
118
- * Feature (WooCommerce): Option to display either total (including fees) or subtotal (total of products)
119
- * Feature (EDD): Native integration with EDD AJAX
120
- * Fix: Several improvements & fixes to WooCommerce AJAX integration for sites with server side caching
121
- * Fix: Cart icon on settings page
122
- * Translations: added Turkish
123
-
124
- = 2.6.1 =
125
-
126
- * Feature: Option to hide theme cart from Storefront or Divi
127
- * Feature: Improved WooCommerce AJAX compatibility
128
- * Fix: Updated FontAwesome to 4.7.0
129
- * Tweak: load FontAwesome in separate CSS file to allow dequeueing
130
- * Translations: Updated pt_BR
131
-
132
- = 2.6.0 =
133
-
134
- * WooCommerce 3.0 compatibility
135
- * Translations: updated Swedish
136
-
137
- = 2.5.8 =
138
-
139
- * Translations: Added Croatian, Hebrew, Hungarian (updated) & Vietnamese
140
- * Fix: Built-in AJAX for multiple menus
141
- * Fix: Textdomain definition and allow custom translations
142
- * Tweak: prevent loading cart when WooCommerce not loaded
143
-
144
- = 2.5.7 =
145
-
146
- * Fix: Improved JS in Easy Digital Downloads
147
- * New: Hungarian translation
148
- * Tweak: Use css dash instead of hard-coded dash
149
-
150
- = 2.5.6 =
151
-
152
- * New: Slovak Translation
153
- * New: Option to use built in js
154
- * Tweak: Moved JS to footer
155
- * Tweak: improved css positioning
156
- * Tweak: added js selectors
157
- * Tweak: Brazilian Portuguese Translation
158
-
159
- = 2.5.5 =
160
-
161
- * New: Norwegian Translation
162
-
163
- = 2.5.4 =
164
-
165
- * New: Czech Translations
166
- * New: Greek Translations
167
- * Tweak: Seperated Item Classes
168
- * Tweak: Removed Unnecessary submenu classes
169
- * Tweak: Use get_total() instead of get_cart_total()
170
- * Fix: Prices show tax if cart prices are set to display including tax
171
- * Fix: Updated Font Awesome
172
-
173
- = 2.5.3 =
174
-
175
- * Fix: Ubermenu
176
- * Added: Greek Translation
177
-
178
- = 2.5.2 =
179
-
180
- *Tweak: Merged menu cart versions
181
-
182
- = 2.5.1 =
183
-
184
- * WPML String Translation fix
185
-
186
- = 2.5 =
187
-
188
- * Major Code refactor: CLEANER, FASTER, MORE FLEXIBLE!
189
- * Added: Shop detection for Multisite
190
- * Added: WPML String Translation setting
191
- * Added: Persian translations
192
- * Updated: Font Awesome
193
- * Updated: Spanish, Portugese, Brazilian, French & Polish Translations
194
- * Fix: PHP strict warnings
195
- * Fix: CSS for Twenty Twelve & Twenty Fourteen
196
-
197
- = 2.2.2 =
198
-
199
- * Jigoshop Bug Fix
200
-
201
- = 2.2.1 =
202
-
203
- * WPML bug fixes
204
-
205
- = 2.2.0 =
206
-
207
- * Several bugfixes & improvements
208
- * Better AJAX integration with EDD & eShop
209
- * Various filters added for better theme integration & easier customization
210
- * DOMHtml warnings surpressed
211
-
212
- = 2.1.5 =
213
-
214
- Fix: Edd and WP e-Commerce ajax.
215
-
216
- = 2.1.4 =
217
-
218
- Fixed WP e-Commerce ajax conflict and uploaded proper French translation.
219
-
220
- = 2.1.3 =
221
-
222
- EDD total price bug fixed
223
-
224
- = 2.1.2 =
225
-
226
- Added WP-Ecommerce and EDD
227
-
228
- = 2.1.0 =
229
-
230
- Initial Release
231
-
232
- == Upgrade Notice ==
233
-
234
- = 2.5.5 =
235
-
236
- * New: Norwegian Translation
237
-
238
- = 2.5.4 =
239
-
240
- * New: Czech Translations
241
- * New: Greek Translations
242
- * Tweak: Seperated Item Classes
243
- * Tweak: Removed Unnecessary submenu classes
244
- * Tweak: Use get_total() instead of get_cart_total()
245
- * Fix: Prices show tax if cart prices are set to display including tax
246
- * Fix: Updated Font Awesome
247
-
248
- = 2.5.3 =
249
-
250
- * Fix: Ubermenu
251
- * Added: Greek Translation
252
-
253
- = 2.5.2 =
254
-
255
- *Tweak: Merged menu cart versions
256
-
257
- = 2.5.1 =
258
-
259
- * WPML String Translation fix
260
-
261
- = 2.5 =
262
-
263
- * Major Code refactor: CLEANER, FASTER, MORE FLEXIBLE!
264
- * Added: Shop detection for Multisite
265
- * Added: WPML String Translation setting
266
- * Added: Persian translations
267
- * Updated: Font Awesome
268
- * Updated: Spanish, Portugese, Brazilian, French & Polish Translations
269
- * Fix: PHP strict warnings
270
- * Fix: CSS for Twenty Twelve & Twenty Fourteen
271
-
272
- = 2.2.2 =
273
-
274
- * Jigoshop Bug Fix
275
-
276
- = 2.2.1 =
277
-
278
- * WPML bug fixes
279
-
280
- = 2.2.0 =
281
-
282
- * Several bugfixes & improvements
283
- * Better AJAX integration with EDD & eShop
284
- * Various filters added for better theme integration & easier customization
285
- * DOMHtml warnings surpressed
286
-
287
- = 2.1.5 =
288
-
289
- Fix: Edd and WP e-Commerce ajax.
290
-
291
- = 2.1.4 =
292
-
293
- Fixed WP e-Commerce ajax conflict and uploaded proper French translation.
294
-
295
- = 2.1.3 =
296
-
297
- EDD total price bug fixed
298
-
299
- = 2.1.2 =
300
-
301
- Added WP-Ecommerce and EDD
302
-
303
- = 2.1.0 =
304
-
 
 
 
 
 
305
  Initial Release
1
+ === WooCommerce Menu Cart ===
2
+ Contributors: jprummer, pomegranate
3
+ Donate link: https://www.wpovernight.com/
4
+ Tags: woocommerce, menu, bar, cart, basket, header, shopping cart, navigation, edd, ecommerce, eshop, wp-ecommerce, jigoshop, wpec
5
+ Requires at least: 3.4
6
+ Tested up to: 5.3
7
+ Requires PHP: 5.3
8
+ Stable tag: 2.7.7
9
+
10
+ Automatically displays a shopping cart in your menu bar. Works with WooCommerce, WP-Ecommerce, EDD, Eshop and Jigoshop
11
+
12
+ == Description ==
13
+
14
+ **Works with WooCommerce, WP-Ecommerce, EDD, Eshop and Jigoshop**
15
+
16
+ This plugin installs a shopping cart button in the navigation bar. The plugin takes less than a minute to setup,
17
+ and includes the following options:
18
+
19
+ * Display cart icon, or only items/prices.
20
+ * Display items only, price only, or both.
21
+ * Display always, or only when there are items in the cart.
22
+ * Float left, float right, or use your menu's default settings.
23
+ * Customize your own CSS
24
+
25
+ Pro Version Includes:
26
+
27
+ * A choice of over 10 cart icons
28
+ * A fully featured cart details flyout
29
+ * Ability to add cart + flyout for unlimited menus
30
+ * Ability to add a custom css class
31
+ * Automatic updates on any great new features
32
+ * Shortcode to display cart *anywhere* on your site
33
+ * Quick and thorough support
34
+
35
+ **Download the Pro version here - https://wpovernight.com/downloads/menu-cart-pro/**
36
+
37
+ Finally, the cart automatically conforms to your site's styles, leaving you with no extra work.
38
+
39
+ Compatibility:
40
+
41
+ * WooCommerce
42
+ * Easy Digital Downloads
43
+ * Eshop
44
+ * WP-Ecommerce
45
+ * Jigoshop
46
+
47
+ Translations:
48
+
49
+ * Brazilian Portuguese
50
+ * Danish
51
+ * Dutch
52
+ * Croatian
53
+ * Czech
54
+ * English
55
+ * French
56
+ * German
57
+ * Greek
58
+ * Hebrew
59
+ * Hungarian
60
+ * Italian
61
+ * Norwegian
62
+ * Persian
63
+ * Polish
64
+ * Portuguese
65
+ * Russian
66
+ * Spanish[1]
67
+ * Swedish
68
+ * Turkish
69
+ * Vietnamese
70
+
71
+ [1] WebHostingHub
72
+ == Installation ==
73
+
74
+ Delete any old installations of the plugin. Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
75
+
76
+ Once the plugin is activated navigate to Settings > Menu Cart Setup. Select your options, save and you're ready to go. It's that easy!
77
+
78
+ == Screenshots ==
79
+
80
+ 1. Shows menu before and after Menu Cart.
81
+ 2. 3 different display style options to choose from.
82
+ 3. Shows settings page.
83
+
84
+ == Frequently Asked Questions ==
85
+
86
+ == Changelog ==
87
+
88
+ = 2.7.7 =
89
+ * Fix: include default classes when menu cart is the only item in the menu
90
+ * Fix: cart existence check global usage only for old versions
91
+ * Tested up to WooCommerce 3.9
92
+
93
+ = 2.7.6 =
94
+ * Improved accessibility for screen readers (cart icon)
95
+ * Tested up to WC3.8
96
+ * Tested up to WP5.3
97
+
98
+ = 2.7.5 =
99
+ * Fix: check if woocommerce version constant is defined
100
+ * Fix: Prevent fatal errors when switching eCommerce plugins
101
+ * Fix: Persian translations
102
+ * Fix: Notices when not using icon
103
+ * Marked tested up to WC3.6
104
+ * Marked tested up to WP5.2
105
+
106
+ = 2.7.4 =
107
+ * Tested up to WP5.1
108
+
109
+ = 2.7.3 =
110
+ * Fix: French plural forms rule (zero = single)
111
+
112
+ = 2.7.2 =
113
+ * Tested with WooCommerce 3.5
114
+
115
+ = 2.7.1 =
116
+
117
+ * fix label on price to display setting
118
+ * Fix live updating cart for first product with 'Always display cart' setting enabled
119
+
120
+ = 2.7.0 =
121
+
122
+ * Feature: Full integration with wordpress.org language packs (finally!)
123
+ * Feature (WooCommerce): Option to display either total (including fees) or subtotal (total of products)
124
+ * Feature (EDD): Native integration with EDD AJAX
125
+ * Fix: Several improvements & fixes to WooCommerce AJAX integration for sites with server side caching
126
+ * Fix: Cart icon on settings page
127
+ * Translations: added Turkish
128
+
129
+ = 2.6.1 =
130
+
131
+ * Feature: Option to hide theme cart from Storefront or Divi
132
+ * Feature: Improved WooCommerce AJAX compatibility
133
+ * Fix: Updated FontAwesome to 4.7.0
134
+ * Tweak: load FontAwesome in separate CSS file to allow dequeueing
135
+ * Translations: Updated pt_BR
136
+
137
+ = 2.6.0 =
138
+
139
+ * WooCommerce 3.0 compatibility
140
+ * Translations: updated Swedish
141
+
142
+ = 2.5.8 =
143
+
144
+ * Translations: Added Croatian, Hebrew, Hungarian (updated) & Vietnamese
145
+ * Fix: Built-in AJAX for multiple menus
146
+ * Fix: Textdomain definition and allow custom translations
147
+ * Tweak: prevent loading cart when WooCommerce not loaded
148
+
149
+ = 2.5.7 =
150
+
151
+ * Fix: Improved JS in Easy Digital Downloads
152
+ * New: Hungarian translation
153
+ * Tweak: Use css dash instead of hard-coded dash
154
+
155
+ = 2.5.6 =
156
+
157
+ * New: Slovak Translation
158
+ * New: Option to use built in js
159
+ * Tweak: Moved JS to footer
160
+ * Tweak: improved css positioning
161
+ * Tweak: added js selectors
162
+ * Tweak: Brazilian Portuguese Translation
163
+
164
+ = 2.5.5 =
165
+
166
+ * New: Norwegian Translation
167
+
168
+ = 2.5.4 =
169
+
170
+ * New: Czech Translations
171
+ * New: Greek Translations
172
+ * Tweak: Seperated Item Classes
173
+ * Tweak: Removed Unnecessary submenu classes
174
+ * Tweak: Use get_total() instead of get_cart_total()
175
+ * Fix: Prices show tax if cart prices are set to display including tax
176
+ * Fix: Updated Font Awesome
177
+
178
+ = 2.5.3 =
179
+
180
+ * Fix: Ubermenu
181
+ * Added: Greek Translation
182
+
183
+ = 2.5.2 =
184
+
185
+ *Tweak: Merged menu cart versions
186
+
187
+ = 2.5.1 =
188
+
189
+ * WPML String Translation fix
190
+
191
+ = 2.5 =
192
+
193
+ * Major Code refactor: CLEANER, FASTER, MORE FLEXIBLE!
194
+ * Added: Shop detection for Multisite
195
+ * Added: WPML String Translation setting
196
+ * Added: Persian translations
197
+ * Updated: Font Awesome
198
+ * Updated: Spanish, Portugese, Brazilian, French & Polish Translations
199
+ * Fix: PHP strict warnings
200
+ * Fix: CSS for Twenty Twelve & Twenty Fourteen
201
+
202
+ = 2.2.2 =
203
+
204
+ * Jigoshop Bug Fix
205
+
206
+ = 2.2.1 =
207
+
208
+ * WPML bug fixes
209
+
210
+ = 2.2.0 =
211
+
212
+ * Several bugfixes & improvements
213
+ * Better AJAX integration with EDD & eShop
214
+ * Various filters added for better theme integration & easier customization
215
+ * DOMHtml warnings surpressed
216
+
217
+ = 2.1.5 =
218
+
219
+ Fix: Edd and WP e-Commerce ajax.
220
+
221
+ = 2.1.4 =
222
+
223
+ Fixed WP e-Commerce ajax conflict and uploaded proper French translation.
224
+
225
+ = 2.1.3 =
226
+
227
+ EDD total price bug fixed
228
+
229
+ = 2.1.2 =
230
+
231
+ Added WP-Ecommerce and EDD
232
+
233
+ = 2.1.0 =
234
+
235
+ Initial Release
236
+
237
+ == Upgrade Notice ==
238
+
239
+ = 2.5.5 =
240
+
241
+ * New: Norwegian Translation
242
+
243
+ = 2.5.4 =
244
+
245
+ * New: Czech Translations
246
+ * New: Greek Translations
247
+ * Tweak: Seperated Item Classes
248
+ * Tweak: Removed Unnecessary submenu classes
249
+ * Tweak: Use get_total() instead of get_cart_total()
250
+ * Fix: Prices show tax if cart prices are set to display including tax
251
+ * Fix: Updated Font Awesome
252
+
253
+ = 2.5.3 =
254
+
255
+ * Fix: Ubermenu
256
+ * Added: Greek Translation
257
+
258
+ = 2.5.2 =
259
+
260
+ *Tweak: Merged menu cart versions
261
+
262
+ = 2.5.1 =
263
+
264
+ * WPML String Translation fix
265
+
266
+ = 2.5 =
267
+
268
+ * Major Code refactor: CLEANER, FASTER, MORE FLEXIBLE!
269
+ * Added: Shop detection for Multisite
270
+ * Added: WPML String Translation setting
271
+ * Added: Persian translations
272
+ * Updated: Font Awesome
273
+ * Updated: Spanish, Portugese, Brazilian, French & Polish Translations
274
+ * Fix: PHP strict warnings
275
+ * Fix: CSS for Twenty Twelve & Twenty Fourteen
276
+
277
+ = 2.2.2 =
278
+
279
+ * Jigoshop Bug Fix
280
+
281
+ = 2.2.1 =
282
+
283
+ * WPML bug fixes
284
+
285
+ = 2.2.0 =
286
+
287
+ * Several bugfixes & improvements
288
+ * Better AJAX integration with EDD & eShop
289
+ * Various filters added for better theme integration & easier customization
290
+ * DOMHtml warnings surpressed
291
+
292
+ = 2.1.5 =
293
+
294
+ Fix: Edd and WP e-Commerce ajax.
295
+
296
+ = 2.1.4 =
297
+
298
+ Fixed WP e-Commerce ajax conflict and uploaded proper French translation.
299
+
300
+ = 2.1.3 =
301
+
302
+ EDD total price bug fixed
303
+
304
+ = 2.1.2 =
305
+
306
+ Added WP-Ecommerce and EDD
307
+
308
+ = 2.1.0 =
309
+
310
  Initial Release
wp-menu-cart.php CHANGED
@@ -1,613 +1,619 @@
1
- <?php
2
- /**
3
- * Plugin Name: WooCommerce Menu Cart
4
- * Plugin URI: www.wpovernight.com/plugins
5
- * Description: Extension for your e-commerce plugin (WooCommerce, WP-Ecommerce, Easy Digital Downloads, Eshop or Jigoshop) that places a cart icon with number of items and total cost in the menu bar. Activate the plugin, set your options and you're ready to go! Will automatically conform to your theme styles.
6
- * Version: 2.7.6
7
- * Author: Jeremiah Prummer, Ewout Fernhout
8
- * Author URI: www.wpovernight.com/
9
- * License: GPL2
10
- * Text Domain: wp-menu-cart
11
- * WC requires at least: 2.0.0
12
- * WC tested up to: 3.8.0
13
- */
14
-
15
- class WpMenuCart {
16
-
17
- public static $plugin_slug;
18
- public static $plugin_basename;
19
-
20
- /**
21
- * Construct.
22
- */
23
- public function __construct() {
24
- self::$plugin_slug = basename(dirname(__FILE__));
25
- self::$plugin_basename = plugin_basename(__FILE__);
26
-
27
- $this->options = get_option('wpmenucart');
28
-
29
- // load the localisation & classes
30
- add_action( 'plugins_loaded', array( &$this, 'languages' ), 0 ); // or use init?
31
- add_filter( 'load_textdomain_mofile', array( $this, 'textdomain_fallback' ), 10, 2 );
32
- add_action( 'init', array( &$this, 'wpml' ), 0 );
33
- add_action( 'init', array( $this, 'load_classes' ) );
34
-
35
- // enqueue scripts & ajax
36
- add_action( 'wp_enqueue_scripts', array( &$this, 'load_scripts_styles' ) ); // Load scripts
37
- add_action( 'wp_ajax_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
38
- add_action( 'wp_ajax_nopriv_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
39
-
40
- // add filters to selected menus to add cart item <li>
41
- add_action( 'init', array( $this, 'filter_nav_menus' ) );
42
- // $this->filter_nav_menus();
43
- }
44
-
45
- /**
46
- * Load classes
47
- * @return void
48
- */
49
- public function load_classes() {
50
- include_once( 'includes/wpmenucart-settings.php' );
51
- $this->settings = new WpMenuCart_Settings();
52
-
53
- if ( $this->good_to_go() ) {
54
- if (isset($this->options['shop_plugin'])) {
55
- if ( false === $this->is_shop_active( $this->options['shop_plugin'] ) ) {
56
- return;
57
- }
58
- switch ($this->options['shop_plugin']) {
59
- case 'woocommerce':
60
- include_once( 'includes/wpmenucart-woocommerce.php' );
61
- $this->shop = new WPMenuCart_WooCommerce();
62
- if ( !isset($this->options['builtin_ajax']) ) {
63
- if ( defined('WOOCOMMERCE_VERSION') && version_compare( WOOCOMMERCE_VERSION, '2.7', '>=' ) ) {
64
- add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
65
- } else {
66
- add_filter( 'add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
67
- }
68
- }
69
- break;
70
- case 'jigoshop':
71
- include_once( 'includes/wpmenucart-jigoshop.php' );
72
- $this->shop = new WPMenuCart_Jigoshop();
73
- if ( !isset($this->options['builtin_ajax']) ) {
74
- add_filter( 'add_to_cart_fragments', array( &$this, 'woocommerce_ajax_fragments' ) );
75
- }
76
- break;
77
- case 'wp-e-commerce':
78
- include_once( 'includes/wpmenucart-wpec.php' );
79
- $this->shop = new WPMenuCart_WPEC();
80
- break;
81
- case 'eshop':
82
- include_once( 'includes/wpmenucart-eshop.php' );
83
- $this->shop = new WPMenuCart_eShop();
84
- break;
85
- case 'easy-digital-downloads':
86
- include_once( 'includes/wpmenucart-edd.php' );
87
- $this->shop = new WPMenuCart_EDD();
88
- if ( !isset($this->options['builtin_ajax']) ) {
89
- add_action("wp_enqueue_scripts", array( &$this, 'load_edd_ajax' ), 0 );
90
- }
91
- break;
92
- }
93
- if ( isset( $this->options['builtin_ajax'] ) || in_array( $this->options['shop_plugin'], array( 'WP e-Commerce', 'wp-e-commerce', 'eShop', 'eshop' ) ) ) {
94
- add_action("wp_enqueue_scripts", array( &$this, 'load_custom_ajax' ), 0 );
95
- }
96
-
97
- }
98
- }
99
- }
100
-
101
- /**
102
- * Check if a shop is active or if conflicting old versions of the plugin are active
103
- * @return boolean
104
- */
105
- public function good_to_go() {
106
- $wpmenucart_shop_check = get_option( 'wpmenucart_shop_check' );
107
- $active_plugins = $this->get_active_plugins();
108
-
109
- // check for shop plugins
110
- if ( !$this->is_shop_active() && $wpmenucart_shop_check != 'hide' ) {
111
- add_action( 'admin_notices', array ( $this, 'need_shop' ) );
112
- return FALSE;
113
- }
114
-
115
- // check for old versions
116
- if ( count( $this->get_active_old_versions() ) > 0 ) {
117
- add_action( 'admin_notices', array ( $this, 'woocommerce_version_active' ) );
118
- return FALSE;
119
- }
120
-
121
- // we made it! good to go :o)
122
- return TRUE;
123
- }
124
-
125
- /**
126
- * Return true if one ore more shops are activated.
127
- * @return boolean
128
- */
129
- public function is_shop_active( $shop = '' ) {
130
- if ( empty($shop) ) {
131
- if ( count( $this->get_active_shops() ) > 0 ) {
132
- return TRUE;
133
- } else {
134
- return FALSE;
135
- }
136
- } else {
137
- switch ( $shop ) {
138
- case 'woocommerce':
139
- return function_exists('WC');
140
- break;
141
- case 'easy-digital-downloads':
142
- return function_exists('EDD');
143
- break;
144
- case 'jigoshop':
145
- return class_exists('jigoshop_cart');
146
- break;
147
- case 'wp-e-commerce':
148
- return function_exists('wpsc_cart_item_count');
149
- break;
150
- case 'eshop':
151
- return !empty($GLOBALS['eshopoptions']);
152
- break;
153
- default:
154
- return false;
155
- break;
156
- }
157
- }
158
- }
159
-
160
- /**
161
- * Get an array of all active plugins, including multisite
162
- * @return array active plugin paths
163
- */
164
- public static function get_active_plugins() {
165
- $active_plugins = (array) apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
166
- if (is_multisite()) {
167
- // get_site_option( 'active_sitewide_plugins', array() ) returns a 'reversed list'
168
- // like [hello-dolly/hello.php] => 1369572703 so we do array_keys to make the array
169
- // compatible with $active_plugins
170
- $active_sitewide_plugins = (array) array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
171
- // merge arrays and remove doubles
172
- $active_plugins = (array) array_unique( array_merge( $active_plugins, $active_sitewide_plugins ) );
173
- }
174
-
175
- return $active_plugins;
176
- }
177
-
178
- /**
179
- * Get array of active shop plugins
180
- *
181
- * @return array plugin name => plugin path
182
- */
183
- public static function get_active_shops() {
184
- $active_plugins = self::get_active_plugins();
185
-
186
- $shop_plugins = array (
187
- 'WooCommerce' => 'woocommerce/woocommerce.php',
188
- 'Jigoshop' => 'jigoshop/jigoshop.php',
189
- 'WP e-Commerce' => 'wp-e-commerce/wp-shopping-cart.php',
190
- 'eShop' => 'eshop/eshop.php',
191
- 'Easy Digital Downloads' => 'easy-digital-downloads/easy-digital-downloads.php',
192
- );
193
-
194
- // filter shop plugins & add shop names as keys
195
- $active_shop_plugins = array_intersect( $shop_plugins, $active_plugins );
196
-
197
- return $active_shop_plugins;
198
- }
199
-
200
- /**
201
- * Get array of active old WooCommerce Menu Cart plugins
202
- *
203
- * @return array plugin paths
204
- */
205
- public function get_active_old_versions() {
206
- $active_plugins = $this->get_active_plugins();
207
-
208
- $old_versions = array (
209
- 'woocommerce-menu-bar-cart/wc_cart_nav.php', //first version
210
- 'woocommerce-menu-bar-cart/woocommerce-menu-cart.php', //last free version
211
- 'woocommerce-menu-cart/woocommerce-menu-cart.php', //never actually released? just in case...
212
- 'woocommerce-menu-cart-pro/woocommerce-menu-cart-pro.php', //old pro version
213
- );
214
-
215
- $active_old_plugins = array_intersect( $old_versions, $active_plugins );
216
-
217
- return $active_old_plugins;
218
- }
219
-
220
- /**
221
- * Fallback admin notices
222
- *
223
- * @return string Fallack notice.
224
- */
225
- public function need_shop() {
226
- $error = __( 'WP Menu Cart could not detect an active shop plugin. Make sure you have activated at least one of the supported plugins.' , 'wp-menu-cart' );
227
- $message = sprintf('<div class="error"><p>%1$s <a href="%2$s">%3$s</a></p></div>', $error, add_query_arg( 'hide_wpmenucart_shop_check', 'true' ), __( 'Hide this notice', 'wp-menu-cart' ) );
228
- echo $message;
229
- }
230
-
231
- public function woocommerce_version_active() {
232
- $error = __( 'An old version of WooCommerce Menu Cart is currently activated, you need to disable or uninstall it for WP Menu Cart to function properly' , 'wp-menu-cart' );
233
- $message = '<div class="error"><p>' . $error . '</p></div>';
234
- echo $message;
235
- }
236
-
237
- /**
238
- * Load translations.
239
- */
240
- public function languages() {
241
- $locale = apply_filters( 'plugin_locale', get_locale(), 'wp-menu-cart' );
242
- $dir = trailingslashit( WP_LANG_DIR );
243
-
244
- /**
245
- * Frontend/global Locale. Looks in:
246
- *
247
- * - WP_LANG_DIR/wp-menu-cart/wp-menu-cart-LOCALE.mo
248
- * - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
249
- * - wp-menu-cart/languages/wp-menu-cart-LOCALE.mo (which if not found falls back to:)
250
- * - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
251
- */
252
- load_textdomain( 'wp-menu-cart', $dir . 'wp-menu-cart/wp-menu-cart-' . $locale . '.mo' );
253
- load_textdomain( 'wp-menu-cart', $dir . 'plugins/wp-menu-cart-' . $locale . '.mo' );
254
- load_plugin_textdomain( 'wp-menu-cart', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
255
- }
256
-
257
- /**
258
- * Maintain textdomain compatibility between main plugin (wp-menu-cart) and WooCommerce version (woocommerce-menu-bar-cart)
259
- * so that wordpress.org language packs can be used for both
260
- */
261
- public function textdomain_fallback( $mofile, $textdomain ) {
262
- $main_domain = 'wp-menu-cart';
263
- $wc_domain = 'woocommerce-menu-bar-cart';
264
-
265
- // check if this is filtering the mofile for this plugin
266
- if ( $textdomain === $main_domain ) {
267
- $wc_mofile = str_replace( "{$textdomain}-", "{$wc_domain}-", $mofile ); // with trailing dash to target file and not folder
268
- if ( file_exists( $wc_mofile ) ) {
269
- // we have a wc override - use it
270
- return $wc_mofile;
271
- }
272
- }
273
-
274
- return $mofile;
275
- }
276
-
277
- /**
278
- * Register strings for WPML String Translation
279
- */
280
- public function wpml() {
281
- if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_register_string' ) ) {
282
- icl_register_string('WP Menu Cart', 'item text', 'item');
283
- icl_register_string('WP Menu Cart', 'items text', 'items');
284
- icl_register_string('WP Menu Cart', 'empty cart text', 'your cart is currently empty');
285
- icl_register_string('WP Menu Cart', 'hover text', 'View your shopping cart');
286
- icl_register_string('WP Menu Cart', 'empty hover text', 'Start shopping');
287
- }
288
- }
289
-
290
-
291
- /**
292
- * Load custom ajax
293
- */
294
- public function load_custom_ajax() {
295
- wp_enqueue_script(
296
- 'wpmenucart',
297
- plugins_url( '/javascript/wpmenucart.js' , __FILE__ ),
298
- array( 'jquery' ),
299
- '2.7.6',
300
- true
301
- );
302
-
303
- // get URL to WordPress ajax handling page
304
- if ( $this->options['shop_plugin'] == 'easy-digital-downloads' && function_exists( 'edd_get_ajax_url' ) ) {
305
- // use EDD function to prevent SSL issues http://git.io/V7w76A
306
- $ajax_url = edd_get_ajax_url();
307
- } else {
308
- $ajax_url = admin_url( 'admin-ajax.php' );
309
- }
310
-
311
- wp_localize_script(
312
- 'wpmenucart',
313
- 'wpmenucart_ajax',
314
- array(
315
- 'ajaxurl' => $ajax_url,
316
- 'nonce' => wp_create_nonce('wpmenucart')
317
- )
318
- );
319
- }
320
-
321
- /**
322
- * Load EDD ajax helper
323
- */
324
- public function load_edd_ajax() {
325
- wp_enqueue_script(
326
- 'wpmenucart-edd-ajax',
327
- plugins_url( '/javascript/wpmenucart-edd-ajax.js', __FILE__ ),
328
- array( 'jquery' ),
329
- '2.7.6'
330
- );
331
-
332
- wp_localize_script(
333
- 'wpmenucart-edd-ajax',
334
- 'wpmenucart_ajax',
335
- array(
336
- 'ajaxurl' => function_exists( 'edd_get_ajax_url' ) ? edd_get_ajax_url() : admin_url( 'admin-ajax.php' ),
337
- 'nonce' => wp_create_nonce('wpmenucart'),
338
- 'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
339
- )
340
- );
341
- }
342
-
343
-
344
- /**
345
- * Load CSS
346
- */
347
- public function load_scripts_styles() {
348
- if (isset($this->options['icon_display'])) {
349
- wp_register_style( 'wpmenucart-icons', plugins_url( '/css/wpmenucart-icons.css', __FILE__ ), array(), '', 'all' );
350
- wp_enqueue_style( 'wpmenucart-icons' );
351
- wp_register_style( 'wpmenucart-fontawesome', plugins_url( '/css/wpmenucart-fontawesome.css', __FILE__ ), array(), '', 'all' );
352
- wp_enqueue_style( 'wpmenucart-fontawesome' );
353
- }
354
-
355
- $css = file_exists( get_stylesheet_directory() . '/wpmenucart-main.css' )
356
- ? get_stylesheet_directory_uri() . '/wpmenucart-main.css'
357
- : plugins_url( '/css/wpmenucart-main.css', __FILE__ );
358
-
359
- wp_register_style( 'wpmenucart', $css, array(), '', 'all' );
360
- wp_enqueue_style( 'wpmenucart' );
361
-
362
- // Hide built-in theme carts
363
- if ( isset($this->options['hide_theme_cart']) ) {
364
- wp_add_inline_style( 'wpmenucart', '.et-cart-info { display:none !important; } .site-header-cart { display:none !important; }' );
365
- }
366
-
367
- //Load Stylesheet if twentytwelve is active
368
- if ( wp_get_theme() == 'Twenty Twelve' ) {
369
- wp_register_style( 'wpmenucart-twentytwelve', plugins_url( '/css/wpmenucart-twentytwelve.css', __FILE__ ), array(), '', 'all' );
370
- wp_enqueue_style( 'wpmenucart-twentytwelve' );
371
- }
372
-
373
- //Load Stylesheet if twentyfourteen is active
374
- if ( wp_get_theme() == 'Twenty Fourteen' ) {
375
- wp_register_style( 'wpmenucart-twentyfourteen', plugins_url( '/css/wpmenucart-twentyfourteen.css', __FILE__ ), array(), '', 'all' );
376
- wp_enqueue_style( 'wpmenucart-twentyfourteen' );
377
- }
378
-
379
- // extra script that improves AJAX behavior when 'Always display cart' is disabled
380
- wp_enqueue_script(
381
- 'wpmenucart-ajax-assist',
382
- plugins_url( '/javascript/wpmenucart-ajax-assist.js', __FILE__ ),
383
- array( 'jquery' )
384
- );
385
- wp_localize_script(
386
- 'wpmenucart-ajax-assist',
387
- 'wpmenucart_ajax_assist',
388
- array(
389
- 'shop_plugin' => isset($this->options['shop_plugin']) ? $this->options['shop_plugin'] : '',
390
- 'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
391
- )
392
- );
393
-
394
- }
395
-
396
- /**
397
- * Add filters to selected menus to add cart item <li>
398
- */
399
- public function filter_nav_menus() {
400
- // exit if no shop class is active
401
- if ( !isset($this->shop) )
402
- return;
403
-
404
- // exit if no menus set
405
- if ( !isset( $this->options['menu_slugs'] ) || empty( $this->options['menu_slugs'] ) )
406
- return;
407
-
408
- if ( $this->options['menu_slugs'][1] != '0' ) {
409
- add_filter( 'wp_nav_menu_' . $this->options['menu_slugs'][1] . '_items', array( &$this, 'add_itemcart_to_menu' ) , 10, 2 );
410
- }
411
- }
412
-
413
- /**
414
- * Add Menu Cart to menu
415
- *
416
- * @return menu items + Menu Cart item
417
- */
418
- public function add_itemcart_to_menu( $items ) {
419
- // WooCommerce specific: check if woocommerce cart object is actually loaded
420
- if ( isset($this->options['shop_plugin']) && $this->options['shop_plugin'] == 'woocommerce' ) {
421
- global $woocommerce;
422
- if (empty($woocommerce) || !is_object($woocommerce) || !isset($woocommerce->cart) || !is_object($woocommerce->cart)) {
423
- return $items; // nothing to load data from, return menu without cart item
424
- }
425
- }
426
-
427
- $classes = 'wpmenucartli wpmenucart-display-'.$this->options['items_alignment'];
428
-
429
- if ($this->get_common_li_classes($items) != '')
430
- $classes .= ' ' . $this->get_common_li_classes($items);
431
-
432
- $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
433
-
434
- // Filter for <li> item classes
435
- /* Usage (in the themes functions.php):
436
- add_filter('wpmenucart_menu_item_classes', 'add_wpmenucart_item_class', 1, 1);
437
- function add_wpmenucart_item_class ($classes) {
438
- $classes .= ' yourclass';
439
- return $classes;
440
- }
441
- */
442
- $classes = apply_filters( 'wpmenucart_menu_item_classes', $classes );
443
- $this->menu_items['menu']['menu_item_li_classes'] = $classes;
444
-
445
- // DEPRECATED: These filters are now deprecated in favour of the more precise filters in the functions!
446
- $wpmenucart_menu_item = apply_filters( 'wpmenucart_menu_item_filter', $this->wpmenucart_menu_item() );
447
-
448
- $item_data = $this->shop->menu_item();
449
-
450
- $menu_item_li = '<li class="'.$classes.'" id="wpmenucartli">' . $wpmenucart_menu_item . '</li>';
451
-
452
- if ( apply_filters('wpmenucart_prepend_menu_item', false) ) {
453
- $items = apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li ) . $items;
454
- } else {
455
- $items .= apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li );
456
- }
457
-
458
- return $items;
459
- }
460
-
461
- /**
462
- * Get a flat list of common classes from all menu items in a menu
463
- * @param string $items nav_menu HTML containing all <li> menu items
464
- * @return string flat (imploded) list of common classes
465
- */
466
- public function get_common_li_classes($items) {
467
- if (empty($items)) return '';
468
- if (!class_exists('DOMDocument')) return '';
469
-
470
- $libxml_previous_state = libxml_use_internal_errors(true); // enable user error handling
471
-
472
- $dom_items = new DOMDocument;
473
- $dom_items->loadHTML( $items );
474
- $lis = $dom_items->getElementsByTagName('li');
475
-
476
- if (empty($lis)) {
477
- libxml_clear_errors();
478
- libxml_use_internal_errors($libxml_previous_state);
479
- return;
480
- }
481
-
482
- foreach($lis as $li) {
483
- if ($li->parentNode->tagName != 'ul')
484
- $li_classes[] = explode( ' ', $li->getAttribute('class') );
485
- }
486
-
487
- // Uncomment to dump DOM errors / warnings
488
- //$errors = libxml_get_errors();
489
- //print_r ($errors);
490
-
491
- // clear errors and reset to previous error handling state
492
- libxml_clear_errors();
493
- libxml_use_internal_errors($libxml_previous_state);
494
-
495
- if ( !empty($li_classes) ) {
496
- $common_li_classes = array_shift($li_classes);
497
- foreach ($li_classes as $li_class) {
498
- $common_li_classes = array_intersect($li_class, $common_li_classes);
499
- }
500
- $common_li_classes_flat = implode(' ', $common_li_classes);
501
- } else {
502
- $common_li_classes_flat = '';
503
- }
504
- return $common_li_classes_flat;
505
- }
506
-
507
- /**
508
- * Ajaxify Menu Cart
509
- */
510
- public function woocommerce_ajax_fragments( $fragments ) {
511
- if ( ! defined('WOOCOMMERCE_CART') ) {
512
- define( 'WOOCOMMERCE_CART', true );
513
- }
514
-
515
- $fragments['a.wpmenucart-contents'] = $this->wpmenucart_menu_item();
516
- return $fragments;
517
- }
518
-
519
- /**
520
- * Create HTML for Menu Cart item
521
- */
522
- public function wpmenucart_menu_item() {
523
- $item_data = $this->shop->menu_item();
524
-
525
- // Check empty cart settings
526
- if ($item_data['cart_contents_count'] == 0 && ( !isset($this->options['always_display']) ) ) {
527
- $empty_menu_item = '<a class="wpmenucart-contents empty-wpmenucart" style="display:none">&nbsp;</a>';
528
- return $empty_menu_item;
529
- }
530
-
531
- if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_t' ) ) {
532
- //use WPML
533
- $viewing_cart = icl_t('WP Menu Cart', 'hover text', 'View your shopping cart');
534
- $start_shopping = icl_t('WP Menu Cart', 'empty hover text', 'Start shopping');
535
- $cart_contents = $item_data['cart_contents_count'] .' '. ( $item_data['cart_contents_count'] == 1 ? icl_t('WP Menu Cart', 'item text', 'item') : icl_t('WP Menu Cart', 'items text', 'items') );
536
- } else {
537
- //use regular WP i18n
538
- $viewing_cart = __('View your shopping cart', 'wp-menu-cart');
539
- $start_shopping = __('Start shopping', 'wp-menu-cart');
540
- $cart_contents = sprintf(_n('%d item', '%d items', $item_data['cart_contents_count'], 'wp-menu-cart'), $item_data['cart_contents_count']);
541
- }
542
-
543
- $this->menu_items['menu']['cart_contents'] = $cart_contents;
544
-
545
- if ($item_data['cart_contents_count'] == 0) {
546
- $menu_item_href = apply_filters ('wpmenucart_emptyurl', $item_data['shop_page_url'] );
547
- $menu_item_title = apply_filters ('wpmenucart_emptytitle', $start_shopping );
548
- $menu_item_classes = 'wpmenucart-contents empty-wpmenucart-visible';
549
- } else {
550
- $menu_item_href = apply_filters ('wpmenucart_fullurl', $item_data['cart_url'] );
551
- $menu_item_title = apply_filters ('wpmenucart_fulltitle', $viewing_cart );
552
- $menu_item_classes = 'wpmenucart-contents';
553
- }
554
-
555
- $this->menu_items['menu']['menu_item_href'] = $menu_item_href;
556
- $this->menu_items['menu']['menu_item_title'] = $menu_item_title;
557
-
558
- if(defined('UBERMENU_VERSION') && (version_compare(UBERMENU_VERSION, '3.0.0') >= 0)){
559
- $menu_item_classes .= ' ubermenu-target';
560
- }
561
-
562
- $menu_item = '<a class="'.$menu_item_classes.'" href="'.$menu_item_href.'" title="'.$menu_item_title.'">';
563
-
564
- $menu_item_a_content = '';
565
- if (isset($this->options['icon_display'])) {
566
- $icon = isset($this->options['cart_icon']) ? $this->options['cart_icon'] : '0';
567
- $menu_item_icon = '<i class="wpmenucart-icon-shopping-cart-'.$icon.'" role="img" aria-label="'.__( 'Cart','woocommerce' ).'"></i>';
568
- $menu_item_a_content .= $menu_item_icon;
569
- } else {
570
- $menu_item_icon = '';
571
- }
572
-
573
- switch ($this->options['items_display']) {
574
- case 1: //items only
575
- $menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span>';
576
- break;
577
- case 2: //price only
578
- $menu_item_a_content .= '<span class="amount">'.$item_data['cart_total'].'</span>';
579
- break;
580
- case 3: //items & price
581
- $menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span><span class="amount">'.$item_data['cart_total'].'</span>';
582
- break;
583
- }
584
- $menu_item_a_content = apply_filters ('wpmenucart_menu_item_a_content', $menu_item_a_content, $menu_item_icon, $cart_contents, $item_data );
585
-
586
- $this->menu_items['menu']['menu_item_a_content'] = $menu_item_a_content;
587
-
588
- $menu_item .= $menu_item_a_content . '</a>';
589
-
590
- $menu_item = apply_filters ('wpmenucart_menu_item_a', $menu_item, $item_data, $this->options, $menu_item_a_content, $viewing_cart, $start_shopping, $cart_contents);
591
-
592
- if( !empty( $menu_item ) ) return $menu_item;
593
- }
594
-
595
- public function wpmenucart_ajax() {
596
- check_ajax_referer( 'wpmenucart', 'security' );
597
-
598
- $variable = $this->wpmenucart_menu_item();
599
- echo $variable;
600
- die();
601
- }
602
-
603
- }
604
-
605
- $wpMenuCart = new WpMenuCart();
606
-
607
- /**
608
- * Hide notifications
609
- */
610
-
611
- if ( ! empty( $_GET['hide_wpmenucart_shop_check'] ) ) {
612
- update_option( 'wpmenucart_shop_check', 'hide' );
 
 
 
 
 
 
613
  }
1
+ <?php
2
+ /**
3
+ * Plugin Name: WooCommerce Menu Cart
4
+ * Plugin URI: www.wpovernight.com/plugins
5
+ * Description: Extension for your e-commerce plugin (WooCommerce, WP-Ecommerce, Easy Digital Downloads, Eshop or Jigoshop) that places a cart icon with number of items and total cost in the menu bar. Activate the plugin, set your options and you're ready to go! Will automatically conform to your theme styles.
6
+ * Version: 2.7.7
7
+ * Author: Jeremiah Prummer, Ewout Fernhout
8
+ * Author URI: www.wpovernight.com/
9
+ * License: GPL2
10
+ * Text Domain: wp-menu-cart
11
+ * WC requires at least: 2.0.0
12
+ * WC tested up to: 3.9.0
13
+ */
14
+
15
+ class WpMenuCart {
16
+
17
+ public static $plugin_slug;
18
+ public static $plugin_basename;
19
+
20
+ /**
21
+ * Construct.
22
+ */
23
+ public function __construct() {
24
+ self::$plugin_slug = basename(dirname(__FILE__));
25
+ self::$plugin_basename = plugin_basename(__FILE__);
26
+
27
+ $this->options = get_option('wpmenucart');
28
+
29
+ // load the localisation & classes
30
+ add_action( 'plugins_loaded', array( &$this, 'languages' ), 0 ); // or use init?
31
+ add_filter( 'load_textdomain_mofile', array( $this, 'textdomain_fallback' ), 10, 2 );
32
+ add_action( 'init', array( &$this, 'wpml' ), 0 );
33
+ add_action( 'init', array( $this, 'load_classes' ) );
34
+
35
+ // enqueue scripts & ajax
36
+ add_action( 'wp_enqueue_scripts', array( &$this, 'load_scripts_styles' ) ); // Load scripts
37
+ add_action( 'wp_ajax_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
38
+ add_action( 'wp_ajax_nopriv_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
39
+
40
+ // add filters to selected menus to add cart item <li>
41
+ add_action( 'init', array( $this, 'filter_nav_menus' ) );
42
+ // $this->filter_nav_menus();
43
+ }
44
+
45
+ /**
46
+ * Load classes
47
+ * @return void
48
+ */
49
+ public function load_classes() {
50
+ include_once( 'includes/wpmenucart-settings.php' );
51
+ $this->settings = new WpMenuCart_Settings();
52
+
53
+ if ( $this->good_to_go() ) {
54
+ if (isset($this->options['shop_plugin'])) {
55
+ if ( false === $this->is_shop_active( $this->options['shop_plugin'] ) ) {
56
+ return;
57
+ }
58
+ switch ($this->options['shop_plugin']) {
59
+ case 'woocommerce':
60
+ include_once( 'includes/wpmenucart-woocommerce.php' );
61
+ $this->shop = new WPMenuCart_WooCommerce();
62
+ if ( !isset($this->options['builtin_ajax']) ) {
63
+ if ( defined('WOOCOMMERCE_VERSION') && version_compare( WOOCOMMERCE_VERSION, '2.7', '>=' ) ) {
64
+ add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
65
+ } else {
66
+ add_filter( 'add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
67
+ }
68
+ }
69
+ break;
70
+ case 'jigoshop':
71
+ include_once( 'includes/wpmenucart-jigoshop.php' );
72
+ $this->shop = new WPMenuCart_Jigoshop();
73
+ if ( !isset($this->options['builtin_ajax']) ) {
74
+ add_filter( 'add_to_cart_fragments', array( &$this, 'woocommerce_ajax_fragments' ) );
75
+ }
76
+ break;
77
+ case 'wp-e-commerce':
78
+ include_once( 'includes/wpmenucart-wpec.php' );
79
+ $this->shop = new WPMenuCart_WPEC();
80
+ break;
81
+ case 'eshop':
82
+ include_once( 'includes/wpmenucart-eshop.php' );
83
+ $this->shop = new WPMenuCart_eShop();
84
+ break;
85
+ case 'easy-digital-downloads':
86
+ include_once( 'includes/wpmenucart-edd.php' );
87
+ $this->shop = new WPMenuCart_EDD();
88
+ if ( !isset($this->options['builtin_ajax']) ) {
89
+ add_action("wp_enqueue_scripts", array( &$this, 'load_edd_ajax' ), 0 );
90
+ }
91
+ break;
92
+ }
93
+ if ( isset( $this->options['builtin_ajax'] ) || in_array( $this->options['shop_plugin'], array( 'WP e-Commerce', 'wp-e-commerce', 'eShop', 'eshop' ) ) ) {
94
+ add_action("wp_enqueue_scripts", array( &$this, 'load_custom_ajax' ), 0 );
95
+ }
96
+
97
+ }
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Check if a shop is active or if conflicting old versions of the plugin are active
103
+ * @return boolean
104
+ */
105
+ public function good_to_go() {
106
+ $wpmenucart_shop_check = get_option( 'wpmenucart_shop_check' );
107
+ $active_plugins = $this->get_active_plugins();
108
+
109
+ // check for shop plugins
110
+ if ( !$this->is_shop_active() && $wpmenucart_shop_check != 'hide' ) {
111
+ add_action( 'admin_notices', array ( $this, 'need_shop' ) );
112
+ return FALSE;
113
+ }
114
+
115
+ // check for old versions
116
+ if ( count( $this->get_active_old_versions() ) > 0 ) {
117
+ add_action( 'admin_notices', array ( $this, 'woocommerce_version_active' ) );
118
+ return FALSE;
119
+ }
120
+
121
+ // we made it! good to go :o)
122
+ return TRUE;
123
+ }
124
+
125
+ /**
126
+ * Return true if one ore more shops are activated.
127
+ * @return boolean
128
+ */
129
+ public function is_shop_active( $shop = '' ) {
130
+ if ( empty($shop) ) {
131
+ if ( count( $this->get_active_shops() ) > 0 ) {
132
+ return TRUE;
133
+ } else {
134
+ return FALSE;
135
+ }
136
+ } else {
137
+ switch ( $shop ) {
138
+ case 'woocommerce':
139
+ return function_exists('WC');
140
+ break;
141
+ case 'easy-digital-downloads':
142
+ return function_exists('EDD');
143
+ break;
144
+ case 'jigoshop':
145
+ return class_exists('jigoshop_cart');
146
+ break;
147
+ case 'wp-e-commerce':
148
+ return function_exists('wpsc_cart_item_count');
149
+ break;
150
+ case 'eshop':
151
+ return !empty($GLOBALS['eshopoptions']);
152
+ break;
153
+ default:
154
+ return false;
155
+ break;
156
+ }
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Get an array of all active plugins, including multisite
162
+ * @return array active plugin paths
163
+ */
164
+ public static function get_active_plugins() {
165
+ $active_plugins = (array) apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
166
+ if (is_multisite()) {
167
+ // get_site_option( 'active_sitewide_plugins', array() ) returns a 'reversed list'
168
+ // like [hello-dolly/hello.php] => 1369572703 so we do array_keys to make the array
169
+ // compatible with $active_plugins
170
+ $active_sitewide_plugins = (array) array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
171
+ // merge arrays and remove doubles
172
+ $active_plugins = (array) array_unique( array_merge( $active_plugins, $active_sitewide_plugins ) );
173
+ }
174
+
175
+ return $active_plugins;
176
+ }
177
+
178
+ /**
179
+ * Get array of active shop plugins
180
+ *
181
+ * @return array plugin name => plugin path
182
+ */
183
+ public static function get_active_shops() {
184
+ $active_plugins = self::get_active_plugins();
185
+
186
+ $shop_plugins = array (
187
+ 'WooCommerce' => 'woocommerce/woocommerce.php',
188
+ 'Jigoshop' => 'jigoshop/jigoshop.php',
189
+ 'WP e-Commerce' => 'wp-e-commerce/wp-shopping-cart.php',
190
+ 'eShop' => 'eshop/eshop.php',
191
+ 'Easy Digital Downloads' => 'easy-digital-downloads/easy-digital-downloads.php',
192
+ );
193
+
194
+ // filter shop plugins & add shop names as keys
195
+ $active_shop_plugins = array_intersect( $shop_plugins, $active_plugins );
196
+
197
+ return $active_shop_plugins;
198
+ }
199
+
200
+ /**
201
+ * Get array of active old WooCommerce Menu Cart plugins
202
+ *
203
+ * @return array plugin paths
204
+ */
205
+ public function get_active_old_versions() {
206
+ $active_plugins = $this->get_active_plugins();
207
+
208
+ $old_versions = array (
209
+ 'woocommerce-menu-bar-cart/wc_cart_nav.php', //first version
210
+ 'woocommerce-menu-bar-cart/woocommerce-menu-cart.php', //last free version
211
+ 'woocommerce-menu-cart/woocommerce-menu-cart.php', //never actually released? just in case...
212
+ 'woocommerce-menu-cart-pro/woocommerce-menu-cart-pro.php', //old pro version
213
+ );
214
+
215
+ $active_old_plugins = array_intersect( $old_versions, $active_plugins );
216
+
217
+ return $active_old_plugins;
218
+ }
219
+
220
+ /**
221
+ * Fallback admin notices
222
+ *
223
+ * @return string Fallack notice.
224
+ */
225
+ public function need_shop() {
226
+ $error = __( 'WP Menu Cart could not detect an active shop plugin. Make sure you have activated at least one of the supported plugins.' , 'wp-menu-cart' );
227
+ $message = sprintf('<div class="error"><p>%1$s <a href="%2$s">%3$s</a></p></div>', $error, add_query_arg( 'hide_wpmenucart_shop_check', 'true' ), __( 'Hide this notice', 'wp-menu-cart' ) );
228
+ echo $message;
229
+ }
230
+
231
+ public function woocommerce_version_active() {
232
+ $error = __( 'An old version of WooCommerce Menu Cart is currently activated, you need to disable or uninstall it for WP Menu Cart to function properly' , 'wp-menu-cart' );
233
+ $message = '<div class="error"><p>' . $error . '</p></div>';
234
+ echo $message;
235
+ }
236
+
237
+ /**
238
+ * Load translations.
239
+ */
240
+ public function languages() {
241
+ $locale = apply_filters( 'plugin_locale', get_locale(), 'wp-menu-cart' );
242
+ $dir = trailingslashit( WP_LANG_DIR );
243
+
244
+ /**
245
+ * Frontend/global Locale. Looks in:
246
+ *
247
+ * - WP_LANG_DIR/wp-menu-cart/wp-menu-cart-LOCALE.mo
248
+ * - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
249
+ * - wp-menu-cart/languages/wp-menu-cart-LOCALE.mo (which if not found falls back to:)
250
+ * - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
251
+ */
252
+ load_textdomain( 'wp-menu-cart', $dir . 'wp-menu-cart/wp-menu-cart-' . $locale . '.mo' );
253
+ load_textdomain( 'wp-menu-cart', $dir . 'plugins/wp-menu-cart-' . $locale . '.mo' );
254
+ load_plugin_textdomain( 'wp-menu-cart', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
255
+ }
256
+
257
+ /**
258
+ * Maintain textdomain compatibility between main plugin (wp-menu-cart) and WooCommerce version (woocommerce-menu-bar-cart)
259
+ * so that wordpress.org language packs can be used for both
260
+ */
261
+ public function textdomain_fallback( $mofile, $textdomain ) {
262
+ $main_domain = 'wp-menu-cart';
263
+ $wc_domain = 'woocommerce-menu-bar-cart';
264
+
265
+ // check if this is filtering the mofile for this plugin
266
+ if ( $textdomain === $main_domain ) {
267
+ $wc_mofile = str_replace( "{$textdomain}-", "{$wc_domain}-", $mofile ); // with trailing dash to target file and not folder
268
+ if ( file_exists( $wc_mofile ) ) {
269
+ // we have a wc override - use it
270
+ return $wc_mofile;
271
+ }
272
+ }
273
+
274
+ return $mofile;
275
+ }
276
+
277
+ /**
278
+ * Register strings for WPML String Translation
279
+ */
280
+ public function wpml() {
281
+ if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_register_string' ) ) {
282
+ icl_register_string('WP Menu Cart', 'item text', 'item');
283
+ icl_register_string('WP Menu Cart', 'items text', 'items');
284
+ icl_register_string('WP Menu Cart', 'empty cart text', 'your cart is currently empty');
285
+ icl_register_string('WP Menu Cart', 'hover text', 'View your shopping cart');
286
+ icl_register_string('WP Menu Cart', 'empty hover text', 'Start shopping');
287
+ }
288
+ }
289
+
290
+
291
+ /**
292
+ * Load custom ajax
293
+ */
294
+ public function load_custom_ajax() {
295
+ wp_enqueue_script(
296
+ 'wpmenucart',
297
+ plugins_url( '/javascript/wpmenucart.js' , __FILE__ ),
298
+ array( 'jquery' ),
299
+ '2.7.7',
300
+ true
301
+ );
302
+
303
+ // get URL to WordPress ajax handling page
304
+ if ( $this->options['shop_plugin'] == 'easy-digital-downloads' && function_exists( 'edd_get_ajax_url' ) ) {
305
+ // use EDD function to prevent SSL issues http://git.io/V7w76A
306
+ $ajax_url = edd_get_ajax_url();
307
+ } else {
308
+ $ajax_url = admin_url( 'admin-ajax.php' );
309
+ }
310
+
311
+ wp_localize_script(
312
+ 'wpmenucart',
313
+ 'wpmenucart_ajax',
314
+ array(
315
+ 'ajaxurl' => $ajax_url,
316
+ 'nonce' => wp_create_nonce('wpmenucart')
317
+ )
318
+ );
319
+ }
320
+
321
+ /**
322
+ * Load EDD ajax helper
323
+ */
324
+ public function load_edd_ajax() {
325
+ wp_enqueue_script(
326
+ 'wpmenucart-edd-ajax',
327
+ plugins_url( '/javascript/wpmenucart-edd-ajax.js', __FILE__ ),
328
+ array( 'jquery' ),
329
+ '2.7.7'
330
+ );
331
+
332
+ wp_localize_script(
333
+ 'wpmenucart-edd-ajax',
334
+ 'wpmenucart_ajax',
335
+ array(
336
+ 'ajaxurl' => function_exists( 'edd_get_ajax_url' ) ? edd_get_ajax_url() : admin_url( 'admin-ajax.php' ),
337
+ 'nonce' => wp_create_nonce('wpmenucart'),
338
+ 'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
339
+ )
340
+ );
341
+ }
342
+
343
+
344
+ /**
345
+ * Load CSS
346
+ */
347
+ public function load_scripts_styles() {
348
+ if (isset($this->options['icon_display'])) {
349
+ wp_register_style( 'wpmenucart-icons', plugins_url( '/css/wpmenucart-icons.css', __FILE__ ), array(), '', 'all' );
350
+ wp_enqueue_style( 'wpmenucart-icons' );
351
+ wp_register_style( 'wpmenucart-fontawesome', plugins_url( '/css/wpmenucart-fontawesome.css', __FILE__ ), array(), '', 'all' );
352
+ wp_enqueue_style( 'wpmenucart-fontawesome' );
353
+ }
354
+
355
+ $css = file_exists( get_stylesheet_directory() . '/wpmenucart-main.css' )
356
+ ? get_stylesheet_directory_uri() . '/wpmenucart-main.css'
357
+ : plugins_url( '/css/wpmenucart-main.css', __FILE__ );
358
+
359
+ wp_register_style( 'wpmenucart', $css, array(), '', 'all' );
360
+ wp_enqueue_style( 'wpmenucart' );
361
+
362
+ // Hide built-in theme carts
363
+ if ( isset($this->options['hide_theme_cart']) ) {
364
+ wp_add_inline_style( 'wpmenucart', '.et-cart-info { display:none !important; } .site-header-cart { display:none !important; }' );
365
+ }
366
+
367
+ //Load Stylesheet if twentytwelve is active
368
+ if ( wp_get_theme() == 'Twenty Twelve' ) {
369
+ wp_register_style( 'wpmenucart-twentytwelve', plugins_url( '/css/wpmenucart-twentytwelve.css', __FILE__ ), array(), '', 'all' );
370
+ wp_enqueue_style( 'wpmenucart-twentytwelve' );
371
+ }
372
+
373
+ //Load Stylesheet if twentyfourteen is active
374
+ if ( wp_get_theme() == 'Twenty Fourteen' ) {
375
+ wp_register_style( 'wpmenucart-twentyfourteen', plugins_url( '/css/wpmenucart-twentyfourteen.css', __FILE__ ), array(), '', 'all' );
376
+ wp_enqueue_style( 'wpmenucart-twentyfourteen' );
377
+ }
378
+
379
+ // extra script that improves AJAX behavior when 'Always display cart' is disabled
380
+ wp_enqueue_script(
381
+ 'wpmenucart-ajax-assist',
382
+ plugins_url( '/javascript/wpmenucart-ajax-assist.js', __FILE__ ),
383
+ array( 'jquery' )
384
+ );
385
+ wp_localize_script(
386
+ 'wpmenucart-ajax-assist',
387
+ 'wpmenucart_ajax_assist',
388
+ array(
389
+ 'shop_plugin' => isset($this->options['shop_plugin']) ? $this->options['shop_plugin'] : '',
390
+ 'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
391
+ )
392
+ );
393
+
394
+ }
395
+
396
+ /**
397
+ * Add filters to selected menus to add cart item <li>
398
+ */
399
+ public function filter_nav_menus() {
400
+ // exit if no shop class is active
401
+ if ( !isset($this->shop) )
402
+ return;
403
+
404
+ // exit if no menus set
405
+ if ( !isset( $this->options['menu_slugs'] ) || empty( $this->options['menu_slugs'] ) )
406
+ return;
407
+
408
+ if ( $this->options['menu_slugs'][1] != '0' ) {
409
+ add_filter( 'wp_nav_menu_' . $this->options['menu_slugs'][1] . '_items', array( &$this, 'add_itemcart_to_menu' ) , 10, 2 );
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Add Menu Cart to menu
415
+ *
416
+ * @return menu items + Menu Cart item
417
+ */
418
+ public function add_itemcart_to_menu( $items ) {
419
+ // WooCommerce specific: check if woocommerce cart object is actually loaded
420
+ if ( isset($this->options['shop_plugin']) && $this->options['shop_plugin'] == 'woocommerce' ) {
421
+ if ( function_exists( 'WC' ) ) {
422
+ if ( empty( WC()->cart ) ) {
423
+ return $items; // nothing to load data from, return menu without cart item
424
+ }
425
+ } else {
426
+ global $woocommerce;
427
+ if ( empty($woocommerce) || !is_object($woocommerce) || !isset($woocommerce->cart) || !is_object($woocommerce->cart) ) {
428
+ return $items; // nothing to load data from, return menu without cart item
429
+ }
430
+ }
431
+ }
432
+
433
+ $classes = 'menu-item wpmenucartli wpmenucart-display-'.$this->options['items_alignment'];
434
+
435
+ if ($this->get_common_li_classes($items) != '')
436
+ $classes .= ' ' . $this->get_common_li_classes($items);
437
+
438
+ $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
439
+
440
+ // Filter for <li> item classes
441
+ /* Usage (in the themes functions.php):
442
+ add_filter('wpmenucart_menu_item_classes', 'add_wpmenucart_item_class', 1, 1);
443
+ function add_wpmenucart_item_class ($classes) {
444
+ $classes .= ' yourclass';
445
+ return $classes;
446
+ }
447
+ */
448
+ $classes = apply_filters( 'wpmenucart_menu_item_classes', $classes );
449
+ $this->menu_items['menu']['menu_item_li_classes'] = $classes;
450
+
451
+ // DEPRECATED: These filters are now deprecated in favour of the more precise filters in the functions!
452
+ $wpmenucart_menu_item = apply_filters( 'wpmenucart_menu_item_filter', $this->wpmenucart_menu_item() );
453
+
454
+ $item_data = $this->shop->menu_item();
455
+
456
+ $menu_item_li = '<li class="'.$classes.'" id="wpmenucartli">' . $wpmenucart_menu_item . '</li>';
457
+
458
+ if ( apply_filters('wpmenucart_prepend_menu_item', false) ) {
459
+ $items = apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li ) . $items;
460
+ } else {
461
+ $items .= apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li );
462
+ }
463
+
464
+ return $items;
465
+ }
466
+
467
+ /**
468
+ * Get a flat list of common classes from all menu items in a menu
469
+ * @param string $items nav_menu HTML containing all <li> menu items
470
+ * @return string flat (imploded) list of common classes
471
+ */
472
+ public function get_common_li_classes($items) {
473
+ if (empty($items)) return '';
474
+ if (!class_exists('DOMDocument')) return '';
475
+
476
+ $libxml_previous_state = libxml_use_internal_errors(true); // enable user error handling
477
+
478
+ $dom_items = new DOMDocument;
479
+ $dom_items->loadHTML( $items );
480
+ $lis = $dom_items->getElementsByTagName('li');
481
+
482
+ if (empty($lis)) {
483
+ libxml_clear_errors();
484
+ libxml_use_internal_errors($libxml_previous_state);
485
+ return;
486
+ }
487
+
488
+ foreach($lis as $li) {
489
+ if ($li->parentNode->tagName != 'ul')
490
+ $li_classes[] = explode( ' ', $li->getAttribute('class') );
491
+ }
492
+
493
+ // Uncomment to dump DOM errors / warnings
494
+ //$errors = libxml_get_errors();
495
+ //print_r ($errors);
496
+
497
+ // clear errors and reset to previous error handling state
498
+ libxml_clear_errors();
499
+ libxml_use_internal_errors($libxml_previous_state);
500
+
501
+ if ( !empty($li_classes) ) {
502
+ $common_li_classes = array_shift($li_classes);
503
+ foreach ($li_classes as $li_class) {
504
+ $common_li_classes = array_intersect($li_class, $common_li_classes);
505
+ }
506
+ $common_li_classes_flat = implode(' ', $common_li_classes);
507
+ } else {
508
+ $common_li_classes_flat = '';
509
+ }
510
+ return $common_li_classes_flat;
511
+ }
512
+
513
+ /**
514
+ * Ajaxify Menu Cart
515
+ */
516
+ public function woocommerce_ajax_fragments( $fragments ) {
517
+ if ( ! defined('WOOCOMMERCE_CART') ) {
518
+ define( 'WOOCOMMERCE_CART', true );
519
+ }
520
+
521
+ $fragments['a.wpmenucart-contents'] = $this->wpmenucart_menu_item();
522
+ return $fragments;
523
+ }
524
+
525
+ /**
526
+ * Create HTML for Menu Cart item
527
+ */
528
+ public function wpmenucart_menu_item() {
529
+ $item_data = $this->shop->menu_item();
530
+
531
+ // Check empty cart settings
532
+ if ($item_data['cart_contents_count'] == 0 && ( !isset($this->options['always_display']) ) ) {
533
+ $empty_menu_item = '<a class="wpmenucart-contents empty-wpmenucart" style="display:none">&nbsp;</a>';
534
+ return $empty_menu_item;
535
+ }
536
+
537
+ if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_t' ) ) {
538
+ //use WPML
539
+ $viewing_cart = icl_t('WP Menu Cart', 'hover text', 'View your shopping cart');
540
+ $start_shopping = icl_t('WP Menu Cart', 'empty hover text', 'Start shopping');
541
+ $cart_contents = $item_data['cart_contents_count'] .' '. ( $item_data['cart_contents_count'] == 1 ? icl_t('WP Menu Cart', 'item text', 'item') : icl_t('WP Menu Cart', 'items text', 'items') );
542
+ } else {
543
+ //use regular WP i18n
544
+ $viewing_cart = __('View your shopping cart', 'wp-menu-cart');
545
+ $start_shopping = __('Start shopping', 'wp-menu-cart');
546
+ $cart_contents = sprintf(_n('%d item', '%d items', $item_data['cart_contents_count'], 'wp-menu-cart'), $item_data['cart_contents_count']);
547
+ }
548
+
549
+ $this->menu_items['menu']['cart_contents'] = $cart_contents;
550
+
551
+ if ($item_data['cart_contents_count'] == 0) {
552
+ $menu_item_href = apply_filters ('wpmenucart_emptyurl', $item_data['shop_page_url'] );
553
+ $menu_item_title = apply_filters ('wpmenucart_emptytitle', $start_shopping );
554
+ $menu_item_classes = 'wpmenucart-contents empty-wpmenucart-visible';
555
+ } else {
556
+ $menu_item_href = apply_filters ('wpmenucart_fullurl', $item_data['cart_url'] );
557
+ $menu_item_title = apply_filters ('wpmenucart_fulltitle', $viewing_cart );
558
+ $menu_item_classes = 'wpmenucart-contents';
559
+ }
560
+
561
+ $this->menu_items['menu']['menu_item_href'] = $menu_item_href;
562
+ $this->menu_items['menu']['menu_item_title'] = $menu_item_title;
563
+
564
+ if(defined('UBERMENU_VERSION') && (version_compare(UBERMENU_VERSION, '3.0.0') >= 0)){
565
+ $menu_item_classes .= ' ubermenu-target';
566
+ }
567
+
568
+ $menu_item = '<a class="'.$menu_item_classes.'" href="'.$menu_item_href.'" title="'.$menu_item_title.'">';
569
+
570
+ $menu_item_a_content = '';
571
+ if (isset($this->options['icon_display'])) {
572
+ $icon = isset($this->options['cart_icon']) ? $this->options['cart_icon'] : '0';
573
+ $menu_item_icon = '<i class="wpmenucart-icon-shopping-cart-'.$icon.'" role="img" aria-label="'.__( 'Cart','woocommerce' ).'"></i>';
574
+ $menu_item_a_content .= $menu_item_icon;
575
+ } else {
576
+ $menu_item_icon = '';
577
+ }
578
+
579
+ switch ($this->options['items_display']) {
580
+ case 1: //items only
581
+ $menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span>';
582
+ break;
583
+ case 2: //price only
584
+ $menu_item_a_content .= '<span class="amount">'.$item_data['cart_total'].'</span>';
585
+ break;
586
+ case 3: //items & price
587
+ $menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span><span class="amount">'.$item_data['cart_total'].'</span>';
588
+ break;
589
+ }
590
+ $menu_item_a_content = apply_filters ('wpmenucart_menu_item_a_content', $menu_item_a_content, $menu_item_icon, $cart_contents, $item_data );
591
+
592
+ $this->menu_items['menu']['menu_item_a_content'] = $menu_item_a_content;
593
+
594
+ $menu_item .= $menu_item_a_content . '</a>';
595
+
596
+ $menu_item = apply_filters ('wpmenucart_menu_item_a', $menu_item, $item_data, $this->options, $menu_item_a_content, $viewing_cart, $start_shopping, $cart_contents);
597
+
598
+ if( !empty( $menu_item ) ) return $menu_item;
599
+ }
600
+
601
+ public function wpmenucart_ajax() {
602
+ check_ajax_referer( 'wpmenucart', 'security' );
603
+
604
+ $variable = $this->wpmenucart_menu_item();
605
+ echo $variable;
606
+ die();
607
+ }
608
+
609
+ }
610
+
611
+ $wpMenuCart = new WpMenuCart();
612
+
613
+ /**
614
+ * Hide notifications
615
+ */
616
+
617
+ if ( ! empty( $_GET['hide_wpmenucart_shop_check'] ) ) {
618
+ update_option( 'wpmenucart_shop_check', 'hide' );
619
  }