YITH WooCommerce Catalog Mode - Version 2.0.0

Version Description

Last Stable Tag 2.0.0

Download this release

Release Info

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

Code changes from version 1.6.16 to 2.0.0

Files changed (108) hide show
  1. Gruntfile.js +141 -0
  2. assets/css/admin.css +82 -0
  3. assets/css/admin.min.css +1 -0
  4. assets/css/frontend.css +1 -0
  5. assets/css/frontend.min.css +0 -0
  6. assets/images/01-bg.png +0 -0
  7. assets/images/01-icon.png +0 -0
  8. assets/images/01.png +0 -0
  9. assets/images/02-bg.png +0 -0
  10. assets/images/02-icon.png +0 -0
  11. assets/images/02.png +0 -0
  12. assets/images/03-bg.png +0 -0
  13. assets/images/03-icon.png +0 -0
  14. assets/images/03.png +0 -0
  15. assets/images/04-bg.png +0 -0
  16. assets/images/04-icon.png +0 -0
  17. assets/images/04.png +0 -0
  18. assets/images/05-bg.png +0 -0
  19. assets/images/05-icon.png +0 -0
  20. assets/images/05.png +0 -0
  21. assets/images/06-bg.png +0 -0
  22. assets/images/06-icon.png +0 -0
  23. assets/images/06.png +0 -0
  24. assets/images/07-bg.png +0 -0
  25. assets/images/07-icon.png +0 -0
  26. assets/images/07.png +0 -0
  27. assets/images/08-bg.png +0 -0
  28. assets/images/08-icon.png +0 -0
  29. assets/images/08.png +0 -0
  30. assets/images/09-bg.png +0 -0
  31. assets/images/09-icon.png +0 -0
  32. assets/images/09.png +0 -0
  33. assets/images/10-bg.png +0 -0
  34. assets/images/10-icon.png +0 -0
  35. assets/images/10.png +0 -0
  36. assets/images/premium-01.jpg +0 -0
  37. assets/images/premium-02.jpg +0 -0
  38. assets/images/premium-03.jpg +0 -0
  39. assets/images/premium-04.jpg +0 -0
  40. assets/images/premium-05.jpg +0 -0
  41. assets/images/premium-06.jpg +0 -0
  42. assets/images/premium-07.jpg +0 -0
  43. assets/images/upgrade.png +0 -0
  44. assets/images/yith-woocommerce-catalog-mode.jpg +0 -0
  45. class-yith-woocommerce-catalog-mode.php +839 -0
  46. class.yith-woocommerce-catalog-mode.php +0 -966
  47. includes/actions/update-2.0.0/ywctm-install.php +28 -0
  48. includes/actions/update-2.0.0/ywctm-update.php +192 -0
  49. includes/admin/fields/yith-multiple-field.php +50 -0
  50. includes/ywctm-functions.php +48 -0
  51. init.php +40 -59
  52. languages/yith-woocommerce-catalog-mode.pot +150 -182
  53. package-lock.json +1329 -0
  54. package.json +19 -0
  55. plugin-fw/.jshintrc +26 -0
  56. plugin-fw/Gruntfile.js +96 -0
  57. plugin-fw/assets/css/yith-fields.css +91 -87
  58. plugin-fw/assets/fonts/yith-icon.eot +0 -0
  59. plugin-fw/assets/fonts/yith-icon.svg +9 -0
  60. plugin-fw/assets/fonts/yith-icon.ttf +0 -0
  61. plugin-fw/assets/fonts/yith-icon.woff +0 -0
  62. plugin-fw/assets/js/how-to.min.js +1 -1
  63. plugin-fw/assets/js/jquery.colorbox.min.js +5 -32
  64. plugin-fw/assets/js/metabox.js +14 -0
  65. plugin-fw/assets/js/metabox.min.js +1 -1
  66. plugin-fw/assets/js/multisite-updater.js +1 -1
  67. plugin-fw/assets/js/multisite-updater.min.js +1 -8
  68. plugin-fw/assets/js/wp-pages.min.js +1 -1
  69. plugin-fw/assets/js/yit-cpt-unlimited.min.js +1 -2
  70. plugin-fw/assets/js/yit-plugin-panel.js +35 -14
  71. plugin-fw/assets/js/yit-plugin-panel.min.js +1 -1
  72. plugin-fw/assets/js/yit-wp-pointer.min.js +1 -6
  73. plugin-fw/assets/js/yith-dashboard.min.js +1 -2
  74. plugin-fw/assets/js/yith-enhanced-select-wc-2.6.min.js +1 -5
  75. plugin-fw/assets/js/yith-enhanced-select.min.js +1 -10
  76. plugin-fw/assets/js/yith-fields.min.js +1 -30
  77. plugin-fw/assets/js/yith-gutenberg.min.js +1 -6
  78. plugin-fw/assets/js/yith-promo.min.js +1 -1
  79. plugin-fw/assets/js/yith-system-info.min.js +1 -1
  80. plugin-fw/assets/js/yith-update-plugins.min.js +1 -2
  81. plugin-fw/init.php +3 -3
  82. plugin-fw/languages/yith-plugin-fw-el.mo +0 -0
  83. plugin-fw/languages/yith-plugin-fw-el.po +822 -0
  84. plugin-fw/languages/yith-plugin-fw-es_ES.mo +0 -0
  85. plugin-fw/languages/yith-plugin-fw-es_ES.po +664 -484
  86. plugin-fw/languages/yith-plugin-fw-it_IT.mo +0 -0
  87. plugin-fw/languages/yith-plugin-fw-it_IT.po +658 -483
  88. plugin-fw/languages/yith-plugin-fw-nl_NL.mo +0 -0
  89. plugin-fw/languages/yith-plugin-fw-nl_NL.po +1152 -0
  90. plugin-fw/languages/yith-plugin-fw.pot +274 -395
  91. plugin-fw/lib/yit-plugin-gradients.php +6 -6
  92. plugin-fw/lib/yit-plugin-panel-wc.php +24 -20
  93. plugin-fw/lib/yit-plugin-panel.php +18 -9
  94. plugin-fw/lib/yit-pointers.php +2 -2
  95. plugin-fw/lib/yith-system-status.php +45 -39
  96. plugin-fw/package.json +21 -0
  97. plugin-fw/templates/fields/country-select.php +1 -2
  98. plugin-fw/templates/fields/multi-colorpicker.php +3 -3
  99. plugin-fw/templates/fields/multi-select.php +2 -1
  100. plugin-fw/templates/fields/onoff.php +4 -2
  101. plugin-fw/templates/fields/select-images.php +5 -4
  102. plugin-fw/templates/panel/panel-field-container.php +4 -2
  103. plugin-fw/yit-functions.php +23 -2
  104. plugin-options/{premium-landing-options.php → premium-options.php} +9 -9
  105. plugin-options/settings-options.php +57 -56
  106. readme.txt +68 -33
  107. templates/admin/premium.php +318 -405
  108. wpml-config.xml +0 -7
