YITH WooCommerce Catalog Mode - Version 1.3.0

Version Description

Last Stable Tag 1.3.0

Download this release

Release Info

Developer yithemes
Plugin Icon 128x128 YITH WooCommerce Catalog Mode
Version 1.3.0
Comparing to
See all releases

Code changes from version 1.2.4 to 1.3.0

class.yith-woocommerce-catalog-mode.php CHANGED
@@ -4,75 +4,103 @@ if ( !defined( 'ABSPATH' ) ) {
4
  exit;
5
  } // Exit if accessed directly
6
 
7
- /**
8
- * Implements features of YITH WooCommerce Catalog Mode plugin
9
- *
10
- * @class YITH_WC_Catalog_Mode
11
- * @package Yithemes
12
- * @since 1.0.0
13
- * @author Your Inspiration Themes
14
- */
15
- class YITH_WC_Catalog_Mode {
16
 
17
  /**
18
- * Panel object
19
  *
20
- * @var /Yit_Plugin_Panel object
 
21
  * @since 1.0.0
22
- * @see plugin-fw/lib/yit-plugin-panel.php
23
  */
24
- protected $_panel;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- /**
27
- * @var $_premium string Premium tab template file name
28
- */
29
- protected $_premium = 'premium.php';
30
-
31
- /**
32
- * @var string Premium version landing link
33
- */
34
- protected $_premium_landing = 'http://yithemes.com/themes/plugins/yith-woocommerce-catalog-mode/';
35
 
36
- /**
37
- * @var string Plugin official documentation
38
- */
39
- protected $_official_documentation = 'http://yithemes.com/docs-plugins/yith-woocommerce-catalog-mode/';
40
 
41
- /**
42
- * @var string Yith WooCommerce Catalog Mode panel page
43
- */
44
- protected $_panel_page = 'yith_wc_catalog_mode_panel';
45
-
46
- /**
47
- * Constructor
48
- *
49
- * Initialize plugin and registers actions and filters to be used
50
- *
51
- * @since 1.0.0
52
- * @return mixed
53
- * @author Alberto Ruggiero
54
- */
55
- public function __construct() {
56
- if ( !function_exists( 'WC' ) ) {
57
- return;
58
  }
59
 
60
- // Load Plugin Framework
61
- add_action( 'plugins_loaded', array( $this, 'plugin_fw_loader' ), 12 );
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- //Add action links
64
- add_filter( 'plugin_action_links_' . plugin_basename( YWCTM_DIR . '/' . basename( YWCTM_FILE ) ), array( $this, 'action_links' ) );
65
- add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 );
66
 
67
- // Add stylesheets and scripts files
68
- add_action( 'admin_menu', array( $this, 'add_menu_page' ), 5 );
69
- add_action( 'yith_catalog_mode_premium', array( $this, 'premium_tab' ) );
70
 
71
- if ( get_option( 'ywctm_enable_plugin' ) == 'yes' ) {
 
 
72
 
73
- if ( $this->check_user_admin_enable() ) {
74
 
75
  if ( !is_admin() || $this->is_quick_view() ) {
 
76
  if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
77
 
78
  $priority = has_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ) );
@@ -85,12 +113,10 @@ class YITH_WC_Catalog_Mode {
85
  add_action( 'woocommerce_single_product_summary', array( $this, 'hide_add_to_cart_single' ), 10 );
86
  add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'hide_add_to_cart_loop' ), 5 );
87
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
88
-
89
  add_filter( 'woocommerce_add_to_cart_validation', array( $this, 'avoid_add_to_cart' ), 10, 2 );
90
 
91
  if ( defined( 'YITH_WCWL' ) && YITH_WCWL ) {
92
  add_filter( 'woocommerce_loop_add_to_cart_link', array( $this, 'hide_add_to_cart_wishlist' ), 10, 2 );
93
-
94
  }
95
 
96
  }
@@ -99,694 +125,666 @@ class YITH_WC_Catalog_Mode {
99
 
100
  }
101
 
102
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
- /**
105
- * ADMIN FUNCTIONS
106
- */
107
 
108
- /**
109
- * Add a panel under YITH Plugins tab
110
- *
111
- * @since 1.0.0
112
- * @return void
113
- * @author Alberto Ruggiero
114
- * @use /Yit_Plugin_Panel class
115
- * @see plugin-fw/lib/yit-plugin-panel.php
116
- */
117
- public function add_menu_page() {
118
-
119
- if ( !empty( $this->_panel ) ) {
120
- return;
121
- }
122
 
123
- $admin_tabs = array();
 
 
124
 
125
- if ( defined( 'YWCTM_PREMIUM' ) ) {
126
- $admin_tabs['premium-settings'] = __( 'Settings', 'yith-woocommerce-catalog-mode' );
127
- $admin_tabs['exclusions'] = __( 'Exclusion List', 'yith-woocommerce-catalog-mode' );
128
- $admin_tabs['custom-url'] = __( 'Custom Button Url List', 'yith-woocommerce-catalog-mode' );
129
- }
130
- else {
131
- $admin_tabs['settings'] = __( 'Settings', 'yith-woocommerce-catalog-mode' );
132
- $admin_tabs['premium-landing'] = __( 'Premium Version', 'yith-woocommerce-catalog-mode' );
133
- }
134
 
135
- $args = array(
136
- 'create_menu_page' => true,
137
- 'parent_slug' => '',
138
- 'page_title' => __( 'Catalog Mode', 'yith-woocommerce-catalog-mode' ),
139
- 'menu_title' => __( 'Catalog Mode', 'yith-woocommerce-catalog-mode' ),
140
- 'capability' => 'manage_options',
141
- 'parent' => '',
142
- 'parent_page' => 'yit_plugin_panel',
143
- 'page' => $this->_panel_page,
144
- 'admin-tabs' => $admin_tabs,
145
- 'options-path' => YWCTM_DIR . '/plugin-options'
146
- );
147
-
148
- $this->_panel = new YIT_Plugin_Panel_WooCommerce( $args );
149
- }
150
 
151
- /**
152
- * FRONTEND FUNCTIONS
153
- */
 
 
 
 
 
 
 
 
 
154
 
155
- /**
156
- * Check if catalog mode is enabled for administrator
157
- *
158
- * @since 1.0.2
159
- * @return bool
160
- * @author Alberto Ruggiero
161
- */
162
- public function check_user_admin_enable() {
163
 
164
- return !( current_user_can( 'administrator' ) && is_user_logged_in() && get_option( 'ywctm_admin_view' ) == 'no' );
 
 
165
 
166
- }
 
 
 
 
 
 
 
 
 
 
167
 
168
- /**
169
- * Checks if "Cart & Checkout pages" needs to be hidden
170
- *
171
- * @since 1.0.2
172
- * @return bool
173
- * @author Alberto Ruggiero
174
- */
175
- public function check_hide_cart_checkout_pages() {
176
 
177
- return get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() && get_option( 'ywctm_hide_cart_header' ) == 'yes';
178
 
179
- }
180
 
181
- /**
182
- * Hides "Add to cart" button from single product page
183
- *
184
- * @since 1.0.0
185
- *
186
- * @param $action
187
- *
188
- * @return void
189
- * @author Alberto Ruggiero
190
- */
191
- public function hide_add_to_cart_single( $action = '' ) {
192
 
193
- if ( $action == '' ) {
194
- $action = 'woocommerce_single_product_summary';
195
- }
196
 
197
- $priority = has_action( $action, 'woocommerce_template_single_add_to_cart' );
 
198
 
199
- if ( $this->check_add_to_cart_single( $priority ) ) {
200
 
201
- add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'hide_add_to_cart_quick_view' ), 10 );
202
 
203
  }
204
 
