-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwp-menu-cart.php
executable file
·655 lines (564 loc) · 22.1 KB
/
wp-menu-cart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
<?php
/**
* Plugin Name: WP Menu Cart
* Plugin URI: www.wpovernight.com/plugins
* 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.
* Version: 2.9.6
* Author: Jeremiah Prummer, Ewout Fernhout
* Author URI: www.wpovernight.com/
* License: GPL2
* Text Domain: wp-menu-cart
* WC requires at least: 2.0.0
* WC tested up to: 4.6.0
*/
class WpMenuCart {
protected $plugin_version = '2.9.6';
public static $plugin_slug;
public static $plugin_basename;
/**
* Construct.
*/
public function __construct() {
self::$plugin_slug = basename(dirname(__FILE__));
self::$plugin_basename = plugin_basename(__FILE__);
$this->options = get_option('wpmenucart');
$this->define( 'WPMENUCART_VERSION', $this->plugin_version );
// load the localisation & classes
add_action( 'plugins_loaded', array( &$this, 'languages' ), 0 ); // or use init?
add_filter( 'load_textdomain_mofile', array( $this, 'textdomain_fallback' ), 10, 2 );
add_action( 'init', array( &$this, 'wpml' ), 0 );
add_action( 'init', array( $this, 'load_classes' ) );
// enqueue scripts & ajax
add_action( 'wp_enqueue_scripts', array( &$this, 'load_scripts_styles' ) ); // Load scripts
add_action( 'wp_ajax_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
add_action( 'wp_ajax_nopriv_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
// add filters to selected menus to add cart item <li>
add_action( 'init', array( $this, 'filter_nav_menus' ) );
// $this->filter_nav_menus();
}
/**
* Define constant if not already set
* @param string $name
* @param string|bool $value
*/
private function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
}
/**
* Load classes
* @return void
*/
public function load_classes() {
include_once( 'includes/wpmenucart-settings.php' );
$this->settings = new WpMenuCart_Settings();
if ( $this->good_to_go() ) {
if (isset($this->options['shop_plugin'])) {
if ( false === $this->is_shop_active( $this->options['shop_plugin'] ) ) {
return;
}
switch ($this->options['shop_plugin']) {
case 'woocommerce':
include_once( 'includes/wpmenucart-woocommerce.php' );
$this->shop = new WPMenuCart_WooCommerce();
if ( !isset($this->options['builtin_ajax']) ) {
if ( defined('WOOCOMMERCE_VERSION') && version_compare( WOOCOMMERCE_VERSION, '2.7', '>=' ) ) {
add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
} else {
add_filter( 'add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
}
}
break;
case 'jigoshop':
include_once( 'includes/wpmenucart-jigoshop.php' );
$this->shop = new WPMenuCart_Jigoshop();
if ( !isset($this->options['builtin_ajax']) ) {
add_filter( 'add_to_cart_fragments', array( &$this, 'woocommerce_ajax_fragments' ) );
}
break;
case 'wp-e-commerce':
include_once( 'includes/wpmenucart-wpec.php' );
$this->shop = new WPMenuCart_WPEC();
break;
case 'eshop':
include_once( 'includes/wpmenucart-eshop.php' );
$this->shop = new WPMenuCart_eShop();
break;
case 'easy-digital-downloads':
include_once( 'includes/wpmenucart-edd.php' );
$this->shop = new WPMenuCart_EDD();
if ( !isset($this->options['builtin_ajax']) ) {
add_action("wp_enqueue_scripts", array( &$this, 'load_edd_ajax' ), 0 );
}
break;
}
if ( isset( $this->options['builtin_ajax'] ) || in_array( $this->options['shop_plugin'], array( 'WP e-Commerce', 'wp-e-commerce', 'eShop', 'eshop' ) ) ) {
add_action("wp_enqueue_scripts", array( &$this, 'load_custom_ajax' ), 0 );
}
}
}
}
/**
* Check if a shop is active or if conflicting old versions of the plugin are active
* @return boolean
*/
public function good_to_go() {
$wpmenucart_shop_check = get_option( 'wpmenucart_shop_check' );
$active_plugins = $this->get_active_plugins();
// check for shop plugins
if ( !$this->is_shop_active() && $wpmenucart_shop_check != 'hide' ) {
add_action( 'admin_notices', array ( $this, 'need_shop' ) );
return FALSE;
}
// check for old versions
if ( count( $this->get_active_old_versions() ) > 0 ) {
add_action( 'admin_notices', array ( $this, 'woocommerce_version_active' ) );
return FALSE;
}
// we made it! good to go :o)
return TRUE;
}
/**
* Return true if one ore more shops are activated.
* @return boolean
*/
public function is_shop_active( $shop = '' ) {
if ( empty($shop) ) {
if ( count( $this->get_active_shops() ) > 0 ) {
return TRUE;
} else {
return FALSE;
}
} else {
switch ( $shop ) {
case 'woocommerce':
return function_exists('WC');
break;
case 'easy-digital-downloads':
return function_exists('EDD');
break;
case 'jigoshop':
return class_exists('jigoshop_cart');
break;
case 'wp-e-commerce':
return function_exists('wpsc_cart_item_count');
break;
case 'eshop':
return !empty($GLOBALS['eshopoptions']);
break;
default:
return false;
break;
}
}
}
/**
* Get an array of all active plugins, including multisite
* @return array active plugin paths
*/
public static function get_active_plugins() {
$active_plugins = (array) apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
if (is_multisite()) {
// get_site_option( 'active_sitewide_plugins', array() ) returns a 'reversed list'
// like [hello-dolly/hello.php] => 1369572703 so we do array_keys to make the array
// compatible with $active_plugins
$active_sitewide_plugins = (array) array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
// merge arrays and remove doubles
$active_plugins = (array) array_unique( array_merge( $active_plugins, $active_sitewide_plugins ) );
}
return $active_plugins;
}
/**
* Get array of active shop plugins
*
* @return array plugin name => plugin path
*/
public static function get_active_shops() {
$active_plugins = self::get_active_plugins();
$shop_plugins = array (
'WooCommerce' => 'woocommerce/woocommerce.php',
'Jigoshop' => 'jigoshop/jigoshop.php',
'WP e-Commerce' => 'wp-e-commerce/wp-shopping-cart.php',
'eShop' => 'eshop/eshop.php',
'Easy Digital Downloads' => 'easy-digital-downloads/easy-digital-downloads.php',
);
// filter shop plugins & add shop names as keys
$active_shop_plugins = array_intersect( $shop_plugins, $active_plugins );
return $active_shop_plugins;
}
/**
* Get array of active old WooCommerce Menu Cart plugins
*
* @return array plugin paths
*/
public function get_active_old_versions() {
$active_plugins = $this->get_active_plugins();
$old_versions = array (
'woocommerce-menu-bar-cart/wc_cart_nav.php', //first version
'woocommerce-menu-bar-cart/woocommerce-menu-cart.php', //last free version
'woocommerce-menu-cart/woocommerce-menu-cart.php', //never actually released? just in case...
'woocommerce-menu-cart-pro/woocommerce-menu-cart-pro.php', //old pro version
);
$active_old_plugins = array_intersect( $old_versions, $active_plugins );
return $active_old_plugins;
}
/**
* Fallback admin notices
*
* @return string Fallack notice.
*/
public function need_shop() {
$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' );
$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' ) );
echo $message;
}
public function woocommerce_version_active() {
$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' );
$message = '<div class="error"><p>' . $error . '</p></div>';
echo $message;
}
/**
* Load translations.
*/
public function languages() {
if ( function_exists( 'determine_locale' ) ) { // WP5.0+
$locale = determine_locale();
} else {
$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
}
$locale = apply_filters( 'plugin_locale', $locale, 'wp-menu-cart' );
/**
* Frontend/global Locale. Looks in:
*
* - WP_LANG_DIR/wp-menu-cart/wp-menu-cart-LOCALE.mo
* - wp-menu-cart/languages/wp-menu-cart-LOCALE.mo (which if not found falls back to:)
* - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
*/
unload_textdomain( 'wp-menu-cart');
load_textdomain( 'wp-menu-cart', WP_LANG_DIR . '/wp-menu-cart/wp-menu-cart-' . $locale . '.mo' );
load_plugin_textdomain( 'wp-menu-cart', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Maintain textdomain compatibility between main plugin (wp-menu-cart) and WooCommerce version (woocommerce-menu-bar-cart)
* so that wordpress.org language packs can be used for both
*/
public function textdomain_fallback( $mofile, $textdomain ) {
$main_domain = 'wp-menu-cart';
$wc_domain = 'woocommerce-menu-bar-cart';
// check if this is filtering the mofile for this plugin
if ( $textdomain === $main_domain ) {
$wc_mofile = str_replace( "{$textdomain}-", "{$wc_domain}-", $mofile ); // with trailing dash to target file and not folder
if ( file_exists( $wc_mofile ) ) {
if (!is_callable('copy')) {
$copy = false;
} elseif ( !file_exists( $mofile ) ) {
$copy = true;
} else { // can copy but file already exists
$wc_file_date = filemtime($wc_mofile);
$main_file_date = filemtime($mofile);
// check if wc file is newer
if ( $wc_file_date && $main_file_date && ( $wc_file_date > $main_file_date ) ) {
$copy = true;
} else {
$copy = false;
}
}
// we have a wc override - copy and use it
if ( $copy && $success = copy( $wc_mofile, $mofile ) ) {
// copy .po too if available
$wc_pofile = substr_replace($wc_mofile,".po",-3);
if (file_exists($wc_pofile)) {
copy($wc_pofile,substr_replace($mofile,".po",-3));
}
return $mofile;
}
return $wc_mofile;
}
}
return $mofile;
}
/**
* Register strings for WPML String Translation
*/
public function wpml() {
if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_register_string' ) ) {
icl_register_string('WP Menu Cart', 'item text', 'item');
icl_register_string('WP Menu Cart', 'items text', 'items');
icl_register_string('WP Menu Cart', 'empty cart text', 'your cart is currently empty');
icl_register_string('WP Menu Cart', 'hover text', 'View your shopping cart');
icl_register_string('WP Menu Cart', 'empty hover text', 'Start shopping');
}
}
/**
* Load custom ajax
*/
public function load_custom_ajax() {
wp_enqueue_script(
'wpmenucart',
plugins_url( '/javascript/wpmenucart.js' , __FILE__ ),
array( 'jquery' ),
WPMENUCART_VERSION,
true
);
// get URL to WordPress ajax handling page
if ( $this->options['shop_plugin'] == 'easy-digital-downloads' && function_exists( 'edd_get_ajax_url' ) ) {
// use EDD function to prevent SSL issues http://git.io/V7w76A
$ajax_url = edd_get_ajax_url();
} else {
$ajax_url = admin_url( 'admin-ajax.php' );
}
wp_localize_script(
'wpmenucart',
'wpmenucart_ajax',
array(
'ajaxurl' => $ajax_url,
'nonce' => wp_create_nonce('wpmenucart')
)
);
}
/**
* Load EDD ajax helper
*/
public function load_edd_ajax() {
wp_enqueue_script(
'wpmenucart-edd-ajax',
plugins_url( '/javascript/wpmenucart-edd-ajax.js', __FILE__ ),
array( 'jquery' ),
WPMENUCART_VERSION
);
wp_localize_script(
'wpmenucart-edd-ajax',
'wpmenucart_ajax',
array(
'ajaxurl' => function_exists( 'edd_get_ajax_url' ) ? edd_get_ajax_url() : admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce('wpmenucart'),
'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
)
);
}
/**
* Load CSS
*/
public function load_scripts_styles() {
if (isset($this->options['icon_display'])) {
wp_enqueue_style( 'wpmenucart-icons', plugins_url( '/css/wpmenucart-icons.css', __FILE__ ), array(), WPMENUCART_VERSION, 'all' );
wp_enqueue_style( 'wpmenucart-font', plugins_url( '/css/wpmenucart-font.css', __FILE__ ), array(), WPMENUCART_VERSION, 'all' );
}
$css = file_exists( get_stylesheet_directory() . '/wpmenucart-main.css' )
? get_stylesheet_directory_uri() . '/wpmenucart-main.css'
: plugins_url( '/css/wpmenucart-main.css', __FILE__ );
wp_enqueue_style( 'wpmenucart', $css, array(), WPMENUCART_VERSION, 'all' );
// Hide built-in theme carts
if ( isset($this->options['hide_theme_cart']) ) {
wp_add_inline_style( 'wpmenucart', '.et-cart-info { display:none !important; } .site-header-cart { display:none !important; }' );
}
//Load Stylesheet if twentytwelve is active
if ( wp_get_theme() == 'Twenty Twelve' ) {
wp_enqueue_style( 'wpmenucart-twentytwelve', plugins_url( '/css/wpmenucart-twentytwelve.css', __FILE__ ), array(), WPMENUCART_VERSION, 'all' );
}
//Load Stylesheet if twentyfourteen is active
if ( wp_get_theme() == 'Twenty Fourteen' ) {
wp_enqueue_style( 'wpmenucart-twentyfourteen', plugins_url( '/css/wpmenucart-twentyfourteen.css', __FILE__ ), array(), WPMENUCART_VERSION, 'all' );
}
// extra script that improves AJAX behavior when 'Always display cart' is disabled
wp_enqueue_script(
'wpmenucart-ajax-assist',
plugins_url( '/javascript/wpmenucart-ajax-assist.js', __FILE__ ),
array( 'jquery' ),
WPMENUCART_VERSION
);
wp_localize_script(
'wpmenucart-ajax-assist',
'wpmenucart_ajax_assist',
array(
'shop_plugin' => isset($this->options['shop_plugin']) ? $this->options['shop_plugin'] : '',
'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
)
);
}
/**
* Add filters to selected menus to add cart item <li>
*/
public function filter_nav_menus() {
// exit if no shop class is active
if ( !isset($this->shop) )
return;
// exit if no menus set
if ( !isset( $this->options['menu_slugs'] ) || empty( $this->options['menu_slugs'] ) )
return;
if ( $this->options['menu_slugs'][1] != '0' ) {
add_filter( 'wp_nav_menu_' . $this->options['menu_slugs'][1] . '_items', array( &$this, 'add_itemcart_to_menu' ) , 10, 2 );
}
}
/**
* Add Menu Cart to menu
*
* @return menu items + Menu Cart item
*/
public function add_itemcart_to_menu( $items ) {
// WooCommerce specific: check if woocommerce cart object is actually loaded
if ( isset($this->options['shop_plugin']) && $this->options['shop_plugin'] == 'woocommerce' ) {
if ( function_exists( 'WC' ) ) {
if ( empty( WC()->cart ) ) {
return $items; // nothing to load data from, return menu without cart item
}
} else {
global $woocommerce;
if ( empty($woocommerce) || !is_object($woocommerce) || !isset($woocommerce->cart) || !is_object($woocommerce->cart) ) {
return $items; // nothing to load data from, return menu without cart item
}
}
}
$classes = 'menu-item wpmenucartli wpmenucart-display-'.$this->options['items_alignment'];
if ($this->get_common_li_classes($items) != '') {
$classes .= ' ' . $this->get_common_li_classes($items);
}
if ( function_exists( 'is_checkout' ) && function_exists( 'is_cart' ) && ( is_checkout() || is_cart() ) && empty($this->options['show_on_cart_checkout_page']) ) {
$classes .= ' hidden-wpmenucart';
}
// Filter for <li> item classes
/* Usage (in the themes functions.php):
add_filter('wpmenucart_menu_item_classes', 'add_wpmenucart_item_class', 1, 1);
function add_wpmenucart_item_class ($classes) {
$classes .= ' yourclass';
return $classes;
}
*/
$classes = apply_filters( 'wpmenucart_menu_item_classes', $classes );
$this->menu_items['menu']['menu_item_li_classes'] = $classes;
// DEPRECATED: These filters are now deprecated in favour of the more precise filters in the functions!
$wpmenucart_menu_item = apply_filters( 'wpmenucart_menu_item_filter', $this->wpmenucart_menu_item() );
$item_data = $this->shop->menu_item();
$menu_item_li = '<li class="'.$classes.'" id="wpmenucartli">' . $wpmenucart_menu_item . '</li>';
if ( apply_filters('wpmenucart_prepend_menu_item', false) ) {
$items = apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li ) . $items;
} else {
$items .= apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li );
}
return $items;
}
/**
* Get a flat list of common classes from all menu items in a menu
* @param string $items nav_menu HTML containing all <li> menu items
* @return string flat (imploded) list of common classes
*/
public function get_common_li_classes($items) {
if (empty($items)) return '';
if (!class_exists('DOMDocument')) return '';
$libxml_previous_state = libxml_use_internal_errors(true); // enable user error handling
$dom_items = new DOMDocument;
$dom_items->loadHTML( $items );
$lis = $dom_items->getElementsByTagName('li');
if (empty($lis)) {
libxml_clear_errors();
libxml_use_internal_errors($libxml_previous_state);
return;
}
foreach($lis as $li) {
if ($li->parentNode->tagName != 'ul')
$li_classes[] = explode( ' ', $li->getAttribute('class') );
}
// Uncomment to dump DOM errors / warnings
//$errors = libxml_get_errors();
//print_r ($errors);
// clear errors and reset to previous error handling state
libxml_clear_errors();
libxml_use_internal_errors($libxml_previous_state);
if ( !empty($li_classes) ) {
$common_li_classes = array_shift($li_classes);
foreach ($li_classes as $li_class) {
$common_li_classes = array_intersect($li_class, $common_li_classes);
}
$common_li_classes_flat = implode(' ', $common_li_classes);
} else {
$common_li_classes_flat = '';
}
return $common_li_classes_flat;
}
/**
* Ajaxify Menu Cart
*/
public function woocommerce_ajax_fragments( $fragments ) {
if ( ! defined('WOOCOMMERCE_CART') ) {
define( 'WOOCOMMERCE_CART', true );
}
$fragments['a.wpmenucart-contents'] = $this->wpmenucart_menu_item();
return $fragments;
}
/**
* Create HTML for Menu Cart item
*/
public function wpmenucart_menu_item() {
$item_data = $this->shop->menu_item();
// Check empty cart settings
if ($item_data['cart_contents_count'] == 0 && ( !isset($this->options['always_display']) ) ) {
$empty_menu_item = '<a class="wpmenucart-contents empty-wpmenucart" style="display:none"> </a>';
return $empty_menu_item;
}
if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_t' ) ) {
//use WPML
$viewing_cart = icl_t('WP Menu Cart', 'hover text', 'View your shopping cart');
$start_shopping = icl_t('WP Menu Cart', 'empty hover text', 'Start shopping');
$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') );
} else {
//use regular WP i18n
$viewing_cart = __('View your shopping cart', 'wp-menu-cart');
$start_shopping = __('Start shopping', 'wp-menu-cart');
$cart_contents = sprintf(_n('%d item', '%d items', $item_data['cart_contents_count'], 'wp-menu-cart'), $item_data['cart_contents_count']);
}
$this->menu_items['menu']['cart_contents'] = $cart_contents;
if ($item_data['cart_contents_count'] == 0) {
$menu_item_href = apply_filters ('wpmenucart_emptyurl', $item_data['shop_page_url'] );
$menu_item_title = apply_filters ('wpmenucart_emptytitle', $start_shopping );
$menu_item_classes = 'wpmenucart-contents empty-wpmenucart-visible';
} else {
$menu_item_href = apply_filters ('wpmenucart_fullurl', $item_data['cart_url'] );
$menu_item_title = apply_filters ('wpmenucart_fulltitle', $viewing_cart );
$menu_item_classes = 'wpmenucart-contents';
}
$this->menu_items['menu']['menu_item_href'] = $menu_item_href;
$this->menu_items['menu']['menu_item_title'] = $menu_item_title;
if(defined('UBERMENU_VERSION') && (version_compare(UBERMENU_VERSION, '3.0.0') >= 0)){
$menu_item_classes .= ' ubermenu-target';
}
$menu_item = '<a class="'.$menu_item_classes.'" href="'.$menu_item_href.'" title="'.$menu_item_title.'">';
$menu_item_a_content = '';
if (isset($this->options['icon_display'])) {
$icon = isset($this->options['cart_icon']) ? $this->options['cart_icon'] : '0';
$menu_item_icon = '<i class="wpmenucart-icon-shopping-cart-'.$icon.'" role="img" aria-label="'.__( 'Cart','woocommerce' ).'"></i>';
$menu_item_a_content .= $menu_item_icon;
} else {
$menu_item_icon = '';
}
switch ($this->options['items_display']) {
case 1: //items only
$menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span>';
break;
case 2: //price only
$menu_item_a_content .= '<span class="amount">'.$item_data['cart_total'].'</span>';
break;
case 3: //items & price
$menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span><span class="amount">'.$item_data['cart_total'].'</span>';
break;
}
$menu_item_a_content = apply_filters ('wpmenucart_menu_item_a_content', $menu_item_a_content, $menu_item_icon, $cart_contents, $item_data );
$this->menu_items['menu']['menu_item_a_content'] = $menu_item_a_content;
$menu_item .= $menu_item_a_content . '</a>';
$menu_item = apply_filters ('wpmenucart_menu_item_a', $menu_item, $item_data, $this->options, $menu_item_a_content, $viewing_cart, $start_shopping, $cart_contents);
if( !empty( $menu_item ) ) return $menu_item;
}
public function wpmenucart_ajax() {
check_ajax_referer( 'wpmenucart', 'security' );
$variable = $this->wpmenucart_menu_item();
echo $variable;
die();
}
}
$wpMenuCart = new WpMenuCart();
/**
* Hide notifications
*/
if ( ! empty( $_GET['hide_wpmenucart_shop_check'] ) ) {
update_option( 'wpmenucart_shop_check', 'hide' );
}