Gruntfile.js ADDED
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Required
3
+ * - install grunt
4
+ * sudo npm install -g grunt-cli
5
+ * - install node-wp-i18n
6
+ * sudo npm install -g node-wp-i18n
7
+ */
8
+
9
+ const potInfo = {
10
+ potFilename: 'yith-woocommerce-catalog-mode.pot',
11
+ potHeaders : {
12
+ poedit : true, // Includes common Poedit headers.
13
+ 'x-poedit-keywordslist': true, // Include a list of all possible gettext functions.
14
+ 'report-msgid-bugs-to' : 'Your Inspiration Themes <plugins@yithemes.com>',
15
+ 'language-team' : 'Your Inspiration Themes <info@yithemes.com>'
16
+ }
17
+ };
18
+
19
+ module.exports = function ( grunt ) {
20
+ 'use strict';
21
+
22
+ grunt.initConfig(
23
+ {
24
+ dirs: {
25
+ css: 'assets/css',
26
+ js : 'assets/js'
27
+ },
28
+
29
+ uglify: {
30
+ options: {
31
+ ie8 : true,
32
+ parse : {
33
+ strict: false
34
+ },
35
+ output: {
36
+ comments: /@license|@preserve|^!/
37
+ }
38
+ },
39
+ common : {
40
+ files: [ {
41
+ expand: true,
42
+ cwd : '<%= dirs.js %>/',
43
+ src : [ '*.js', '!*.min.js' ],
44
+ dest : '<%= dirs.js %>/',
45
+ ext : '.min.js'
46
+ } ]
47
+ }
48
+ },
49
+
50
+ jshint: {
51
+ options: {
52
+ jshintrc: '.jshintrc'
53
+ },
54
+ all : [
55
+ '<%= dirs.js %>/**/*.js',
56
+ '!<%= dirs.js %>/**/*.min.js'
57
+ ]
58
+ },
59
+
60
+ cssmin: {
61
+ minify: {
62
+ expand: true,
63
+ cwd : '<%= dirs.css %>/',
64
+ src : [ '*.css', '!*.min.css' ],
65
+ dest : '<%= dirs.css %>/',
66
+ ext : '.min.css'
67
+ }
68
+ },
69
+
70
+ makepot: {
71
+ options: {
72
+ type : 'wp-plugin',
73
+ domainPath : 'languages',
74
+ potHeaders : potInfo.potHeaders,
75
+ updatePoFiles: true,
76
+ processPot : function ( pot ) {
77
+ // Exclude plugin meta
78
+ var translation,
79
+ excluded_meta = [
80
+ 'Plugin Name of the plugin/theme',
81
+ 'Plugin URI of the plugin/theme',
82
+ 'Author of the plugin/theme',
83
+ 'Author URI of the plugin/theme'
84
+ ];
85
+
86
+ for ( translation in pot.translations[ '' ] ) {
87
+ if ( 'undefined' !== typeof pot.translations[ '' ][ translation ].comments.extracted ) {
88
+ if ( excluded_meta.indexOf( pot.translations[ '' ][ translation ].comments.extracted ) >= 0 ) {
89
+ console.log( 'Excluded meta: ' + pot.translations[ '' ][ translation ].comments.extracted );
90
+ delete pot.translations[ '' ][ translation ];
91
+ }
92
+ }
93
+ }
94
+
95
+ return pot;
96
+ }
97
+ },
98
+ dist : {
99
+ options: {
100
+ potFilename: potInfo.potFilename,
101
+ exclude : [
102
+ 'plugin-fw/.*',
103
+ 'plugin-upgrade/.*',
104
+ 'mode_modules/.*',
105
+ 'tests/.*',
106
+ 'tmp/.*',
107
+ 'lib/.*',
108
+ 'includes/libraries/.*',
109
+ 'logs/.*'
110
+ ]
111
+ }
112
+ }
113
+ }
114
+
115
+ }
116
+ );
117
+
118
+ // Load NPM tasks to be used here.
119
+ grunt.loadNpmTasks( 'grunt-wp-i18n' );
120
+ grunt.loadNpmTasks( 'grunt-contrib-uglify' );
121
+ grunt.loadNpmTasks( 'grunt-contrib-jshint' );
122
+ grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
123
+
124
+ // Register tasks.
125
+ grunt.registerTask(
126
+ 'default',
127
+ [
128
+ 'js',
129
+ 'css',
130
+ 'i18n'
131
+ ]
132
+ );
133
+
134
+ grunt.registerTask( 'checkjs', [ 'jshint' ] );
135
+
136
+ grunt.registerTask( 'js', [ 'uglify' ] );
137
+
138
+ grunt.registerTask( 'css', [ 'cssmin' ] );
139
+
140
+ grunt.registerTask( 'i18n', [ 'makepot' ] );
141
+ };
assets/css/admin.css ADDED
@@ -0,0 +1,82 @@
1
+ .yith-plugin-fw-yith-multiple-field-field-wrapper .option-element label,
2
+ .yith-multiple-field .option-element label {
3
+ font-size: 11px;
4
+ font-weight: 600;
5
+ }
6
+
7
+ .ywctm-inline-selects .option-element {
8
+ height: 100%;
9
+ display: inline-flex;
10
+ align-items: center;
11
+ padding: 0 10px 0 0;
12
+ vertical-align: top;
13
+ }
14
+
15
+ .ywctm-inline-selects .option-element.hidden {
16
+ padding: 0;
17
+ }
18
+
19
+ .ywctm-inline-selects .option-element > span {
20
+ display: flex;
21
+ min-height: 38px;
22
+ align-items: center;
23
+ }
24
+
25
+ .woocommerce table.form-table .ywctm-inline-selects .option-element > .yith-plugin-fw-select-field-wrapper > .select2 {
26
+ width: 220px !important;
27
+ min-width: 220px !important;
28
+ }
29
+
30
+ .ywctm-multiple-numbers {
31
+ display: grid;
32
+ grid-template-columns: 90px 90px 90px 90px;
33
+ grid-gap: 20px;
34
+ }
35
+
36
+ .ywctm-multiple-numbers .option-element {
37
+ width: 90px;
38
+ display: inline-block;
39
+ }
40
+
41
+ .ywctm-multiple-languages .option-element {
42
+ display: block;
43
+ }
44
+
45
+ .ywctm-multiple-mixed {
46
+ display: grid;
47
+ grid-template-columns: 90px 90px;
48
+ grid-gap: 20px;
49
+ }
50
+
51
+ .ywctm-multiple-mixed .option-element {
52
+ width: 90px;
53
+ display: inline-block;
54
+ }
55
+
56
+ .ywctm-multiple-mixed .option-element > .yith-plugin-fw-select-field-wrapper > .select2 {
57
+ width: 90px !important;
58
+ min-width: 90px !important;
59
+ height: 38px !important;
60
+ }
61
+
62
+ .ywctm-multiple-sliders .option-element {
63
+ display: grid;
64
+ grid-template-columns: 10ch 400px;
65
+ grid-gap: 2%;
66
+ }
67
+
68
+ .ywctm-multiple-sliders .option-element label {
69
+ padding-top: 9px;
70
+ }
71
+
72
+ @media screen and (min-width: 1280px) {
73
+ .yith-colorpicker-group {
74
+ display: grid;
75
+ grid-template-columns: fit-content(48%) fit-content(48%);
76
+ grid-gap: 4%;
77
+ }
78
+
79
+ .yith-colorpicker-group .colorpicker {
80
+ width: auto !important;
81
+ }
82
+ }
assets/css/admin.min.css ADDED
@@ -0,0 +1 @@
1
+ .yith-multiple-field .option-element label,.yith-plugin-fw-yith-multiple-field-field-wrapper .option-element label{font-size:11px;font-weight:600}.ywctm-inline-selects .option-element{height:100%;display:inline-flex;align-items:center;padding:0 10px 0 0;vertical-align:top}.ywctm-inline-selects .option-element.hidden{padding:0}.ywctm-inline-selects .option-element>span{display:flex;min-height:38px;align-items:center}.woocommerce table.form-table .ywctm-inline-selects .option-element>.yith-plugin-fw-select-field-wrapper>.select2{width:220px!important;min-width:220px!important}.ywctm-multiple-numbers{display:grid;grid-template-columns:90px 90px 90px 90px;grid-gap:20px}.ywctm-multiple-numbers .option-element{width:90px;display:inline-block}.ywctm-multiple-languages .option-element{display:block}.ywctm-multiple-mixed{display:grid;grid-template-columns:90px 90px;grid-gap:20px}.ywctm-multiple-mixed .option-element{width:90px;display:inline-block}.ywctm-multiple-mixed .option-element>.yith-plugin-fw-select-field-wrapper>.select2{width:90px!important;min-width:90px!important;height:38px!important}.ywctm-multiple-sliders .option-element{display:grid;grid-template-columns:10ch 400px;grid-gap:2%}.ywctm-multiple-sliders .option-element label{padding-top:9px}@media screen and (min-width:1280px){.yith-colorpicker-group{display:grid;grid-template-columns:fit-content(48%) fit-content(48%);grid-gap:4%}.yith-colorpicker-group .colorpicker{width:auto!important}}
assets/css/frontend.css ADDED
@@ -0,0 +1 @@
1
+ /* Silence is golden */
assets/css/frontend.min.css ADDED
File without changes
assets/images/01-bg.png DELETED
Binary file
assets/images/01-icon.png DELETED
Binary file
assets/images/01.png DELETED
Binary file
assets/images/02-bg.png DELETED
Binary file
assets/images/02-icon.png DELETED
Binary file
assets/images/02.png DELETED
Binary file
assets/images/03-bg.png DELETED
Binary file
assets/images/03-icon.png DELETED
Binary file
assets/images/03.png DELETED
Binary file
assets/images/04-bg.png DELETED
Binary file
assets/images/04-icon.png DELETED
Binary file
assets/images/04.png DELETED
Binary file
assets/images/05-bg.png DELETED
Binary file
assets/images/05-icon.png DELETED
Binary file
assets/images/05.png DELETED
Binary file
assets/images/06-bg.png DELETED
Binary file
assets/images/06-icon.png DELETED
Binary file
assets/images/06.png DELETED
Binary file
assets/images/07-bg.png DELETED
Binary file
assets/images/07-icon.png DELETED
Binary file
assets/images/07.png DELETED
Binary file
assets/images/08-bg.png DELETED
Binary file
assets/images/08-icon.png DELETED
Binary file
assets/images/08.png DELETED
Binary file
assets/images/09-bg.png DELETED
Binary file
assets/images/09-icon.png DELETED
Binary file
assets/images/09.png DELETED
Binary file
assets/images/10-bg.png DELETED
Binary file
assets/images/10-icon.png DELETED
Binary file
assets/images/10.png DELETED
Binary file
assets/images/premium-01.jpg ADDED
Binary file
assets/images/premium-02.jpg ADDED
Binary file
assets/images/premium-03.jpg ADDED
Binary file
assets/images/premium-04.jpg ADDED
Binary file
assets/images/premium-05.jpg ADDED
Binary file
assets/images/premium-06.jpg ADDED
Binary file
assets/images/premium-07.jpg ADDED
Binary file
assets/images/upgrade.png DELETED
Binary file
assets/images/yith-woocommerce-catalog-mode.jpg DELETED
Binary file
class-yith-woocommerce-catalog-mode.php ADDED
@@ -0,0 +1,839 @@
1
+ <?php
2
+
3
+
4
+ if ( ! defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ } // Exit if accessed directly
7
+
8
+ if ( ! class_exists( 'YITH_WooCommerce_Catalog_Mode' ) ) {
9
+
10
+ /**
11
+ * Implements features of YITH WooCommerce Catalog Mode plugin
12
+ *
13
+ * @class YITH_WooCommerce_Catalog_Mode
14
+ * @since 1.0.0
15
+ * @author Your Inspiration Themes
16
+ * @package Yithemes
17
+ */
18
+ class YITH_WooCommerce_Catalog_Mode {
19
+
20
+ /**
21
+ * Panel object
22
+ *
23
+ * @since 1.0.0
24
+ * @var /Yit_Plugin_Panel object
25
+ * @see plugin-fw/lib/yit-plugin-panel.php
26
+ */
27
+ protected $_panel;
28
+
29
+ /**
30
+ * @var $_premium string Premium tab template file name
31
+ */
32
+ protected $_premium = 'premium.php';
33
+
34
+ /**
35
+ * @var string Premium version landing link
36
+ */
37
+ protected $_premium_landing = 'https://yithemes.com/themes/plugins/yith-woocommerce-catalog-mode/';
38
+
39
+ /**
40
+ * @var string Plugin official documentation
41
+ */
42
+ protected $_official_documentation = 'https://docs.yithemes.com/yith-woocommerce-catalog-mode/';
43
+
44
+ /**
45
+ * @var string Yith WooCommerce Catalog Mode panel page
46
+ */
47
+ protected $_panel_page = 'yith_wc_catalog_mode_panel';
48
+
49
+ /**
50
+ * Single instance of the class
51
+ *
52
+ * @since 1.3.0
53
+ * @var YITH_WooCommerce_Catalog_Mode
54
+ */
55
+ protected static $instance;
56
+
57
+ /**
58
+ * Returns single instance of the class
59
+ *
60
+ * @return YITH_WooCommerce_Catalog_Mode
61
+ * @since 1.3.0
62
+ */
63
+ public static function get_instance() {
64
+
65
+ if ( is_null( self::$instance ) ) {
66
+ self::$instance = new self;
67
+ }
68
+
69
+ return self::$instance;
70
+
71
+ }
72
+
73
+ /**
74
+ * Constructor
75
+ *
76
+ * Initialize plugin and registers actions and filters to be used
77
+ *
78
+ * @return void
79
+ * @since 1.0.0
80
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
81
+ */
82
+ public function __construct() {
83
+
84
+ // Load Plugin Framework
85
+ add_action( 'plugins_loaded', array( $this, 'plugin_fw_loader' ), 15 );
86
+
87
+ //Add action links
88
+ add_filter( 'plugin_action_links_' . plugin_basename( YWCTM_DIR . '/' . basename( YWCTM_FILE ) ), array( $this, 'action_links' ) );
89
+ add_filter( 'yith_show_plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 5 );
90
+
91
+ $this->include_files();
92
+
93
+ add_filter( 'yith_plugin_fw_get_field_template_path', array( $this, 'add_custom_fields' ), 10, 2 );
94
+ add_action( 'woocommerce_admin_settings_sanitize_option', array( $this, 'sanitize_custom_field' ), 10, 2 );
95
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_admin' ) );
96
+ add_action( 'admin_menu', array( $this, 'add_menu_page' ), 5 );
97
+ add_action( 'yith_catalog_mode_premium', array( $this, 'premium_tab' ) );
98
+
99
+ if ( ! is_admin() || $this->is_quick_view() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
100
+
101
+ if ( $this->disable_shop() ) {
102
+ $priority = has_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ) );
103
+ remove_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ), $priority );
104
+ add_filter( 'get_pages', array( $this, 'hide_cart_checkout_pages' ) );
105
+ add_filter( 'wp_get_nav_menu_items', array( $this, 'hide_cart_checkout_pages' ) );
106
+ add_filter( 'wp_nav_menu_objects', array( $this, 'hide_cart_checkout_pages' ) );
107
+ add_action( 'wp', array( $this, 'check_pages_redirect' ) );
108
+ }
109
+
110
+ add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'hide_add_to_cart_loop' ), 5 );
111
+ add_filter( 'woocommerce_add_to_cart_validation', array( $this, 'avoid_add_to_cart' ), 10, 2 );
112
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles_frontend' ) );
113
+ add_filter( 'ywctm_css_classes', array( $this, 'hide_atc_single_page' ) );
114
+ add_filter( 'ywctm_css_classes', array( $this, 'hide_cart_widget' ) );
115
+
116
+ if ( defined( 'YITH_WCWL' ) && YITH_WCWL ) {
117
+ add_filter( 'woocommerce_loop_add_to_cart_link', array( $this, 'hide_add_to_cart_wishlist' ), 10, 2 );
118
+ }
119
+ }
120
+
121
+ }
122
+
123
+ /**
124
+ * Files inclusion
125
+ *
126
+ * @return void
127
+ * @since 2.0.0
128
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
129
+ */
130
+ public function include_files() {
131
+
132
+ //Check if options should be upgraded
133
+ $update_path = YWCTM_DIR . 'includes/actions/update-' . YWCTM_VERSION . '/ywctm-install.php';
134
+ if ( ( version_compare( YWCTM_VERSION, get_option( 'ywctm_update_version' ), '>' ) || YWCTM_VERSION === get_transient( 'ywctm_prune_settings' ) ) && file_exists( $update_path ) ) {
135
+ include_once( $update_path );
136
+ }
137
+
138
+ include_once( 'includes/ywctm-functions.php' );
139
+
140
+ }
141
+
142
+ /**
143
+ * ADMIN FUNCTIONS
144
+ */
145
+
146
+ /**
147
+ * Initialize custom fields
148
+ *
149
+ * @param $path string
150
+ * @param $field array
151
+ *
152
+ * @return string
153
+ * @since 2.0.0
154
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
155
+ */
156
+ public function add_custom_fields( $path, $field ) {
157
+
158
+ $custom_fields = array(
159
+ 'yith-multiple-field',
160
+ );
161
+
162
+ if ( in_array( $field['type'], $custom_fields, true ) ) {
163
+ $path = YWCTM_DIR . '/includes/admin/fields/' . $field['type'] . '.php';
164
+ }
165
+
166
+ return $path;
167
+
168
+ }
169
+
170
+ /**
171
+ * Sanitize array fields
172
+ *
173
+ * @param $value mixed
174
+ * @param $option array
175
+ *
176
+ * @return string
177
+ * @since 2.0.0
178
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
179
+ */
180
+ public function sanitize_custom_field( $value, $option ) {
181
+
182
+ $allowed_fields = array(
183
+ 'yith-multiple-field',
184
+ );
185
+
186
+ if ( isset( $option['yith-type'] ) && in_array( $option['yith-type'], $allowed_fields, true ) ) {
187
+ if ( empty( $value ) ) {
188
+ $value = '';
189
+ } elseif ( is_array( $value ) ) {
190
+ $value = maybe_serialize( $value );
191
+ }
192
+ }
193
+
194
+ return $value;
195
+
196
+ }
197
+
198
+ /**
199
+ * Enqueue script file
200
+ *
201
+ * @return void
202
+ * @since 2.0.0
203
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
204
+ */
205
+ public function enqueue_scripts_admin() {
206
+
207
+ wp_register_style( 'ywctm-admin', yit_load_css_file( YWCTM_ASSETS_URL . 'css/admin.css' ), array(), YWCTM_VERSION );
208
+
209
+ if ( ! empty( $_GET['page'] ) && ( $_GET['page'] === $this->_panel_page || 'yith_vendor_ctm_settings' === $_GET['page'] ) ) {
210
+ wp_enqueue_style( 'ywctm-admin' );
211
+ }
212
+
213
+ }
214
+
215
+ /**
216
+ * Add a panel under YITH Plugins tab
217
+ *
218
+ * @return void
219
+ * @since 1.0.0
220
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
221
+ * @use /Yit_Plugin_Panel class
222
+ * @see plugin-fw/lib/yit-plugin-panel.php
223
+ */
224
+ public function add_menu_page() {
225
+
226
+ if ( ! empty( $this->_panel ) ) {
227
+ return;
228
+ }
229
+
230
+ if ( defined( 'YWCTM_PREMIUM' ) && YWCTM_PREMIUM ) {
231
+
232
+ $admin_tabs = array(
233
+ 'premium-settings' => esc_html_x( 'Settings', 'general settings tab name', 'yith-woocommerce-catalog-mode' ),
234
+ 'exclusions' => esc_html_x( 'Exclusion List', 'exclusion settings tab name', 'yith-woocommerce-catalog-mode' ),
235
+ 'inquiry-form' => esc_html_x( 'Inquiry Form', 'inquiry form settings tab name', 'yith-woocommerce-catalog-mode' ),
236
+ 'buttons-labels' => esc_html_x( 'Buttons & Labels', 'buttons & labels settings tab name', 'yith-woocommerce-catalog-mode' ),
237
+ );
238
+
239
+ } else {
240
+
241
+ $admin_tabs = array(
242
+ 'settings' => esc_html__( 'Settings', 'yith-woocommerce-catalog-mode' ),
243
+ 'premium' => esc_html__( 'Premium Version', 'yith-woocommerce-catalog-mode' ),
244
+ );
245
+
246
+ }
247
+
248
+ $args = array(
249
+ 'create_menu_page' => true,
250
+ 'plugin_slug' => YWCTM_SLUG,
251
+ 'parent_slug' => '',
252
+ 'page_title' => 'Catalog Mode',
253
+ 'menu_title' => 'Catalog Mode',
254
+ 'capability' => 'manage_options',
255
+ 'parent' => '',
256
+ 'parent_page' => 'yith_plugin_panel',
257
+ 'page' => $this->_panel_page,
258
+ 'admin-tabs' => $admin_tabs,
259
+ 'options-path' => YWCTM_DIR . '/plugin-options',
260
+ 'class' => yith_set_wrapper_class(),
261
+ );
262
+
263
+ $this->_panel = new YIT_Plugin_Panel_WooCommerce( $args );
264
+
265
+ }
266
+
267
+ /**
268
+ * FRONTEND FUNCTIONS
269
+ */
270
+
271
+ /**
272
+ * Check if catalog mode is enabled for administrator
273
+ *
274
+ * @return boolean
275
+ * @since 2.0.0
276
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
277
+ */
278
+ public function check_user_admin_enable() {
279
+
280
+ $vendor_id = ( defined( 'YWCTM_PREMIUM' ) && YWCTM_PREMIUM ) ? ywctm_get_vendor_id() : '';
281
+
282
+ return ( ( current_user_can( 'administrator' ) || current_user_can( 'manage_vendor_store' ) ) && is_user_logged_in() && ( 'no' === get_option( 'ywctm_admin_view' . $vendor_id ) ) );
283
+ }
284
+
285
+ /**
286
+ * Removes Cart and checkout pages from menu
287
+ *
288
+ * @param $pages array
289
+ *
290
+ * @return array
291
+ * @since 1.0.4
292
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
293
+ */
294
+ public function hide_cart_checkout_pages( $pages ) {
295
+
296
+ $excluded_pages = array(
297
+ wc_get_page_id( 'cart' ),
298
+ wc_get_page_id( 'checkout' ),
299
+ );
300
+
301
+ foreach ( $pages as $key => $page ) {
302
+
303
+ $page_id = ( in_array( current_filter(), array( 'wp_get_nav_menu_items', 'wp_nav_menu_objects' ), true ) ? $page->object_id : $page->ID );
304
+
305
+ if ( in_array( (int) $page_id, $excluded_pages, true ) ) {
306
+ unset( $pages[ $key ] );
307
+
308
+ }
309
+ }
310
+
311
+ return $pages;
312
+
313
+ }
314
+
315
+ /**
316
+ * Checks if "Cart & Checkout pages" needs to be hidden
317
+ *
318
+ * @return boolean
319
+ * @since 1.0.2
320
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
321
+ */
322
+ public function check_hide_cart_checkout_pages() {
323
+
324
+ return $this->check_user_admin_enable() && $this->disable_shop();
325
+
326
+ }
327
+
328
+ /**
329
+ * Avoid Cart and Checkout Pages to be visited
330
+ *
331
+ * @return void
332
+ * @since 1.0.4
333
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
334
+ */
335
+ public function check_pages_redirect() {
336
+
337
+ $cart = is_page( wc_get_page_id( 'cart' ) );
338
+ $checkout = is_page( wc_get_page_id( 'checkout' ) );
339
+
340
+ wp_reset_query();
341
+
342
+ if ( $cart || $checkout ) {
343
+ wp_redirect( home_url() );
344
+ exit;
345
+ }
346
+
347
+ }
348
+
349
+ /**
350
+ * Disable Shop
351
+ *
352
+ * @return boolean
353
+ * @since 1.0.0
354
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
355
+ */
356
+ public function disable_shop() {
357
+
358
+ $disabled = false;
359
+
360
+ if ( get_option( 'ywctm_disable_shop' ) === 'yes' ) {
361
+
362
+ global $post;
363
+
364
+ $post_id = isset( $post ) ? $post->ID : '';
365
+
366
+ if ( ywctm_is_wpml_active() && apply_filters( 'ywctm_wpml_use_default_language_settings', false ) ) {
367
+ $post_id = yit_wpml_object_id( $post_id, 'product', true, wpml_get_default_language() );
368
+ }
369
+
370
+ $disabled = $this->apply_catalog_mode( $post_id );
371
+
372
+ }
373
+
374
+ return $disabled;
375
+
376
+ }
377
+
378
+ /**
379
+ * Check if Catalog mode must be applied to current user
380
+ *
381
+ * @param $post_id integer
382
+ *
383
+ * @return boolean
384
+ * @since 1.3.0
385
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
386
+ */
387
+ public function apply_catalog_mode( $post_id ) {
388
+
389
+ $apply = false;
390
+
391
+ if ( ! $this->check_user_admin_enable() ) {
392
+ $target_users = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_apply_users', 'all' ), $post_id, 'ywctm_apply_users' );
393
+
394
+ $apply = 'all' === $target_users || ! is_user_logged_in();
395
+
396
+ if ( is_callable( array( $this, 'country_check' ) ) ) {
397
+ $apply = $this->country_check( $apply, $post_id );
398
+ }
399
+ }
400
+
401
+ return apply_filters( 'ywctm_applied_roles', $apply, $post_id );
402
+
403
+ }
404
+
405
+ /**
406
+ * Hides "Add to cart" button, if not excluded, from loop page
407
+ *
408
+ * @return void
409
+ * @since 1.0.0
410
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
411
+ */
412
+ public function hide_add_to_cart_loop() {
413
+
414
+ $ywctm_modify_woocommerce_after_shop_loop_item = apply_filters( 'ywctm_modify_woocommerce_after_shop_loop_item', true );
415
+
416
+ if ( $this->check_hide_add_cart() ) {
417
+
418
+ if ( $ywctm_modify_woocommerce_after_shop_loop_item ) {
419
+ remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
420
+ }
421
+ add_filter( 'woocommerce_loop_add_to_cart_link', '__return_empty_string', 10 );
422
+
423
+ } else {
424
+
425
+ if ( $ywctm_modify_woocommerce_after_shop_loop_item ) {
426
+ add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
427
+ }
428
+ remove_filter( 'woocommerce_loop_add_to_cart_link', '__return_empty_string', 10 );
429
+
430
+ }
431
+
432
+ }
433
+
434
+ /**
435
+ * Checks if "Add to cart" needs to be hidden
436
+ *
437
+ * @param $single $boolean
438
+ * @param $product_id integer|boolean
439
+ * @param $ignore_variations boolean
440
+ *
441
+ * @return boolean
442
+ * @since 1.0.0
443
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
444
+ */
445
+ public function check_hide_add_cart( $single = false, $product_id = false, $ignore_variations = false ) {
446
+
447
+ $hide = false;
448
+
449
+ if ( apply_filters( 'ywctm_prices_only_on_cart', false ) ) {
450
+ return $hide;
451
+ }
452
+
453
+ if ( $this->disable_shop() ) {
454
+ $hide = true;
455
+ } else {
456
+
457
+ global $post;
458
+
459
+ if ( ! $product_id && ! isset( $post ) ) {
460
+ return false;
461
+ }
462
+
463
+ $product_id = ( $product_id ) ? $product_id : $post->ID;
464
+
465
+ if ( ywctm_is_wpml_active() && apply_filters( 'ywctm_wpml_use_default_language_settings', false ) ) {
466
+ $product_id = yit_wpml_object_id( $product_id, 'product', true, wpml_get_default_language() );
467
+ }
468
+
469
+ $product = wc_get_product( $product_id );
470
+
471
+ if ( ! $product ) {
472
+ return false;
473
+ }
474
+
475
+ $atc_settings_general = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_add_to_cart_settings' ), $product_id, 'ywctm_hide_add_to_cart_settings' );
476
+ $behavior = $atc_settings_general['action'];
477
+ $where = $atc_settings_general['where'];
478
+ $can_hide = true;
479
+
480
+ if ( ! $single ) {
481
+ $hide_variations = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_variations' ), $product_id, 'ywctm_hide_variations' );
482
+ //APPLY_FILTERS: ywctm_hide_variations_on_loop: hide variations only on loop
483
+ $hide_variations = apply_filters( 'ywctm_hide_variations_on_loop', $hide_variations );
484
+ $is_variable = $product->is_type( 'variable' );
485
+ $is_grouped = $product->is_type( 'grouped' );
486
+ $can_hide = ( ( $is_variable || $is_grouped ) ? 'yes' === $hide_variations : true );
487
+ }
488
+
489
+ if ( $ignore_variations ) {
490
+ $can_hide = true;
491
+ }
492
+
493
+ if ( 'all' !== $atc_settings_general['items'] ) {
494
+ $behavior = apply_filters( 'ywctm_get_exclusion', $behavior, $product_id, 'atc' );
495
+ }
496
+
497
+ if ( ! $single ) {
498
+ $hide_add_to_cart = ( ( 'hide' === $behavior && 'all' === $where ) || ( 'hide' === $behavior && 'shop' === $where ) || ( 'show' === $behavior && 'product' === $where ) );
499
+ } else {
500
+ $hide_add_to_cart = ( ( 'hide' === $behavior && 'all' === $where ) || ( 'hide' === $behavior && 'product' === $where ) || ( 'show' === $behavior && 'shop' === $where ) );
501
+ }
502
+
503
+ //Set "Add to cart" button as hidden
504
+ if ( $hide_add_to_cart && $this->apply_catalog_mode( $product_id ) && $can_hide ) {
505
+ $hide = true;
506
+ }
507
+
508
+ //If "Add to cart" button is set as visible but price is hidden then hide it anyway
509
+ if ( apply_filters( 'ywctm_check_price_hidden', false, $product_id ) && $can_hide ) {
510
+ $hide = true;
511
+ }
512
+
513
+ if ( ! $single ) {
514
+ $hide = apply_filters( 'ywctm_hide_on_loop_anyway', $hide, $product_id );
515
+ } else {
516
+ $hide = apply_filters( 'ywctm_hide_on_single_anyway', $hide, $product_id );
517
+ }
518
+ }
519
+
520
+ return $hide;
521
+
522
+ }
523
+
524
+ /**
525
+ * Add plugin CSS rules if needed
526
+ *
527
+ * @return void
528
+ * @since 2.0.0
529
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
530
+ */
531
+ public function enqueue_styles_frontend() {
532
+
533
+ //APPLY_FILTERS: ywctm_css_classes: CSS selector of elements that should be hidden
534
+ $classes = apply_filters( 'ywctm_css_classes', array() );
535
+
536
+ if ( ! empty( $classes ) ) {
537
+ wp_enqueue_style( 'ywctm-frontend', yit_load_css_file( YWCTM_ASSETS_URL . 'css/frontend.css' ), array(), YWCTM_VERSION );
538
+ $css = implode( ', ', $classes ) . '{display: none !important}';
539
+ wp_add_inline_style( 'ywctm-frontend', $css );
540
+ }
541
+
542
+ }
543
+
544
+ /**
545
+ * Hide cart widget if needed
546
+ *
547
+ * @param $classes array
548
+ *
549
+ * @return array
550
+ * @since 1.3.7
551
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
552
+ */
553
+ public function hide_cart_widget( $classes ) {
554
+
555
+ if ( $this->disable_shop() ) {
556
+
557
+ $args = array(
558
+ '.widget.woocommerce.widget_shopping_cart',
559
+ );
560
+
561
+ $theme_name = ywctm_get_theme_name();
562
+
563
+ if ( 'storefront' === $theme_name ) {
564
+ $args[] = '.site-header-cart.menu';
565
+ }
566
+ //APPLY_FILTERS: ywctm_cart_widget_classes: CSS selector of cart widgets
567
+ $classes = array_merge( $classes, apply_filters( 'ywctm_cart_widget_classes', $args ) );
568
+
569
+ }
570
+
571
+ return $classes;
572
+
573
+ }
574
+
575
+ /**
576
+ * Hides "Add to cart" button from single product page
577
+ *
578
+ * @param $classes array
579
+ *
580
+ * @return array
581
+ * @since 1.4.4
582
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
583
+ */
584
+ public function hide_atc_single_page( $classes ) {
585
+
586
+ if ( $this->check_hide_add_cart( true ) && is_singular() ) {
587
+
588
+ $hide_variations = get_option( 'ywctm_hide_variations' );
589
+
590
+ $args = array(
591
+ 'form.cart button.single_add_to_cart_button',
592
+ );
593
+
594
+ if ( ! class_exists( 'YITH_YWRAQ_Frontend' ) || ( ( class_exists( 'YITH_Request_Quote_Premium' ) ) && ! YITH_Request_Quote_Premium()->check_user_type() ) ) {
595
+ $args[] = 'form.cart .quantity';
596
+ }
597
+
598
+ if ( 'yes' === $hide_variations ) {
599
+ $args[] = 'table.variations';
600
+ $args[] = 'form.variations_form';
601
+ $args[] = '.single_variation_wrap .variations_button';
602
+ }
603
+
604
+ //APPLY_FILTERS: ywctm_cart_widget_classes: CSS selector of add to cart buttons
605
+ $classes = array_merge( $classes, apply_filters( 'ywctm_catalog_classes', $args ) );
606
+
607
+ }
608
+
609
+ return $classes;
610
+
611
+ }
612
+
613
+ /**
614
+ * Checks if "Add to cart" needs to be avoided
615
+ *
616
+ * @param $passed boolean
617
+ * @param $product_id integer
618
+ *
619
+ * @return boolean
620
+ * @since 1.0.5
621
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
622
+ */
623
+ public function avoid_add_to_cart( $passed, $product_id ) {
624
+
625
+ if ( apply_filters( 'ywctm_prices_only_on_cart', false ) ) {
626
+ return $passed;
627
+ }
628
+
629
+ if ( $this->disable_shop() ) {
630
+
631
+ $passed = false;
632
+
633
+ } else {
634
+
635
+ if ( ywctm_is_wpml_active() && apply_filters( 'ywctm_wpml_use_default_language_settings', false ) ) {
636
+ $product_id = yit_wpml_object_id( $product_id, 'product', true, wpml_get_default_language() );
637
+ }
638
+
639
+ $product = wc_get_product( $product_id );
640
+
641
+ if ( ! $product ) {
642
+ return true;
643
+ }
644
+
645
+ $atc_settings_general = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_add_to_cart_settings' ), $product_id, 'ywctm_hide_add_to_cart_settings' );
646
+ $behavior = $atc_settings_general['action'];
647
+ $where = $atc_settings_general['where'];
648
+
649
+ if ( 'all' !== $atc_settings_general['items'] ) {
650
+ $behavior = apply_filters( 'ywctm_get_exclusion', $behavior, $product_id, 'atc' );
651
+ }
652
+
653
+ $hide_add_to_cart = ( 'hide' === $behavior && 'all' === $where );
654
+
655
+ //Set "Add to cart" button as hidden
656
+ if ( $hide_add_to_cart && $this->apply_catalog_mode( $product_id ) ) {
657
+ $passed = false;
658
+ }
659
+
660
+ //If "Add to cart" button is set as visible but price is hidden then hide it anyway
661
+ if ( apply_filters( 'ywctm_check_price_hidden', false, $product_id ) ) {
662
+ $passed = false;
663
+ }
664
+
665
+ if ( apply_filters( 'ywctm_hide_on_single_anyway', false, $product_id ) && apply_filters( 'ywctm_hide_on_loop_anyway', false, $product_id ) ) {
666
+ $passed = false;
667
+ }
668
+ }
669
+
670
+ return $passed;
671
+
672
+ }
673
+
674
+ /**
675
+ * Checks if "Add to cart" needs to be hidden
676
+ *
677
+ * @param $x boolean @deprecated
678
+ * @param $product_id integer|boolean
679
+ *
680
+ * @return bool
681
+ * @since 1.0.2
682
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
683
+ */
684
+ public function check_add_to_cart_single( $x = true, $product_id = false ) {
685
+ return $this->check_hide_add_cart( true, $product_id );
686
+ }
687
+
688
+ /**
689
+ * Checks if "Add to cart" needs to be hidden from loop page
690
+ *
691
+ * @return boolean
692
+ * @since 1.0.6
693
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
694
+ */
695
+ public function check_hide_add_cart_loop() {
696
+ return $this->check_hide_add_cart();
697
+ }
698
+
699
+ /**
700
+ * PLUGIN INTEGRATIONS
701
+ */
702
+
703
+ /**
704
+ * Say if the code is execute by quick view
705
+ *
706
+ * @return boolean
707
+ * @since 1.0.7
708
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
709
+ */
710
+ public function is_quick_view() {
711
+
712
+ $actions = apply_filters( 'ywctm_quick_view_actions', array( 'yith_load_product_quick_view', 'yit_load_product_quick_view' ) );
713
+
714
+ return defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions, true );
715
+ }
716
+
717
+ /**
718
+ * Hides add to cart on wishlist
719
+ *
720
+ * @param $value string
721
+ * @param $product WC_Product
722
+ *
723
+ * @return string
724
+ * @since 1.2.2
725
+ * @author Alberto Ruggiero <alberto.ruggiero@yithemes.com>
726
+ */
727
+ public function hide_add_to_cart_wishlist( $value, $product ) {
728
+
729
+ global $yith_wcwl_is_wishlist;
730
+
731
+ if ( $this->check_hide_add_cart( true, $product->get_id() ) && $yith_wcwl_is_wishlist ) {
732
+
733
+ $value = '';
734
+
735
+ }
736
+
737
+ return $value;
738
+
739
+ }
740
+
741
+
742
+ /**
743
+ * YITH FRAMEWORK
744
+ */
745
+
746
+ /**
747
+ * Load plugin framework
748
+ *
749
+ * @return void
750
+ * @since 1.0.0
751
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
752
+ */
753
+ public function plugin_fw_loader() {
754
+ if ( ! defined( 'YIT_CORE_PLUGIN' ) ) {
755
+ global $plugin_fw_data;
756
+ if ( ! empty( $plugin_fw_data ) ) {
757
+ $plugin_fw_file = array_shift( $plugin_fw_data );
758
+ require_once( $plugin_fw_file );
759
+ }
760
+ }
761
+ }
762
+
763
+ /**
764
+ * Premium Tab Template
765
+ *
766
+ * Load the premium tab template on admin page
767
+ *
768
+ * @return void
769
+ * @since 1.0.0
770
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
771
+ */
772
+ public function premium_tab() {
773
+ $premium_tab_template = YWCTM_TEMPLATE_PATH . '/admin/' . $this->_premium;
774
+ if ( file_exists( $premium_tab_template ) ) {
775
+ include_once( $premium_tab_template );
776
+ }
777
+ }
778
+
779
+ /**
780
+ * Get the premium landing uri
781
+ *
782
+ * @return string The premium landing link
783
+ * @since 1.0.0
784
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
785
+ */
786
+ public function get_premium_landing_uri() {
787
+ return $this->_premium_landing;
788
+ }
789
+
790
+ /**
791
+ * Action Links
792
+ *
793
+ * add the action links to plugin admin page
794
+ *
795
+ * @param $links | links plugin array
796
+ *
797
+ * @return mixed
798
+ * @since 1.0.0
799
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
800
+ * @use plugin_action_links_{$plugin_file_name}
801
+ */
802
+ public function action_links( $links ) {
803
+
804
+ $links = yith_add_action_links( $links, $this->_panel_page, false );
805
+
806
+ return $links;
807
+
808
+ }
809
+
810
+ /**
811
+ * Plugin row meta
812
+ *
813
+ * add the action links to plugin admin page
814
+ *
815
+ * @param $new_row_meta_args
816
+ * @param $plugin_meta
817
+ * @param $plugin_file
818
+ * @param $plugin_data
819
+ * @param $status
820
+ * @param $init_file
821
+ *
822
+ * @return array
823
+ * @since 1.0.0
824
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
825
+ * @use plugin_row_meta
826
+ */
827
+ public function plugin_row_meta( $new_row_meta_args, $plugin_meta, $plugin_file, $plugin_data, $status, $init_file = 'YWCTM_FREE_INIT' ) {
828
+
829
+ if ( defined( $init_file ) && constant( $init_file ) === $plugin_file ) {
830
+ $new_row_meta_args['slug'] = YWCTM_SLUG;
831
+ }
832
+
833
+ return $new_row_meta_args;
834
+
835
+ }
836
+
837
+ }
838
+
839
+ }
class.yith-woocommerce-catalog-mode.php DELETED
@@ -1,966 +0,0 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
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 = 'https://yithemes.com/themes/plugins/yith-woocommerce-catalog-mode/';
37
-
38
- /**
39
- * @var string Plugin official documentation
40
- */
41
- protected $_official_documentation = 'https://docs.yithemes.com/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 void
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( 'yith_show_plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 5 );
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() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
103
-
104
- if ( $this->disable_shop() ) {
105
-
106
- $priority = has_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ) );
107
- remove_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ), $priority );
108
-
109
- }
110
-
111
- add_action( 'wp', array( $this, 'check_pages_redirect' ) );
112
- add_action( 'get_pages', array( $this, 'hide_cart_checkout_pages' ) );
113
- //add_action( 'woocommerce_single_product_summary', array( $this, 'hide_add_to_cart_single' ), 10 );
114
-
115
- add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'hide_add_to_cart_loop' ), 5 );
116
- add_filter( 'woocommerce_add_to_cart_validation', array( $this, 'avoid_add_to_cart' ), 10, 2 );
117
-
118
- add_action( 'wp_head', array( $this, 'add_ywctm_styles' ) );
119
- add_filter( 'ywctm_css_classes', array( $this, 'hide_atc_single_page' ) );
120
- add_filter( 'ywctm_css_classes', array( $this, 'hide_cart_widget' ) );
121
-
122
- if ( defined( 'YITH_WCWL' ) && YITH_WCWL ) {
123
- add_filter( 'woocommerce_loop_add_to_cart_link', array( $this, 'hide_add_to_cart_wishlist' ), 10, 2 );
124
- }
125
-
126
- }
127
-
128
- }
129
-
130
- }
131
-
132
- /**
133
- * ADMIN FUNCTIONS
134
- */
135
-
136
- /**
137
- * Add a panel under YITH Plugins tab
138
- *
139
- * @since 1.0.0
140
- * @return void
141
- * @author Alberto Ruggiero
142
- * @use /Yit_Plugin_Panel class
143
- * @see plugin-fw/lib/yit-plugin-panel.php
144
- */
145
- public function add_menu_page() {
146
-
147
- if ( ! empty( $this->_panel ) ) {
148
- return;
149
- }
150
-
151
- $admin_tabs = array();
152
-
153
- if ( defined( 'YWCTM_PREMIUM' ) ) {
154
- $admin_tabs['premium-settings'] = __( 'Settings', 'yith-woocommerce-catalog-mode' );
155
- $admin_tabs['exclusions'] = __( 'Exclusion List', 'yith-woocommerce-catalog-mode' );
156
- $admin_tabs['alternative-text'] = __( 'Texts replacing price', 'yith-woocommerce-catalog-mode' );
157
- $admin_tabs['custom-url'] = __( 'Custom Button Url List', 'yith-woocommerce-catalog-mode' );
158
-
159
- if ( $this->is_multivendor_active() ) {
160
- $admin_tabs['vendors'] = __( 'Vendor Exclusion List', 'yith-woocommerce-catalog-mode' );
161
- }
162
-
163
- } else {
164
- $admin_tabs['settings'] = __( 'Settings', 'yith-woocommerce-catalog-mode' );
165
- $admin_tabs['premium-landing'] = __( 'Premium Version', 'yith-woocommerce-catalog-mode' );
166
- }
167
-
168
-
169
- $args = array(
170
- 'create_menu_page' => true,
171
- 'parent_slug' => '',
172
- 'page_title' => __( 'Catalog Mode', 'yith-woocommerce-catalog-mode' ),
173
- 'menu_title' => 'Catalog Mode',
174
- 'capability' => 'manage_options',
175
- 'parent' => '',
176
- 'parent_page' => 'yith_plugin_panel',
177
- 'page' => $this->_panel_page,
178
- 'admin-tabs' => $admin_tabs,
179
- 'options-path' => YWCTM_DIR . '/plugin-options'
180
- );
181
-
182
- $this->_panel = new YIT_Plugin_Panel_WooCommerce( $args );
183
- }
184
-
185
- /**
186
- * FRONTEND FUNCTIONS
187
- */
188
-
189
- /**
190
- * Disable Shop
191
- *
192
- * @since 1.0.0
193
- * @return boolean
194
- * @author Alberto Ruggiero
195
- */
196
- public function disable_shop() {
197
-
198
- $disabled = false;
199
-
200
- if ( get_option( 'ywctm_hide_cart_header' ) == 'yes' ) {
201
-
202
- global $post;
203
-
204
- $post_id = isset( $post ) ? $post->ID : '';
205
-
206
- global $sitepress;
207
- $has_wpml = ! empty( $sitepress ) ? true : false;
208
-
209
- if ( $has_wpml && apply_filters( 'ywctm_wpml_use_default_language_settings', false ) ) {
210
- $post_id = yit_wpml_object_id( $post_id, 'product', true, wpml_get_default_language() );
211
- }
212
-
213
- $disabled = $this->apply_catalog_mode( $post_id );
214
-
215
- }
216
-
217
- return $disabled;
218
-
219
- }
220
-
221
- /**
222
- * Adds Catalog Mode styles
223
- *
224
- * @since 1.4.4
225
- * @return void
226
- * @author Alberto Ruggiero
227
- */
228
- public function add_ywctm_styles() {
229
-
230
- $classes = apply_filters( 'ywctm_css_classes', array() );
231
-
232
- if ( $classes ) {
233
-
234
- ob_start();
235
-
236
- ?>
237
- <style type="text/css">
238
-
239
- <?php echo implode( ', ', $classes ); ?>
240
- {
241
- display: none !important
242
- }
243
-
244
- </style>
245
-
246
- <?php
247
-
248
- echo ob_get_clean();
249
- }
250
-
251
- }
252
-
253
- /**
254
- * Check if Catalog mode must be applied to current user
255
- *
256
- * @since 1.3.0
257
- *
258
- * @param $post_id
259
- *
260
- * @return bool
261
- * @author Alberto Ruggiero
262
- */
263
- public function apply_catalog_mode( $post_id ) {
264
-
265
- $target_users = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_price_users', 'all' ), $post_id, 'ywctm_hide_price_users' );
266
-
267
- if ( $target_users == 'country' && defined( 'YWCTM_PREMIUM' ) ) {
268
-
269
- return $this->country_check( $post_id );
270
-
271
- } elseif ( $target_users == 'all' ) {
272
-
273
- return apply_filters( 'ywctm_applied_roles', true );
274
-
275
- } else {
276
-
277
- return apply_filters( 'ywctm_applied_roles', ! is_user_logged_in() );
278
-
279
- }
280
-
281
- }
282
-
283
- /**
284
- * Check if catalog mode is enabled for administrator
285
- *
286
- * @since 1.0.2
287
- * @return bool
288
- * @author Alberto Ruggiero
289
- */
290
- public function check_user_admin_enable() {
291
-
292
- return ! ( current_user_can( 'administrator' ) && is_user_logged_in() && get_option( 'ywctm_admin_view' ) == 'no' );
293
-
294
- }
295
-
296
- /**
297
- * Checks if "Cart & Checkout pages" needs to be hidden
298
- *
299
- * @since 1.0.2
300
- * @return bool
301
- * @author Alberto Ruggiero
302
- */
303
- public function check_hide_cart_checkout_pages() {
304
-
305
- return get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() && $this->disable_shop();
306
-
307
- }
308
-
309
- /**
310
- * Hides "Add to cart" button from single product page
311
- *
312
- * @since 1.4.4
313
- *
314
- * @param $classes
315
- *
316
- * @return array
317
- * @author Alberto Ruggiero
318
- */
319
- public function hide_atc_single_page( $classes ) {
320
-
321
- if ( $this->check_add_to_cart_single( true ) && is_singular() ) {
322
-
323
- $hide_variations = get_option( 'ywctm_hide_variations' );
324
-
325
- $args = array(
326
- 'form.cart button.single_add_to_cart_button'
327
- );
328
-
329
- if ( ! class_exists( 'YITH_YWRAQ_Frontend' ) || ( ( class_exists( 'YITH_Request_Quote_Premium' ) ) && ! YITH_Request_Quote_Premium()->check_user_type() ) ) {
330
-
331
- $args[] = 'form.cart .quantity';
332
-
333
- }
334
-
335
- if ( $hide_variations == 'yes' ) {
336
-
337
- $args[] = 'table.variations';
338
- $args[] = 'form.variations_form';
339
- $args[] = '.single_variation_wrap .variations_button';
340
-
341
- }
342
-
343
- $classes = array_merge( $classes, apply_filters( 'ywctm_catalog_classes', $args ) );
344
-
345
- }
346
-
347
- return $classes;
348
-
349
-
350
- }
351
-
352
- /**
353
- * Checks if "Add to cart" needs to be hidden
354
- *
355
- * @since 1.0.2
356
- *
357
- * @param $priority
358
- * @param $product_id
359
- *
360
- * @return bool
361
- * @author Alberto Ruggiero
362
- */
363
- public function check_add_to_cart_single( $priority = true, $product_id = false ) {
364
-
365
- $hide = false;
366
-
367
- if ( apply_filters( 'ywctm_prices_only_on_cart', false ) ) {
368
- return $hide;
369
- }
370
-
371
- if ( get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() ) {
372
-
373
- if ( $this->disable_shop() ) {
374
-
375
- $hide = true;
376
-
377
- } else {
378
-
379
- global $post;
380
-
381
- if ( ! $product_id && ! isset( $post ) ) {
382
- return false;
383
- }
384
-
385
- $post_id = ( $product_id ) ? $product_id : $post->ID;
386
-
387
- global $sitepress;
388
- $has_wpml = ! empty( $sitepress ) ? true : false;
389
-
390
- if ( $has_wpml && apply_filters( 'ywctm_wpml_use_default_language_settings', false ) ) {
391
- $post_id = yit_wpml_object_id( $post->ID, 'product', true, wpml_get_default_language() );
392
- }
393
-
394
- $product = wc_get_product( $post_id );
395
-
396
- if ( ! $product ) {
397
- return false;
398
- }
399
-
400
- $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' );
401
-
402
- if ( $hide_add_to_cart_single != 'yes' ) {
403
- $hide_add_to_cart_single = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_price' ), $post_id, 'ywctm_hide_price' );
404
- }
405
-
406
- if ( $hide_add_to_cart_single == 'yes' ) {
407
-
408
- if ( $this->apply_catalog_mode( $post_id ) ) {
409
-
410
- $enable_exclusion = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart' ), $post_id, 'ywctm_exclude_hide_add_to_cart' );
411
- $exclude_catalog = apply_filters( 'ywctm_get_exclusion', $product->get_meta( '_ywctm_exclude_catalog_mode' ), $post_id, '_ywctm_exclude_catalog_mode' );
412
-
413
- $hide = ( $enable_exclusion != 'yes' ? true : ( $exclude_catalog != 'yes' ? true : false ) );
414
-
415
- $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' );
416
-
417
- if ( $enable_exclusion == 'yes' && $reverse_criteria == 'yes' ) {
418
-
419
- $hide = ! $hide;
420
-
421
- }
422
-
423
- }
424
-
425
- }
426
-
427
- if ( apply_filters( 'ywctm_check_price_hidden', false, $post_id ) ) {
428
-
429
- $hide = true;
430
-
431
- }
432
-
433
- $hide = apply_filters( 'ywctm_hide_on_single_anyway', $hide, $post_id );
434
-
435
- }
436
-
437
- }
438
-
439
- return $hide;
440
-
441
- }
442
-
443
- /**
444
- * Checks if "Add to cart" needs to be avoided
445
- *
446
- * @since 1.0.5
447
- *
448
- * @param $passed
449
- * @param $product_id
450
- *
451
- * @return bool
452
- * @author Alberto Ruggiero
453
- */
454
- public function avoid_add_to_cart( $passed, $product_id ) {
455
-
456
- if ( apply_filters( 'ywctm_prices_only_on_cart', false ) ) {
457
- return $passed;
458
- }
459
-
460
- if ( get_option( 'ywctm_enable_plugin' ) == 'yes' && $this->check_user_admin_enable() ) {
461
-
462
- if ( $this->disable_shop() ) {
463
-
464
- $passed = false;
465
-
466
- } else {
467
-
468
- global $sitepress;
469
- $has_wpml = ! empty( $sitepress ) ? true : false;
470
-
471
- if ( $has_wpml && apply_filters( 'ywctm_wpml_use_default_language_settings', false ) ) {
472
- $product_id = yit_wpml_object_id( $product_id, 'product', true, wpml_get_default_language() );
473
- }
474
-
475
- $product = wc_get_product( $product_id );
476
-
477
- if ( ! $product ) {
478
- return true;
479
- }
480
-
481
- $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' );
482
-
483
- if ( $hide_add_to_cart_single == 'yes' ) {
484
-
485
- if ( $this->apply_catalog_mode( $product_id ) ) {
486
-
487
- $enable_exclusion = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart' ), $product_id, 'ywctm_exclude_hide_add_to_cart' );
488
- $exclude_catalog = apply_filters( 'ywctm_get_exclusion', $product->get_meta( '_ywctm_exclude_catalog_mode' ), $product_id, '_ywctm_exclude_catalog_mode' );
489
-
490
- $passed = ( $enable_exclusion != 'yes' ? false : ( $exclude_catalog != 'yes' ? false : true ) );
491
-
492
- $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' );
493
-
494
- if ( $enable_exclusion == 'yes' && $reverse_criteria == 'yes' ) {
495
-
496
- $passed = ! $passed;
497
-
498
- }
499
-
500
- }
501
-
502
- }
503
-
504
- if ( apply_filters( 'ywctm_check_price_hidden', false, $product_id ) ) {
505
-
506
- $passed = false;
507
-
508
- }
509
-
510
- if ( apply_filters( 'ywctm_hide_on_single_anyway', false, $product_id ) && apply_filters( 'ywctm_hide_on_loop_anyway', false, $product_id ) ) {
511
-
512
- $passed = false;
513
-
514
- }
515
-
516
- }
517
-
518
- }
519
-
520
- return $passed;
521
- }
522
-
523
- /**
524
- * Checks if "Add to cart" needs to be hidden from loop page
525
- *
526
- * @since 1.0.6
527
- * @return bool
528
- * @author Alberto Ruggiero
529
- */
530
- public function check_hide_add_cart_loop() {
531
-
532
- $hide = false;
533
-
534
- if ( apply_filters( 'ywctm_prices_only_on_cart', false ) ) {
535
- return $hide;
536
- }
537
-
538
- if ( $this->disable_shop() ) {
539
-
540
- $hide = true;
541
-
542
- } else {
543
-
544
- global $product;
545
-
546
- if ( ! $product ) {
547
- return $hide;
548
- }
549
-
550
- $product_id = $product->get_id();
551
-
552
- global $sitepress;
553
- $has_wpml = ! empty( $sitepress ) ? true : false;
554
-
555
- if ( $has_wpml && apply_filters( 'ywctm_wpml_use_default_language_settings', false ) ) {
556
- $product_id = yit_wpml_object_id( $product_id, 'product', true, wpml_get_default_language() );
557
- $product = wc_get_product( $product_id );
558
- }
559
-
560
- if ( ! $product ) {
561
- return $hide;
562
- }
563
-
564
- $hide_add_to_cart_loop = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_add_to_cart_loop' ), $product_id, 'ywctm_hide_add_to_cart_loop' );
565
- $hide_variations = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_variations' ), $product_id, 'ywctm_hide_variations' );
566
- $hide_variations = apply_filters( 'ywctm_hide_variations_on_loop', $hide_variations );
567
-
568
- $is_variable = $product->is_type( 'variable' );
569
- $is_grouped = $product->is_type( 'grouped' );
570
-
571
-
572
- $can_hide = ( ( $is_variable || $is_grouped ) ? $hide_variations == 'yes' : true );
573
-
574
- if ( $hide_add_to_cart_loop != 'yes' ) {
575
- $hide_add_to_cart_loop = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_hide_price' ), $product_id, 'ywctm_hide_price' );
576
- }
577
-
578
- if ( $hide_add_to_cart_loop == 'yes' ) {
579
-
580
- if ( $this->apply_catalog_mode( $product_id ) ) {
581
-
582
- $enable_exclusion = apply_filters( 'ywctm_get_vendor_option', get_option( 'ywctm_exclude_hide_add_to_cart' ), $product_id, 'ywctm_exclude_hide_add_to_cart' );
583
- $exclude_catalog = apply_filters( 'ywctm_get_exclusion', $product->get_meta( '_ywctm_exclude_catalog_mode' ), $product_id, '_ywctm_exclude_catalog_mode' );
584
-
585
- $hide = ( $enable_exclusion != 'yes' ? true : ( $exclude_catalog != 'yes' ? true : false ) );
586
-
587
- $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' );
588
-
589
- if ( ( $is_variable || $is_grouped ) && $enable_exclusion != 'yes' ) {
590
-
591
- $hide = $can_hide;
592
-
593
- }
594
-
595
- if ( $enable_exclusion == 'yes' && $reverse_criteria == 'yes' ) {
596
-
597
- $hide = ! $hide;
598
-
599
- if ( ( $is_variable || $is_grouped ) && ! $can_hide ) {
600
-
601
- $hide = false;
602
-
603
- }
604
-
605
- }
606
-
607
-
608
- }
609
-
610
- }
611
-
612
- if ( apply_filters( 'ywctm_check_price_hidden', false, $product_id ) && $can_hide ) {
613
-
614
- $hide = true;
615
-
616
- }
617
-
618
- $hide = apply_filters( 'ywctm_hide_on_loop_anyway', $hide, $product_id );
619
-
620
- }
621
-
622
- return $hide;
623
-
624
- }
625
-
626
- /**
627
- * Hides "Add to cart" button, if not excluded, from loop page
628
- *
629
- * @since 1.0.0
630
- * @return void
631
- * @author Alberto Ruggiero
632
- */
633
- public function hide_add_to_cart_loop() {
634
-
635
- $ywctm_modify_woocommerce_after_shop_loop_item = apply_filters( 'ywctm_modify_woocommerce_after_shop_loop_item', true );
636
-
637
- if ( $this->check_hide_add_cart_loop() ) {
638
-
639
- if ( $ywctm_modify_woocommerce_after_shop_loop_item ) {
640
- remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
641
- }
642
- add_filter( 'woocommerce_loop_add_to_cart_link', '__return_empty_string', 10 );
643
-
644
- } else {
645
-
646
- if ( $ywctm_modify_woocommerce_after_shop_loop_item ) {
647
- add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
648
- }
649
-
650
- remove_filter( 'woocommerce_loop_add_to_cart_link', '__return_empty_string', 10 );
651
-
652
- }
653
-
654
- }
655
-
656
- /**
657
- * Hide cart widget if needed
658
- *
659
- * @since 1.3.7
660
- *
661
- * @param $classes
662
- *
663
- * @return array
664
- * @author Alberto Ruggiero
665
- */
666
- public function hide_cart_widget( $classes ) {
667
-
668
- if ( $this->disable_shop() ) {
669
-
670
- $args = array(
671
- '.widget.woocommerce.widget_shopping_cart'
672
- );
673
-
674
- $wp_theme = wp_get_theme();
675
- $theme_name = is_child_theme() ? $wp_theme->get_template() : strtolower( $wp_theme->Name );
676
-
677
- if ( 'storefront' == $theme_name ) {
678
-
679
- $args[] = '.site-header-cart.menu';
680
-
681
- }
682
-
683
- $classes = array_merge( $classes, apply_filters( 'ywctm_cart_widget_classes', $args ) );
684
-
685
- }
686
-
687
- return $classes;
688
-
689
- }
690
-
691
- /**
692
- * Avoid Cart and Checkout Pages to be visited
693
- *
694
- * @since 1.0.4
695
- * @return void
696
- * @author Alberto Ruggiero
697
- */
698
- public function check_pages_redirect() {
699
-
700
- if ( $this->disable_shop() ) {
701
-
702
- $cart = is_page( wc_get_page_id( 'cart' ) );
703
- $checkout = is_page( wc_get_page_id( 'checkout' ) );
704
-
705
- wp_reset_query();
706
-
707
- if ( $cart || $checkout ) {
708
-
709
- wp_redirect( home_url() );
710
- exit;
711
-
712
- }
713
-
714
- }
715
-
716
- }
717
-
718
- /**
719
- * Removes Cart and checkout pages from menu
720
- *
721
- * @since 1.0.4
722
- *
723
- * @param $pages
724
- *
725
- * @return mixed
726
- * @author Alberto Ruggiero
727
- */
728
- public function hide_cart_checkout_pages( $pages ) {
729
-
730
- if ( $this->disable_shop() ) {
731
-
732
- $excluded_pages = array(
733
- wc_get_page_id( 'cart' ),
734
- wc_get_page_id( 'checkout' )
735
- );
736
-
737
- for ( $i = 0; $i < count( $pages ); $i ++ ) {
738
- $page = &$pages[ $i ];
739
-
740
- if ( in_array( $page->ID, $excluded_pages ) ) {
741
-
742
- unset( $pages[ $i ] );
743
-
744
- }
745
-
746
- }
747
-
748
- }
749
-
750
- return $pages;
751
-
752
- }
753
-
754
- /**
755
- * Say if the code is execute by quick view
756
- *
757
- * @since 1.0.7
758
- * @return bool
759
- * @author Andrea Frascaspata <andrea.frascaspata@yithemes.com>
760
- */
761
- public function is_quick_view() {
762
- return defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && ( $_REQUEST['action'] == 'yith_load_product_quick_view' || $_REQUEST['action'] == 'yit_load_product_quick_view' );
763
- }
764
-
765
- /**
766
- * Hides add to cart on wishlist
767
- *
768
- * @since 1.2.2
769
- *
770
- * @param $value
771
- * @param $product WC_Product
772
- *
773
- * @return string
774
- * @author Alberto Ruggiero
775
- */
776
- public function hide_add_to_cart_wishlist( $value, $product ) {
777
-
778
- global $yith_wcwl_is_wishlist;
779
-
780
- if ( $this->check_add_to_cart_single( true, $product->get_id() ) && $yith_wcwl_is_wishlist ) {
781
-
782
- $value = '';
783
-
784
- }
785
-
786
- return $value;
787
-
788
- }
789
-
790
- /**
791
- * YITH FRAMEWORK
792
- */
793
-
794
- /**
795
- * Load plugin framework
796
- *
797
- * @since 1.0.0
798
- * @return void
799
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
800
- */
801
- public function plugin_fw_loader() {
802
- if ( ! defined( 'YIT_CORE_PLUGIN' ) ) {
803
- global $plugin_fw_data;
804
- if ( ! empty( $plugin_fw_data ) ) {
805
- $plugin_fw_file = array_shift( $plugin_fw_data );
806
- require_once( $plugin_fw_file );
807
- }
808
- }
809
- }
810
-
811
- /**
812
- * Premium Tab Template
813
- *
814
- * Load the premium tab template on admin page
815
- *
816
- * @since 1.0.0
817
- * @return void
818
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
819
- */
820
- public function premium_tab() {
821
- $premium_tab_template = YWCTM_TEMPLATE_PATH . '/admin/' . $this->_premium;
822
- if ( file_exists( $premium_tab_template ) ) {
823
- include_once( $premium_tab_template );
824
- }
825
- }
826
-
827
- /**
828
- * Get the premium landing uri
829
- *
830
- * @since 1.0.0
831
- * @return string The premium landing link
832
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
833
- */
834
- public function get_premium_landing_uri() {
835
- return $this->_premium_landing;
836
- }
837
-
838
- /**
839
- * Action Links
840
- *
841
- * add the action links to plugin admin page
842
- * @since 1.0.0
843
- *
844
- * @param $links | links plugin array
845
- *
846
- * @return mixed
847
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
848
- * @use plugin_action_links_{$plugin_file_name}
849
- */
850
- public function action_links( $links ) {
851
-
852
- $links = yith_add_action_links( $links, $this->_panel_page, false );
853
-
854
- return $links;
855
-
856
- }
857
-
858
- /**
859
- * Plugin row meta
860
- *
861
- * add the action links to plugin admin page
862
- *
863
- * @since 1.0.0
864
- *
865
- * @param $plugin_meta
866
- * @param $plugin_file
867
- * @param $plugin_data
868
- * @param $status
869
- * @param $init_file
870
- *
871
- * @return array
872
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
873
- * @use plugin_row_meta
874
- */
875
- public function plugin_row_meta( $new_row_meta_args, $plugin_meta, $plugin_file, $plugin_data, $status, $init_file = 'YWCTM_FREE_INIT' ) {
876
-
877
- if ( defined( $init_file ) && constant( $init_file ) == $plugin_file ) {
878
- $new_row_meta_args['slug'] = YWCTM_SLUG;
879
- }
880
-
881
- return $new_row_meta_args;
882
-
883
- }
884
-
885
- /**
886
- * DEPRECATED FUNCTIONS
887
- */
888
-
889
- /**
890
- * Hides "Add to cart" button from single product page
891
- *
892
- * @since 1.0.0
893
- *
894
- * @param $action
895
- *
896
- * @return void
897
- * @author Alberto Ruggiero
898
- */
899
- public function hide_add_to_cart_single( $action = '' ) {
900
-
901
- /*if ( $action == '' ) {
902
- $action = 'woocommerce_single_product_summary';
903
- }
904
-
905
- $priority = has_action( $action, 'woocommerce_template_single_add_to_cart' );
906
-
907
- if ( $this->check_add_to_cart_single( $priority ) ) {
908
-
909
-
910
- }*/
911
- return;
912
-
913
- }
914
-
915
- /**
916
- * Hide add to cart button in quick view
917
- *
918
- * @since 1.0.7
919
- * @return void
920
- * @author Francesco Licandro
921
- */
922
- public function hide_add_to_cart_quick_view() {
923
-
924
- if ( $this->check_add_to_cart_single( true ) ) {
925
-
926
- $hide_variations = get_option( 'ywctm_hide_variations' );
927
- ob_start();
928
-
929
- $args = array(
930
- 'form.cart button.single_add_to_cart_button'
931
- );
932
-
933
- if ( ! class_exists( 'YITH_YWRAQ_Frontend' ) || ( ( class_exists( 'YITH_Request_Quote_Premium' ) ) && ! YITH_Request_Quote_Premium()->check_user_type() ) ) {
934
-
935
- $args[] = 'form.cart .quantity';
936
-
937
- }
938
-
939
- if ( $hide_variations == 'yes' ) {
940
-
941
- $args[] = 'table.variations';
942
- $args[] = 'form.variations_form';
943
- $args[] = '.single_variation_wrap .variations_button';
944
-
945
- }
946
-
947
- $classes = implode( ', ', apply_filters( 'ywctm_catalog_classes', $args ) );
948
-
949
- ?>
950
- <style>
951
-
952
- <?php echo $classes; ?>
953
- {
954
- display: none !important
955
- }
956
-
957
- </style>
958
- <?php
959
- echo ob_get_clean();
960
- }
961
-
962
- }
963
-
964
- }
965
-
966
- }