205
- }
206
-
207
- /**
208
- * Hide add to cart button in quick view
209
- *
210
- * @since 1.0.7
211
- * @return mixed
212
- * @author Francesco Licandro
213
- */
214
- public function hide_add_to_cart_quick_view() {
215
 
216
- $hide_variations = get_option( 'ywctm_hide_variations' );
217
- ob_start();
218
 
219
- $args = array(
220
- 'form.cart button.single_add_to_cart_button'
221
- );
222
 
223
- if ( !class_exists( 'YITH_YWRAQ_Frontend' ) ) {
 
 
 
 
 
 
 
224
 
225
- $args[] = 'form.cart .quantity';
226
 
227
  }
228
 
229
- if ( $hide_variations == 'yes' ) {
230
-
231
- $args[] = 'table.variations';
232
- $args[] = 'form.variations_form';
233
- $args[] = '.single_variation_wrap .variations_button';
 
 
 
 
 
 
 
 
 
 
234
 
235
- }
236
 
237
- $classes = implode( ', ', apply_filters( 'ywctm_catalog_classes', $args ) );
238
 
239
- ?>
240
- <style>
241
 
242
- <?php echo $classes; ?>
243
- {
244
- display: none !important
245
  }
246
 
247
- </style>
248
- <?php
249
- echo ob_get_clean();
250
 
251
- }
 
 
 
 
 
 
 
252
 
253
- /**
254
- * Check if price is hidden to hide add to cart button
255
- *
256
- * @since 1.0.4
257
- *
258
- * @param $post_id
259
- *
260
- * @return bool
261
- * @author Alberto Ruggiero
262
- */
263
- public function check_price_hidden( $post_id ) {
264
 
265
- $hide = false;
 
 
266
 
267
- if ( get_option( 'ywctm_hide_price' ) == 'yes' ) {
268
 
269
- $ywctm_hide_price_users = ( get_option( 'ywctm_hide_price_users' ) != 'unregistered' ) ? true : false;
270
- $user_logged = is_user_logged_in();
271
 
272
- if ( !( !$ywctm_hide_price_users && $user_logged ) ) {
273
 
274
- $exclude_catalog = get_post_meta( $post_id, '_ywctm_exclude_hide_price', true );
275
- $enable_exclusion = get_option( 'ywctm_exclude_hide_price' );
276
 
277
- if ( $enable_exclusion == '' || $enable_exclusion == 'no' ) {
 
 
278
 
279
- $hide = true;
280
 
 
 
 
 
 
 
 
 
281
  }
282
- else {
283
 
284
- if ( $exclude_catalog == '' || $exclude_catalog == 'no' ) {
 
 
285
 
286
- $hide = true;
287
 
288
- }
 
 
 
 
 
 
 
 
 
 
289
 
290
- }
291
 
292
- $reverse_criteria = get_option( 'ywctm_exclude_hide_price_reverse' );
293
 
294
- if ( $reverse_criteria == 'yes' ) {
295
 
296
- $hide = !$hide;
297
 
298
- }
 
299
 
300
- }
301
 
302
- }
303
 
304
- return $hide;
305
 
306
- }
307
 
308
- /**
309
- * Checks if "Add to cart" needs to be hidden
310
- *
311
- * @since 1.0.2
312
- *
313
- * @param $priority
314
- * @param $product_id
315
- *
316
- * @return bool
317
- * @author Alberto Ruggiero
318
- */
319
- public function check_add_to_cart_single( $priority = true, $product_id = false ) {
320
 
321
- $hide = false;
322
 
323
- if ( get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() ) {
324
 
325
- if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
326
 
327
- $hide = true;
328
 
329
- }
330
- else {
 
 
 
 
 
 
 
 
 
 
331
 
332
- global $post;
333
 
334
- if ( !$product_id && !isset( $post ) ) {
335
- return false;
336
- }
337
 
338
- $post_id = ( $product_id ) ? $product_id : $post->ID;
339
 
340
- if ( get_option( 'ywctm_hide_add_to_cart_single' ) == 'yes' ) {
341
 
342
- $ywctm_hide_price_users = ( get_option( 'ywctm_hide_price_users' ) != 'unregistered' ) ? true : false;
343
- $user_logged = is_user_logged_in();
344
 
345
- if ( !( !$ywctm_hide_price_users && $user_logged ) ) {
346
 
347
- $exclude_catalog = get_post_meta( $post_id, '_ywctm_exclude_catalog_mode', true );
348
- $enable_exclusion = get_option( 'ywctm_exclude_hide_add_to_cart' );
 
349
 
350
- if ( $priority ) {
351
 
352
- if ( $enable_exclusion == '' || $enable_exclusion == 'no' ) {
353
 
354
- $hide = true;
355
 
356
- }
357
- else {
358
 
359
- if ( $exclude_catalog == '' || $exclude_catalog == 'no' ) {
 
360
 
361
- $hide = true;
362
 
363
- }
364
 
365
  }
366
 
367
- }
368
 
369
- $reverse_criteria = get_option( 'ywctm_exclude_hide_add_to_cart_reverse' );
370
 
371
- if ( $reverse_criteria == 'yes' ) {
372
 
373
- $hide = !$hide;
374
 
375
  }
376
 
377
  }
378
 
379
- }
380
 
381
- if ( $this->check_price_hidden( $post_id ) ) {
382
 
383
- $hide = true;
384
 
385
  }
386
 
387
  }
388
 
389
- }
390
-
391
- return $hide;
392
- }
393
 
394
- /**
395
- * Checks if "Add to cart" needs to be avoided
396
- *
397
- * @since 1.0.5
398
- *
399
- * @param $passed
400
- * @param $product_id
401
- *
402
- * @return bool
403
- * @author Alberto Ruggiero
404
- */
405
- public function avoid_add_to_cart( $passed, $product_id ) {
406
 
407
- if ( get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() ) {
 
 
 
 
 
 
 
 
 
 
 
408
 
409
- if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
410
 
411
- $passed = false;
412
 
413
- }
414
- else {
415
 
416
- if ( get_option( 'ywctm_hide_add_to_cart_single' ) == 'yes' ) {
 
417
 
418
- $ywctm_hide_price_users = ( get_option( 'ywctm_hide_price_users' ) != 'unregistered' ) ? true : false;
419
- $user_logged = is_user_logged_in();
420
 
421
- if ( !( !$ywctm_hide_price_users && $user_logged ) ) {
422
 
423
- $exclude_catalog = get_post_meta( $product_id, '_ywctm_exclude_catalog_mode', true );
424
- $enable_exclusion = get_option( 'ywctm_exclude_hide_add_to_cart' );
425
 
426
- if ( $enable_exclusion == '' || $enable_exclusion == 'no' ) {
 
427
 
428
- $passed = false;
429
 
430
- }
431
- else {
432
 
433
- if ( $exclude_catalog == '' || $exclude_catalog == 'no' ) {
434
 
435
- $passed = false;
436
 
437
  }
438
 
439
  }
440
 
441
- $reverse_criteria = get_option( 'ywctm_exclude_hide_add_to_cart_reverse' );
442
-
443
- if ( $reverse_criteria == 'yes' ) {
444
-
445
- $passed = !$passed;
446
-
447
- }
448
-
449
  }
450
 
451
- }
452
 
453
- if ( $this->check_price_hidden( $product_id ) ) {
454
 
455
- $passed = false;
456
 
457
  }
458
 
459
  }
460
 
 
461
  }
462
 
463
- return $passed;
464
- }
465
-
466
- /**
467
- * Checks if "Add to cart" needs to be hidden from loop page
468
- *
469
- * @since 1.0.6
470
- * @return bool
471
- * @author Alberto Ruggiero
472
- */
473
- public function check_hide_add_cart_loop() {
474
 
475
- $remove = false;
476
 
477
- if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
478
-
479
- $remove = true;
480
-
481
- }
482
- else {
483
 
484
- global $post;
485
 
486
- if ( get_option( 'ywctm_hide_add_to_cart_loop' ) == 'yes' ) {
 
487
 
488
- $ywctm_hide_price_users = ( get_option( 'ywctm_hide_price_users' ) != 'unregistered' ) ? true : false;
489
- $user_logged = is_user_logged_in();
490
 
491
- if ( !( !$ywctm_hide_price_users && $user_logged ) ) {
492
 
493
- $exclude_catalog = get_post_meta( $post->ID, '_ywctm_exclude_catalog_mode', true );
494
- $enable_exclusion = get_option( 'ywctm_exclude_hide_add_to_cart' );
495
 
496
- if ( $enable_exclusion == '' || $enable_exclusion == 'no' ) {
497
 
498
- $remove = true;
 
499
 
500
- }
501
- else {
502
 
503
- if ( $exclude_catalog == '' || $exclude_catalog == 'no' ) {
504
 
505
- $remove = true;
506
 
507
- }
508
- else {
509
 
510
- $remove = false;
511
 
512
  }
513
 
514
- }
515
-
516
- $product = wc_get_product( $post );
517
 
518
- if ( $product->product_type == 'variable' ) {
519
-
520
- if ( get_option( 'ywctm_hide_variations' ) == 'yes' ) {
521
-
522
- $remove = true;
523
-
524
- }
525
- else {
526
 
527
- $remove = false;
528
 
529
  }
530
 
531
  }
532
 
533
- $reverse_criteria = get_option( 'ywctm_exclude_hide_add_to_cart_reverse' );
534
-
535
- if ( $reverse_criteria == 'yes' ) {
536
 
537
- $remove = !$remove;
538
 
539
- }
540
 
541
  }
542
 
543
- }
544
-
545
- if ( $this->check_price_hidden( $post->ID ) ) {
546
-
547
- $remove = true;
548
 
549
  }
550
 
551
-
552
  }
553
 
554
- return $remove;
555
- }
 
 
 
 
 
 
556
 
557
- /**
558
- * Hides "Add to cart" button, if not excluded, from loop page
559
- *
560
- * @since 1.0.0
561
- * @return void
562
- * @author Alberto Ruggiero
563
- */
564
- public function hide_add_to_cart_loop() {
565
 
566
- if ( $this->check_hide_add_cart_loop() ) {
 
567
 
568
- remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
569
- add_filter( 'woocommerce_loop_add_to_cart_link', '__return_empty_string', 10 );
570
 
571
- }
572
- else {
573
 
574
- add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
575
- remove_filter( 'woocommerce_loop_add_to_cart_link', '__return_empty_string', 10 );
576
 
577
  }
578
 
579
- }
 
 
 
 
 
 
 
 
 
 
 
580
 
581
- /**
582
- * Enqueue css file
583
- *
584
- * @since 1.0.0
585
- * @return void
586
- * @author Alberto Ruggiero
587
- */
588
- public function enqueue_styles() {
589
- if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
590
- wp_enqueue_style( 'ywctm-style', YWCTM_ASSETS_URL . '/css/yith-catalog-mode.css' );
591
  }
592
 
593
- }
 
 
 
 
 
 
 
594
 
595
- /**
596
- * Avoid Cart and Checkout Pages to be visited
597
- *
598
- * @since 1.0.4
599
- * @return void
600
- * @author Alberto Ruggiero
601
- */
602
- public function check_pages_redirect() {
603
 
604
- if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
 
605
 
606
- $cart = is_page( wc_get_page_id( 'cart' ) );
607
- $checkout = is_page( wc_get_page_id( 'checkout' ) );
608
 
609
- wp_reset_query();
610
 
611
- if ( $cart || $checkout ) {
 
612
 
613
- wp_redirect( home_url() );
614
- exit;
615
 
616
  }
617
 
618
  }
619
 
620
- }
 
 
 
 
 
 
 
 
 
 
621
 
622
- /**
623
- * Removes Cart and checkout pages from menu
624
- *
625
- * @since 1.0.4
626
- *
627
- * @param $pages
628
- *
629
- * @return mixed
630
- * @author Alberto Ruggiero
631
- */
632
- public function hide_cart_checkout_pages( $pages ) {
633
 
634
- if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
 
 
 
635
 
636
- $excluded_pages = array(
637
- wc_get_page_id( 'cart' ),
638
- wc_get_page_id( 'checkout' )
639
- );
640
 
641
- for ( $i = 0; $i < count( $pages ); $i ++ ) {
642
- $page = &$pages[$i];
643
 
644
- if ( in_array( $page->ID, $excluded_pages ) ) {
645
 
646
- unset( $pages[$i] );
647
 
648
  }
649
 
650
  }
651
 
 
 
652
  }
653
 
654
- return $pages;
 
 
 
 
 
 
 
 
 
655
 
656
- }
 
 
 
 
 
 
 
 
 
 
 
657
 
658
- /**
659
- * Say if the code is execute by quick view
660
- *
661
- * @since 1.0.7
662
- * @return bool
663
- * @author Andrea Frascaspata <andrea.frascaspata@yithemes.com>
664
- */
665
- public function is_quick_view() {
666
- return defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && ( $_REQUEST['action'] == 'yith_load_product_quick_view' || $_REQUEST['action'] == 'yit_load_product_quick_view' );
667
- }
668
 
669
- /**
670
- * Hides add to cart on wishlist
671
- *
672
- * @since 1.2.2
673
- *
674
- * @param $value
675
- * @param $product
676
- *
677
- * @return string
678
- * @author Alberto Ruggiero
679
- */
680
- public function hide_add_to_cart_wishlist( $value, $product ) {
681
 
682
- global $yith_wcwl_is_wishlist;
683
 
684
- if ( $this->check_add_to_cart_single( true, $product->id ) && $yith_wcwl_is_wishlist ) {
685
 
686
- $value = '';
687
 
688
  }
689
 
690
- return $value;
691
-
692
- }
693
-
694
- /**
695
- * YITH FRAMEWORK
696
- */
697
-
698
- /**
699
- * Load plugin framework
700
- *
701
- * @since 1.0.0
702
- * @return void
703
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
704
- */
705
- public function plugin_fw_loader() {
706
- if ( !defined( 'YIT_CORE_PLUGIN' ) ) {
707
- global $plugin_fw_data;
708
- if ( !empty( $plugin_fw_data ) ) {
709
- $plugin_fw_file = array_shift( $plugin_fw_data );
710
- require_once( $plugin_fw_file );
711
  }
712
  }
713
- }
714
 
715
- /**
716
- * Premium Tab Template
717
- *
718
- * Load the premium tab template on admin page
719
- *
720
- * @since 1.0.0
721
- * @return void
722
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
723
- */
724
- public function premium_tab() {
725
- $premium_tab_template = YWCTM_TEMPLATE_PATH . '/admin/' . $this->_premium;
726
- if ( file_exists( $premium_tab_template ) ) {
727
- include_once( $premium_tab_template );
 
728
  }
729
- }
730
 
731
- /**
732
- * Get the premium landing uri
733
- *
734
- * @since 1.0.0
735
- * @return string The premium landing link
736
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
737
- */
738
- public function get_premium_landing_uri() {
739
- return defined( 'YITH_REFER_ID' ) ? $this->_premium_landing . '?refer_id=' . YITH_REFER_ID : $this->_premium_landing;
740
- }
741
-
742
- /**
743
- * Action Links
744
- *
745
- * add the action links to plugin admin page
746
- * @since 1.0.0
747
- *
748
- * @param $links | links plugin array
749
- *
750
- * @return mixed
751
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
752
- * @use plugin_action_links_{$plugin_file_name}
753
- */
754
- public function action_links( $links ) {
755
 
756
- $links[] = '<a href="' . admin_url( "admin.php?page={$this->_panel_page}" ) . '">' . __( 'Settings', 'yith-woocommerce-catalog-mode' ) . '</a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
757
 
758
- if ( defined( 'YWCTM_FREE_INIT' ) ) {
759
- $links[] = '<a href="' . $this->get_premium_landing_uri() . '" target="_blank">' . __( 'Premium Version', 'yith-woocommerce-catalog-mode' ) . '</a>';
760
  }
761
 
762
- return $links;
763
- }
764
-
765
- /**
766
- * Plugin row meta
767
- *
768
- * add the action links to plugin admin page
769
- *
770
- * @since 1.0.0
771
- *
772
- * @param $plugin_meta
773
- * @param $plugin_file
774
- * @param $plugin_data
775
- * @param $status
776
- *
777
- * @return Array
778
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
779
- * @use plugin_row_meta
780
- */
781
- public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
782
- if ( ( defined( 'YWCTM_INIT' ) && ( YWCTM_INIT == $plugin_file ) ) ||
783
- ( defined( 'YWCTM_FREE_INIT' ) && ( YWCTM_FREE_INIT == $plugin_file ) )
784
- ) {
785
 
786
- $plugin_meta[] = '<a href="' . $this->_official_documentation . '" target="_blank">' . __( 'Plugin Documentation', 'yith-woocommerce-catalog-mode' ) . '</a>';
787
  }
788
 
789
- return $plugin_meta;
790
  }
791
 
792
  }
4
  exit;
5
  } // Exit if accessed directly
6
 
7
+ if ( !class_exists( 'YITH_WC_Catalog_Mode' ) ) {
 
 
 
 
 
 
 
 
8
 
9
  /**
10
+ * Implements features of YITH WooCommerce Catalog Mode plugin
11
  *
12
+ * @class YITH_WC_Catalog_Mode
13
+ * @package Yithemes
14
  * @since 1.0.0
15
+ * @author Your Inspiration Themes
16
  */
17
+ class YITH_WC_Catalog_Mode {
18
+
19
+ /**
20
+ * Panel object
21
+ *
22
+ * @var /Yit_Plugin_Panel object
23
+ * @since 1.0.0
24
+ * @see plugin-fw/lib/yit-plugin-panel.php
25
+ */
26
+ protected $_panel;
27
+
28
+ /**
29
+ * @var $_premium string Premium tab template file name
30
+ */
31
+ protected $_premium = 'premium.php';
32
+
33
+ /**
34
+ * @var string Premium version landing link
35
+ */
36
+ protected $_premium_landing = 'http://yithemes.com/themes/plugins/yith-woocommerce-catalog-mode/';
37
+
38
+ /**
39
+ * @var string Plugin official documentation
40
+ */
41
+ protected $_official_documentation = 'http://yithemes.com/docs-plugins/yith-woocommerce-catalog-mode/';
42
+
43
+ /**
44
+ * @var string Yith WooCommerce Catalog Mode panel page
45
+ */
46
+ protected $_panel_page = 'yith_wc_catalog_mode_panel';
47
+
48
+ /**
49
+ * Single instance of the class
50
+ *
51
+ * @var \YITH_WC_Catalog_Mode
52
+ * @since 1.3.0
53
+ */
54
+ protected static $instance;
55
+
56
+ /**
57
+ * Returns single instance of the class
58
+ *
59
+ * @return \YITH_WC_Catalog_Mode
60
+ * @since 1.3.0
61
+ */
62
+ public static function get_instance() {
63
+
64
+ if ( is_null( self::$instance ) ) {
65
+
66
+ self::$instance = new self;
67
 
68
+ }
 
 
 
 
 
 
 
 
69
 
70
+ return self::$instance;
 
 
 
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
 
74
+ /**
75
+ * Constructor
76
+ *
77
+ * Initialize plugin and registers actions and filters to be used
78
+ *
79
+ * @since 1.0.0
80
+ * @return mixed
81
+ * @author Alberto Ruggiero
82
+ */
83
+ public function __construct() {
84
+
85
+ if ( !function_exists( 'WC' ) ) {
86
+ return;
87
+ }
88
 
89
+ // Load Plugin Framework
90
+ add_action( 'plugins_loaded', array( $this, 'plugin_fw_loader' ), 12 );
 
91
 
92
+ //Add action links
93
+ add_filter( 'plugin_action_links_' . plugin_basename( YWCTM_DIR . '/' . basename( YWCTM_FILE ) ), array( $this, 'action_links' ) );
94
+ add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 );
95
 
96
+ // Add stylesheets and scripts files
97
+ add_action( 'admin_menu', array( $this, 'add_menu_page' ), 5 );
98
+ add_action( 'yith_catalog_mode_premium', array( $this, 'premium_tab' ) );
99
 
100
+ if ( get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() ) {
101
 
102
  if ( !is_admin() || $this->is_quick_view() ) {
103
+
104
  if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
105
 
106
  $priority = has_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ) );
113
  add_action( 'woocommerce_single_product_summary', array( $this, 'hide_add_to_cart_single' ), 10 );
114
  add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'hide_add_to_cart_loop' ), 5 );
115
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
 
116
  add_filter( 'woocommerce_add_to_cart_validation', array( $this, 'avoid_add_to_cart' ), 10, 2 );
117
 
118
  if ( defined( 'YITH_WCWL' ) && YITH_WCWL ) {
119
  add_filter( 'woocommerce_loop_add_to_cart_link', array( $this, 'hide_add_to_cart_wishlist' ), 10, 2 );
 
120
  }
121
 
122
  }
125
 
126
  }
127
 
128
+ /**
129
+ * ADMIN FUNCTIONS
130
+ */
131
+
132
+ /**
133
+ * Add a panel under YITH Plugins tab
134
+ *
135
+ * @since 1.0.0
136
+ * @return void
137
+ * @author Alberto Ruggiero
138
+ * @use /Yit_Plugin_Panel class
139
+ * @see plugin-fw/lib/yit-plugin-panel.php
140
+ */
141
+ public function add_menu_page() {
142
+
143
+ if ( !empty( $this->_panel ) ) {
144
+ return;
145
+ }
146
 
147
+ $admin_tabs = array();
 
 
148
 
149
+ if ( defined( 'YWCTM_PREMIUM' ) ) {
150
+ $admin_tabs['premium-settings'] = __( 'Settings', 'yith-woocommerce-catalog-mode' );
151
+ $admin_tabs['exclusions'] = __( 'Exclusion List', 'yith-woocommerce-catalog-mode' );
152
+ $admin_tabs['custom-url'] = __( 'Custom Button Url List', 'yith-woocommerce-catalog-mode' );
 
 
 
 
 
 
 
 
 
 
153
 
154
+ if ( YITH_WCTM()->is_multivendor_active() ) {
155
+ $admin_tabs['vendors'] = __( 'Vendor Exclusion List', 'yith-woocommerce-catalog-mode' );
156
+ }
157
 
158
+ }
159
+ else {
160
+ $admin_tabs['settings'] = __( 'Settings', 'yith-woocommerce-catalog-mode' );
161
+ $admin_tabs['premium-landing'] = __( 'Premium Version', 'yith-woocommerce-catalog-mode' );
162
+ }
 
 
 
 
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
+ $args = array(
166
+ 'create_menu_page' => true,
167
+ 'parent_slug' => '',
168
+ 'page_title' => __( 'Catalog Mode', 'yith-woocommerce-catalog-mode' ),
169
+ 'menu_title' => __( 'Catalog Mode', 'yith-woocommerce-catalog-mode' ),
170
+ 'capability' => 'manage_options',
171
+ 'parent' => '',
172
+ 'parent_page' => 'yit_plugin_panel',
173
+ 'page' => $this->_panel_page,
174
+ 'admin-tabs' => $admin_tabs,
175
+ 'options-path' => YWCTM_DIR . '/plugin-options'
176
+ );
177
 
178
+ $this->_panel = new YIT_Plugin_Panel_WooCommerce( $args );
179
+ }
 
 
 
 
 
 
180
 
181
+ /**
182
+ * FRONTEND FUNCTIONS
183
+ */
184
 
185
+ /**
186
+ * Check if Catalog mode must be applied to current user
187
+ *
188
+ * @since 1.3.0
189
+ *
190
+ * @param $post_id
191
+ *
192
+ * @return bool
193
+ * @author Alberto Ruggiero
194
+ */
195
+ public function apply_catalog_mode( $post_id ) {
196
 
197
+ $target_users = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_price_users' ), $post_id, 'ywctm_hide_price_users' );
 
 
 
 
 
 
 
198
 
199
+ if ( $target_users == 'country' && defined( 'YWCTM_PREMIUM' ) ) {
200
 
201
+ return $this->country_check($post_id);
202
 
203
+ }
204
+ elseif ( $target_users == 'all' ) {
 
 
 
 
 
 
 
 
 
205
 
206
+ return true;
 
 
207
 
208
+ }
209
+ else {
210
 
211
+ return !is_user_logged_in();
212
 
213
+ }
214
 
215
  }
216
 
217
+ /**
218
+ * Check if catalog mode is enabled for administrator
219
+ *
220
+ * @since 1.0.2
221
+ * @return bool
222
+ * @author Alberto Ruggiero
223
+ */
224
+ public function check_user_admin_enable() {
 
 
225
 
226
+ return !( current_user_can( 'administrator' ) && is_user_logged_in() && get_option( 'ywctm_admin_view' ) == 'no' );
 
227
 
228
+ }
 
 
229
 
230
+ /**
231
+ * Checks if "Cart & Checkout pages" needs to be hidden
232
+ *
233
+ * @since 1.0.2
234
+ * @return bool
235
+ * @author Alberto Ruggiero
236
+ */
237
+ public function check_hide_cart_checkout_pages() {
238
 
239
+ return get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() && get_option( 'ywctm_hide_cart_header' ) == 'yes';
240
 
241
  }
242
 
243
+ /**
244
+ * Hides "Add to cart" button from single product page
245
+ *
246
+ * @since 1.0.0
247
+ *
248
+ * @param $action
249
+ *
250
+ * @return void
251
+ * @author Alberto Ruggiero
252
+ */
253
+ public function hide_add_to_cart_single( $action = '' ) {
254
+
255
+ if ( $action == '' ) {
256
+ $action = 'woocommerce_single_product_summary';
257
+ }
258
 
259
+ $priority = has_action( $action, 'woocommerce_template_single_add_to_cart' );
260
 
261
+ if ( $this->check_add_to_cart_single( $priority ) ) {
262
 
263
+ add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'hide_add_to_cart_quick_view' ), 10 );
 
264
 
 
 
 
265
  }
266
 
267
+ }
 
 
268
 
269
+ /**
270
+ * Hide add to cart button in quick view
271
+ *
272
+ * @since 1.0.7
273
+ * @return mixed
274
+ * @author Francesco Licandro
275
+ */
276
+ public function hide_add_to_cart_quick_view() {
277
 
278
+ $hide_variations = get_option( 'ywctm_hide_variations' );
279
+ ob_start();
 
 
 
 
 
 
 
 
 
280
 
281
+ $args = array(
282
+ 'form.cart button.single_add_to_cart_button'
283
+ );
284
 
285
+ if ( !class_exists( 'YITH_YWRAQ_Frontend' ) ) {
286
 
287
+ $args[] = 'form.cart .quantity';
 
288
 
289
+ }
290
 
291
+ if ( $hide_variations == 'yes' ) {
 
292
 
293
+ $args[] = 'table.variations';
294
+ $args[] = 'form.variations_form';
295
+ $args[] = '.single_variation_wrap .variations_button';
296
 
297
+ }
298
 
299
+ $classes = implode( ', ', apply_filters( 'ywctm_catalog_classes', $args ) );
300
+
301
+ ?>
302
+ <style>
303
+
304
+ <?php echo $classes; ?>
305
+ {
306
+ display: none !important
307
  }
 
308
 
309
+ </style>
310
+ <?php
311
+ echo ob_get_clean();
312
 
313
+ }
314
 
315
+ /**
316
+ * Check if price is hidden to hide add to cart button
317
+ *
318
+ * @since 1.0.4
319
+ *
320
+ * @param $post_id
321
+ *
322
+ * @return bool
323
+ * @author Alberto Ruggiero
324
+ */
325
+ public function check_price_hidden( $post_id ) {
326
 
327
+ $hide = false;
328
 
329
+ $hide_price = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_price' ), $post_id, 'ywctm_hide_price' );
330
 
331
+ if ( $hide_price == 'yes' ) {
332
 
333
+ if ( $this->apply_catalog_mode( $post_id ) ) {
334
 
335
+ $enable_exclusion = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_price' ), $post_id, 'ywctm_exclude_hide_price' );
336
+ $exclude_catalog = apply_filters( 'ywctm_get_exclusion', get_post_meta( $post_id, '_ywctm_exclude_hide_price', true ), $post_id, '_ywctm_exclude_hide_price' );
337
 
338
+ $hide = ( $enable_exclusion != 'yes' ? true : ( $exclude_catalog != 'yes' ? true : false ) );
339
 
340
+ $reverse_criteria = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_price_reverse' ), $post_id, 'ywctm_exclude_hide_price_reverse' );
341
 
342
+ if ( $reverse_criteria == 'yes' ) {
343
 
344
+ $hide = !$hide;
345
 
346
+ }
 
 
 
 
 
 
 
 
 
 
 
347
 
348
+ }
349
 
350
+ }
351
 
352
+ return $hide;
353
 
354
+ }
355
 
356
+ /**
357
+ * Checks if "Add to cart" needs to be hidden
358
+ *
359
+ * @since 1.0.2
360
+ *
361
+ * @param $priority
362
+ * @param $product_id
363
+ *
364
+ * @return bool
365
+ * @author Alberto Ruggiero
366
+ */
367
+ public function check_add_to_cart_single( $priority = true, $product_id = false ) {
368
 
369
+ $hide = false;
370
 
371
+ if ( get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() ) {
 
 
372
 
373
+ if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
374
 
375
+ $hide = true;
376
 
377
+ }
378
+ else {
379
 
380
+ global $post;
381
 
382
+ if ( !$product_id && !isset( $post ) ) {
383
+ return false;
384
+ }
385
 
386
+ $post_id = ( $product_id ) ? $product_id : $post->ID;
387
 
388
+ $hide_add_to_cart_single = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_add_to_cart_single' ), $post_id, 'ywctm_hide_add_to_cart_single' );
389
 
390
+ if ( $hide_add_to_cart_single == 'yes' ) {
391
 
392
+ if ( $this->apply_catalog_mode( $post_id ) ) {
 
393
 
394
+ $enable_exclusion = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart' ), $post_id, 'ywctm_exclude_hide_add_to_cart' );
395
+ $exclude_catalog = apply_filters( 'ywctm_get_exclusion', get_post_meta( $post_id, '_ywctm_exclude_catalog_mode', true ), $post_id, '_ywctm_exclude_catalog_mode' );
396
 
397
+ if ( $priority ) {
398
 
399
+ $hide = ( $enable_exclusion != 'yes' ? true : ( $exclude_catalog != 'yes' ? true : false ) );
400
 
401
  }
402
 
403
+ $reverse_criteria = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart_reverse' ), $post_id, 'ywctm_exclude_hide_add_to_cart_reverse' );
404
 
405
+ if ( $reverse_criteria == 'yes' ) {
406
 
407
+ $hide = !$hide;
408
 
409
+ }
410
 
411
  }
412
 
413
  }
414
 
415
+ if ( $this->check_price_hidden( $post_id ) ) {
416
 
417
+ $hide = true;
418
 
419
+ }
420
 
421
  }
422
 
423
  }
424
 
425
+ return $hide;
 
 
 
426
 
427
+ }
 
 
 
 
 
 
 
 
 
 
 
428
 
429
+ /**
430
+ * Checks if "Add to cart" needs to be avoided
431
+ *
432
+ * @since 1.0.5
433
+ *
434
+ * @param $passed
435
+ * @param $product_id
436
+ *
437
+ * @return bool
438
+ * @author Alberto Ruggiero
439
+ */
440
+ public function avoid_add_to_cart( $passed, $product_id ) {
441
 
442
+ if ( get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() ) {
443
 
444
+ if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
445
 
446
+ $passed = false;
 
447
 
448
+ }
449
+ else {
450
 
451
+ $hide_add_to_cart_single = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_add_to_cart_single' ), $product_id, 'ywctm_hide_add_to_cart_single' );
 
452
 
453
+ if ( $hide_add_to_cart_single == 'yes' ) {
454
 
455
+ if ( $this->apply_catalog_mode( $product_id ) ) {
 
456
 
457
+ $enable_exclusion = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart' ), $product_id, 'ywctm_exclude_hide_add_to_cart' );
458
+ $exclude_catalog = apply_filters( 'ywctm_get_exclusion', get_post_meta( $product_id, '_ywctm_exclude_catalog_mode', true ), $product_id, '_ywctm_exclude_catalog_mode' );
459
 
460
+ $passed = ( $enable_exclusion != 'yes' ? true : ( $exclude_catalog != 'yes' ? true : false ) );
461
 
462
+ $reverse_criteria = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart_reverse' ), $product_id, 'ywctm_exclude_hide_add_to_cart_reverse' );
 
463
 
464
+ if ( $reverse_criteria == 'yes' ) {
465
 
466
+ $passed = !$passed;
467
 
468
  }
469
 
470
  }
471
 
 
 
 
 
 
 
 
 
472
  }
473
 
474
+ if ( $this->check_price_hidden( $product_id ) ) {
475
 
476
+ $passed = false;
477
 
478
+ }
479
 
480
  }
481
 
482
  }
483
 
484
+ return $passed;
485
  }
486
 
487
+ /**
488
+ * Checks if "Add to cart" needs to be hidden from loop page
489
+ *
490
+ * @since 1.0.6
491
+ * @return bool
492
+ * @author Alberto Ruggiero
493
+ */
494
+ public function check_hide_add_cart_loop() {
 
 
 
495
 
496
+ $hide = false;
497
 
498
+ if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
 
 
 
 
 
499
 
500
+ $hide = true;
501
 
502
+ }
503
+ else {
504
 
505
+ global $post;
 
506
 
507
+ $hide_add_to_cart_loop = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_add_to_cart_loop' ), $post->ID, 'ywctm_hide_add_to_cart_loop' );
508
 
509
+ if ( $hide_add_to_cart_loop == 'yes' ) {
 
510
 
511
+ if ( $this->apply_catalog_mode( $post->ID ) ) {
512
 
513
+ $enable_exclusion = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart' ), $post->ID, 'ywctm_exclude_hide_add_to_cart' );
514
+ $exclude_catalog = apply_filters( 'ywctm_get_exclusion', get_post_meta( $post->ID, '_ywctm_exclude_catalog_mode', true ), $post->ID, '_ywctm_exclude_catalog_mode' );
515
 
516
+ $hide = ( $enable_exclusion != 'yes' ? true : ( $exclude_catalog != 'yes' ? true : false ) );
 
517
 
518
+ $product = wc_get_product( $post );
519
 
520
+ if ( $product->product_type == 'variable' ) {
521
 
522
+ $hide_variations = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_variations' ), $post->ID, 'ywctm_hide_variations' );
 
523
 
524
+ $hide = ( $hide_variations == 'yes' ? true : false );
525
 
526
  }
527
 
528
+ $reverse_criteria = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart_reverse' ), $post->ID, 'ywctm_exclude_hide_add_to_cart_reverse' );
 
 
529
 
530
+ if ( $reverse_criteria == 'yes' ) {
 
 
 
 
 
 
 
531
 
532
+ $hide = !$hide;
533
 
534
  }
535
 
536
  }
537
 
538
+ }
 
 
539
 
540
+ if ( $this->check_price_hidden( $post->ID ) ) {
541
 
542
+ $hide = true;
543
 
544
  }
545
 
 
 
 
 
 
546
 
547
  }
548
 
549
+ return $hide;
550
  }
551
 
552
+ /**
553
+ * Hides "Add to cart" button, if not excluded, from loop page
554
+ *
555
+ * @since 1.0.0
556
+ * @return void
557
+ * @author Alberto Ruggiero
558
+ */
559
+ public function hide_add_to_cart_loop() {
560
 
561
+ if ( $this->check_hide_add_cart_loop() ) {
 
 
 
 
 
 
 
562
 
563
+ remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
564
+ add_filter( 'woocommerce_loop_add_to_cart_link', '__return_empty_string', 10 );
565
 
566
+ }
567
+ else {
568
 
569
+ add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
570
+ remove_filter( 'woocommerce_loop_add_to_cart_link', '__return_empty_string', 10 );
571
 
572
+ }
 
573
 
574
  }
575
 
576
+ /**
577
+ * Enqueue css file
578
+ *
579
+ * @since 1.0.0
580
+ * @return void
581
+ * @author Alberto Ruggiero
582
+ */
583
+ public function enqueue_styles() {
584
+
585
+ if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
586
+ wp_enqueue_style( 'ywctm-style', YWCTM_ASSETS_URL . '/css/yith-catalog-mode.css' );
587
+ }
588
 
 
 
 
 
 
 
 
 
 
 
589
  }
590
 
591
+ /**
592
+ * Avoid Cart and Checkout Pages to be visited
593
+ *
594
+ * @since 1.0.4
595
+ * @return void
596
+ * @author Alberto Ruggiero
597
+ */
598
+ public function check_pages_redirect() {
599
 
600
+ if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
 
 
 
 
 
 
 
601
 
602
+ $cart = is_page( wc_get_page_id( 'cart' ) );
603
+ $checkout = is_page( wc_get_page_id( 'checkout' ) );
604
 
605
+ wp_reset_query();
 
606
 
607
+ if ( $cart || $checkout ) {
608
 
609
+ wp_redirect( home_url() );
610
+ exit;
611
 
612
+ }
 
613
 
614
  }
615
 
616
  }
617
 
618
+ /**
619
+ * Removes Cart and checkout pages from menu
620
+ *
621
+ * @since 1.0.4
622
+ *
623
+ * @param $pages
624
+ *
625
+ * @return mixed
626
+ * @author Alberto Ruggiero
627
+ */
628
+ public function hide_cart_checkout_pages( $pages ) {
629
 
630
+ if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
 
 
 
 
 
 
 
 
 
 
631
 
632
+ $excluded_pages = array(
633
+ wc_get_page_id( 'cart' ),
634
+ wc_get_page_id( 'checkout' )
635
+ );
636
 
637
+ for ( $i = 0; $i < count( $pages ); $i ++ ) {
638
+ $page = &$pages[$i];
 
 
639
 
640
+ if ( in_array( $page->ID, $excluded_pages ) ) {
 
641
 
642
+ unset( $pages[$i] );
643
 
644
+ }
645
 
646
  }
647
 
648
  }
649
 
650
+ return $pages;
651
+
652
  }
653
 
654
+ /**
655
+ * Say if the code is execute by quick view
656
+ *
657
+ * @since 1.0.7
658
+ * @return bool
659
+ * @author Andrea Frascaspata <andrea.frascaspata@yithemes.com>
660
+ */
661
+ public function is_quick_view() {
662
+ return defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && ( $_REQUEST['action'] == 'yith_load_product_quick_view' || $_REQUEST['action'] == 'yit_load_product_quick_view' );
663
+ }
664
 
665
+ /**
666
+ * Hides add to cart on wishlist
667
+ *
668
+ * @since 1.2.2
669
+ *
670
+ * @param $value
671
+ * @param $product
672
+ *
673
+ * @return string
674
+ * @author Alberto Ruggiero
675
+ */
676
+ public function hide_add_to_cart_wishlist( $value, $product ) {
677
 
678
+ global $yith_wcwl_is_wishlist;
 
 
 
 
 
 
 
 
 
679
 
680
+ if ( $this->check_add_to_cart_single( true, $product->id ) && $yith_wcwl_is_wishlist ) {
 
 
 
 
 
 
 
 
 
 
 
681
 
682
+ $value = '';
683
 
684
+ }
685
 
686
+ return $value;
687
 
688
  }
689
 
690
+ /**
691
+ * YITH FRAMEWORK
692
+ */
693
+
694
+ /**
695
+ * Load plugin framework
696
+ *
697
+ * @since 1.0.0
698
+ * @return void
699
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
700
+ */
701
+ public function plugin_fw_loader() {
702
+ if ( !defined( 'YIT_CORE_PLUGIN' ) ) {
703
+ global $plugin_fw_data;
704
+ if ( !empty( $plugin_fw_data ) ) {
705
+ $plugin_fw_file = array_shift( $plugin_fw_data );
706
+ require_once( $plugin_fw_file );
707
+ }
 
 
 
708
  }
709
  }
 
710
 
711
+ /**
712
+ * Premium Tab Template
713
+ *
714
+ * Load the premium tab template on admin page
715
+ *
716
+ * @since 1.0.0
717
+ * @return void
718
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
719
+ */
720
+ public function premium_tab() {
721
+ $premium_tab_template = YWCTM_TEMPLATE_PATH . '/admin/' . $this->_premium;
722
+ if ( file_exists( $premium_tab_template ) ) {
723
+ include_once( $premium_tab_template );
724
+ }
725
  }
 
726
 
727
+ /**
728
+ * Get the premium landing uri
729
+ *
730
+ * @since 1.0.0
731
+ * @return string The premium landing link
732
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
733
+ */
734
+ public function get_premium_landing_uri() {
735
+ return defined( 'YITH_REFER_ID' ) ? $this->_premium_landing . '?refer_id=' . YITH_REFER_ID : $this->_premium_landing;
736
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
737
 
738
+ /**
739
+ * Action Links
740
+ *
741
+ * add the action links to plugin admin page
742
+ * @since 1.0.0
743
+ *
744
+ * @param $links | links plugin array
745
+ *
746
+ * @return mixed
747
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
748
+ * @use plugin_action_links_{$plugin_file_name}
749
+ */
750
+ public function action_links( $links ) {
751
+
752
+ $links[] = '<a href="' . admin_url( "admin.php?page={$this->_panel_page}" ) . '">' . __( 'Settings', 'yith-woocommerce-catalog-mode' ) . '</a>';
753
+
754
+ if ( defined( 'YWCTM_FREE_INIT' ) ) {
755
+ $links[] = '<a href="' . $this->get_premium_landing_uri() . '" target="_blank">' . __( 'Premium Version', 'yith-woocommerce-catalog-mode' ) . '</a>';
756
+ }
757
 
758
+ return $links;
 
759
  }
760
 
761
+ /**
762
+ * Plugin row meta
763
+ *
764
+ * add the action links to plugin admin page
765
+ *
766
+ * @since 1.0.0
767
+ *
768
+ * @param $plugin_meta
769
+ * @param $plugin_file
770
+ * @param $plugin_data
771
+ * @param $status
772
+ *
773
+ * @return array
774
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
775
+ * @use plugin_row_meta
776
+ */
777
+ public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
778
+ if ( ( defined( 'YWCTM_INIT' ) && ( YWCTM_INIT == $plugin_file ) ) ||
779
+ ( defined( 'YWCTM_FREE_INIT' ) && ( YWCTM_FREE_INIT == $plugin_file ) )
780
+ ) {
781
+
782
+ $plugin_meta[] = '<a href="' . $this->_official_documentation . '" target="_blank">' . __( 'Plugin Documentation', 'yith-woocommerce-catalog-mode' ) . '</a>';
783
+ }
784
 
785
+ return $plugin_meta;
786
  }
787
 
 
788
  }
789
 
790
  }
init.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://yithemes.com/themes/plugins/yith-woocommerce-catalog-mode/
5
  Description: YITH WooCommerce Catalog Mode allows you to disable shop functions.
6
  Author: YIThemes
7
  Text Domain: yith-woocommerce-catalog-mode
8
- Version: 1.2.4
9
  Author URI: http://yithemes.com/
10
  */
11
 
@@ -34,7 +34,7 @@ function ywctm_install_free_admin_notice() {
34
  }
35
 
36
  if ( !defined( 'YWCTM_VERSION' ) ) {
37
- define( 'YWCTM_VERSION', '1.2.4' );
38
  }
39
 
40
  if ( !defined( 'YWCTM_FREE_INIT' ) ) {
5
  Description: YITH WooCommerce Catalog Mode allows you to disable shop functions.
6
  Author: YIThemes
7
  Text Domain: yith-woocommerce-catalog-mode
8
+ Version: 1.3.0
9
  Author URI: http://yithemes.com/
10
  */
11
 
34
  }
35
 
36
  if ( !defined( 'YWCTM_VERSION' ) ) {
37
+ define( 'YWCTM_VERSION', '1.3.0' );
38
  }
39
 
40
  if ( !defined( 'YWCTM_FREE_INIT' ) ) {
languages/yith-woocommerce-catalog-mode.pot CHANGED
@@ -1,8 +1,8 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: YITH WooCommerce Catalog Mode\n"
4
- "POT-Creation-Date: 2015-10-02 09:48+0100\n"
5
- "PO-Revision-Date: 2015-10-02 09:48+0100\n"
6
  "Last-Translator: \n"
7
  "Language-Team: Your Inspiration Themes <plugins@yithemes.com>\n"
8
  "Language: en\n"
@@ -19,30 +19,35 @@ msgstr ""
19
  "X-Poedit-SearchPath-0: ..\n"
20
  "X-Poedit-SearchPathExcluded-0: ../plugin-fw\n"
21
 
22
- #: ../class.yith-woocommerce-catalog-mode.php:602
23
- #: ../class.yith-woocommerce-catalog-mode.php:671
 
24
  msgid "Settings"
25
  msgstr ""
26
 
27
- #: ../class.yith-woocommerce-catalog-mode.php:606
28
- msgid "Premium Settings"
29
  msgstr ""
30
 
31
- #: ../class.yith-woocommerce-catalog-mode.php:607
32
- msgid "Exclusion List"
 
 
 
 
33
  msgstr ""
34
 
35
- #: ../class.yith-woocommerce-catalog-mode.php:610
36
- #: ../class.yith-woocommerce-catalog-mode.php:674
37
  msgid "Premium Version"
38
  msgstr ""
39
 
40
- #: ../class.yith-woocommerce-catalog-mode.php:616
41
- #: ../class.yith-woocommerce-catalog-mode.php:617
42
  msgid "Catalog Mode"
43
  msgstr ""
44
 
45
- #: ../class.yith-woocommerce-catalog-mode.php:700
46
  msgid "Plugin Documentation"
47
  msgstr ""
48
 
@@ -58,93 +63,80 @@ msgid ""
58
  "you are using the premium one."
59
  msgstr ""
60
 
61
- #: ../plugin-options/settings-options.php:18
62
  msgid "Upgrade to the PREMIUM VERSION"
63
  msgstr ""
64
 
65
- #: ../plugin-options/settings-options.php:21
66
- #: ../plugin-options/settings-options.php:27
67
  msgid "YITH WooCommerce Catalog Mode"
68
  msgstr ""
69
 
70
- #: ../plugin-options/settings-options.php:22
71
  msgid "Discover the Advanced Features"
72
  msgstr ""
73
 
74
- #: ../plugin-options/settings-options.php:23
75
  msgid ""
76
  "Upgrade to the PREMIUM VERSION of YITH WooCommerce Catalog Mode to benefit "
77
  "from all features!"
78
  msgstr ""
79
 
80
- #: ../plugin-options/settings-options.php:29
81
  msgid "Get Support and Pro Features"
82
  msgstr ""
83
 
84
- #: ../plugin-options/settings-options.php:30
85
  msgid ""
86
  "By purchasing the premium version of the plugin, you will take advantage of "
87
  "the advanced features of the product and you will get one year of free "
88
  "updates and support through our platform available 24h/24."
89
  msgstr ""
90
 
91
- #: ../plugin-options/settings-options.php:40
92
- #: ../plugin-options/settings-options.php:49
93
- #: ../plugin-options/settings-options.php:99
94
- #: ../plugin-options/settings-options.php:107
95
- msgid "\"Add to cart\" button"
96
- msgstr ""
97
-
98
  #: ../plugin-options/settings-options.php:42
99
- msgid "Exclude selected products (See \"Exclusions\" tab)"
100
  msgstr ""
101
 
102
- #: ../plugin-options/settings-options.php:51
103
- msgid "Reverse Exclusion List (Restrict Catalog Mode to selected items only)"
104
  msgstr ""
105
 
106
- #: ../plugin-options/settings-options.php:58
107
- msgid "Variable products"
108
  msgstr ""
109
 
110
- #: ../plugin-options/settings-options.php:60
111
- msgid "Hide product variations"
112
  msgstr ""
113
 
114
- #: ../plugin-options/settings-options.php:71
115
- msgid "General Settings"
116
  msgstr ""
117
 
118
- #: ../plugin-options/settings-options.php:76
119
- msgid "Enable YITH Woocommerce Catalog Mode"
120
  msgstr ""
121
 
122
- #: ../plugin-options/settings-options.php:83
123
  msgid "Admin View"
124
  msgstr ""
125
 
126
- #: ../plugin-options/settings-options.php:85
127
  msgid "Enable Catalog Mode also for administrators"
128
  msgstr ""
129
 
130
- #: ../plugin-options/settings-options.php:94
131
- msgid "Catalog Mode Settings"
132
- msgstr ""
133
-
134
- #: ../plugin-options/settings-options.php:101
135
- msgid "Hide in product details page"
136
  msgstr ""
137
 
138
- #: ../plugin-options/settings-options.php:109
139
- msgid "Hide in other pages"
140
  msgstr ""
141
 
142
- #: ../plugin-options/settings-options.php:118
143
- msgid "\"Cart\" and \"Checkout\" pages"
144
- msgstr ""
145
-
146
- #: ../plugin-options/settings-options.php:120
147
- msgid "Hide and disable all shop features"
148
  msgstr ""
149
 
150
  #: ../templates/admin/premium.php:226 ../templates/admin/premium.php:352
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: YITH WooCommerce Catalog Mode\n"
4
+ "POT-Creation-Date: 2016-03-01 14:05+0100\n"
5
+ "PO-Revision-Date: 2016-03-01 14:05+0100\n"
6
  "Last-Translator: \n"
7
  "Language-Team: Your Inspiration Themes <plugins@yithemes.com>\n"
8
  "Language: en\n"
19
  "X-Poedit-SearchPath-0: ..\n"
20
  "X-Poedit-SearchPathExcluded-0: ../plugin-fw\n"
21
 
22
+ #: ../class.yith-woocommerce-catalog-mode.php:150
23
+ #: ../class.yith-woocommerce-catalog-mode.php:160
24
+ #: ../class.yith-woocommerce-catalog-mode.php:752
25
  msgid "Settings"
26
  msgstr ""
27
 
28
+ #: ../class.yith-woocommerce-catalog-mode.php:151
29
+ msgid "Exclusion List"
30
  msgstr ""
31
 
32
+ #: ../class.yith-woocommerce-catalog-mode.php:152
33
+ msgid "Custom Button Url List"
34
+ msgstr ""
35
+
36
+ #: ../class.yith-woocommerce-catalog-mode.php:155
37
+ msgid "Vendor Exclusion List"
38
  msgstr ""
39
 
40
+ #: ../class.yith-woocommerce-catalog-mode.php:161
41
+ #: ../class.yith-woocommerce-catalog-mode.php:755
42
  msgid "Premium Version"
43
  msgstr ""
44
 
45
+ #: ../class.yith-woocommerce-catalog-mode.php:168
46
+ #: ../class.yith-woocommerce-catalog-mode.php:169
47
  msgid "Catalog Mode"
48
  msgstr ""
49
 
50
+ #: ../class.yith-woocommerce-catalog-mode.php:782
51
  msgid "Plugin Documentation"
52
  msgstr ""
53
 
63
  "you are using the premium one."
64
  msgstr ""
65
 
66
+ #: ../plugin-options/settings-options.php:20
67
  msgid "Upgrade to the PREMIUM VERSION"
68
  msgstr ""
69
 
70
+ #: ../plugin-options/settings-options.php:23
71
+ #: ../plugin-options/settings-options.php:29
72
  msgid "YITH WooCommerce Catalog Mode"
73
  msgstr ""
74
 
75
+ #: ../plugin-options/settings-options.php:24
76
  msgid "Discover the Advanced Features"
77
  msgstr ""
78
 
79
+ #: ../plugin-options/settings-options.php:25
80
  msgid ""
81
  "Upgrade to the PREMIUM VERSION of YITH WooCommerce Catalog Mode to benefit "
82
  "from all features!"
83
  msgstr ""
84
 
85
+ #: ../plugin-options/settings-options.php:31
86
  msgid "Get Support and Pro Features"
87
  msgstr ""
88
 
89
+ #: ../plugin-options/settings-options.php:32
90
  msgid ""
91
  "By purchasing the premium version of the plugin, you will take advantage of "
92
  "the advanced features of the product and you will get one year of free "
93
  "updates and support through our platform available 24h/24."
94
  msgstr ""
95
 
 
 
 
 
 
 
 
96
  #: ../plugin-options/settings-options.php:42
97
+ msgid "General Settings"
98
  msgstr ""
99
 
100
+ #: ../plugin-options/settings-options.php:46
101
+ msgid "Enable YITH WooCommerce Catalog Mode"
102
  msgstr ""
103
 
104
+ #: ../plugin-options/settings-options.php:57
105
+ msgid "Catalog Mode Settings"
106
  msgstr ""
107
 
108
+ #: ../plugin-options/settings-options.php:61
109
+ msgid "\"Add to cart\" button"
110
  msgstr ""
111
 
112
+ #: ../plugin-options/settings-options.php:63
113
+ msgid "Hide in product detail page"
114
  msgstr ""
115
 
116
+ #: ../plugin-options/settings-options.php:70
117
+ msgid "Hide in other shop pages"
118
  msgstr ""
119
 
120
+ #: ../plugin-options/settings-options.php:77
121
  msgid "Admin View"
122
  msgstr ""
123
 
124
+ #: ../plugin-options/settings-options.php:79
125
  msgid "Enable Catalog Mode also for administrators"
126
  msgstr ""
127
 
128
+ #: ../plugin-options/settings-options.php:88
129
+ msgid "Other Settings"
 
 
 
 
130
  msgstr ""
131
 
132
+ #: ../plugin-options/settings-options.php:93
133
+ msgid "Disable shop"
134
  msgstr ""
135
 
136
+ #: ../plugin-options/settings-options.php:95
137
+ msgid ""
138
+ "Hide and disable \"Cart\" page, \"Checkout\" page and all \"Add to Cart\" "
139
+ "buttons"
 
 
140
  msgstr ""
141
 
142
  #: ../templates/admin/premium.php:226 ../templates/admin/premium.php:352
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: yithemes
4
  Tags: woocommerce catalog mode plugin, woocommerce catalog only, woocommerce, products, themes, yit, yith, yithemes, e-commerce, shop, catalog mode, catalogue mode, remove add to cart, ask for price, ask price, asking for price, asking price, button remove, call, call for price, call me, call us, contact, email, hide add to cart, hide price
5
  Requires at least: 4.0
6
  Tested up to: 4.4.2
7
- Stable tag: 1.2.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -113,6 +113,10 @@ yith-woocommerce-catalog-mode-<WORDPRESS LOCALE >.mo
113
 
114
  == Changelog ==
115
 
 
 
 
 
116
  = Version 1.2.4 - Released: Feb 19, 2016 =
117
 
118
  * Updated: plugin core framework
@@ -205,7 +209,7 @@ yith-woocommerce-catalog-mode-<WORDPRESS LOCALE >.mo
205
 
206
  == Upgrade Notice ==
207
 
208
- Last Stable Tag 1.2.4
209
 
210
  == Suggestions ==
211
 
4
  Tags: woocommerce catalog mode plugin, woocommerce catalog only, woocommerce, products, themes, yit, yith, yithemes, e-commerce, shop, catalog mode, catalogue mode, remove add to cart, ask for price, ask price, asking for price, asking price, button remove, call, call for price, call me, call us, contact, email, hide add to cart, hide price
5
  Requires at least: 4.0
6
  Tested up to: 4.4.2
7
+ Stable tag: 1.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
113
 
114
  == Changelog ==
115
 
116
+ = Version 1.3.0 - Released: Mar 01, 2016 =
117
+
118
+ * Updated: language file
119
+
120
  = Version 1.2.4 - Released: Feb 19, 2016 =
121
 
122
  * Updated: plugin core framework
209
 
210
  == Upgrade Notice ==
211
 
212
+ Last Stable Tag 1.3.0
213
 
214
  == Suggestions ==
215