2
2
/**
3
3
* Product Notes for WooCommerce - Main Class
4
4
*
5
- * @version 2.9.5
5
+ * @version 3.0.0
6
6
* @since 1.0.0
7
7
*
8
8
* @author Algoritmika Ltd
@@ -57,7 +57,7 @@ public static function instance() {
57
57
/**
58
58
* Alg_WC_Product_Notes Constructor.
59
59
*
60
- * @version 2.9.2
60
+ * @version 3.0.0
61
61
* @since 1.0.0
62
62
*
63
63
* @access public
@@ -69,6 +69,11 @@ function __construct() {
69
69
return ;
70
70
}
71
71
72
+ // Load libs
73
+ if ( is_admin () ) {
74
+ require_once plugin_dir_path ( ALG_WC_PRODUCT_NOTES_FILE ) . 'vendor/autoload.php ' ;
75
+ }
76
+
72
77
// Set up localisation
73
78
add_action ( 'init ' , array ( $ this , 'localize ' ) );
74
79
@@ -77,7 +82,7 @@ function __construct() {
77
82
78
83
// Pro
79
84
if ( 'internal-product-notes-for-woocommerce-pro.php ' === basename ( ALG_WC_PRODUCT_NOTES_FILE ) ) {
80
- require_once ( 'pro/class-alg-wc-pn-pro.php ' ) ;
85
+ require_once plugin_dir_path ( __FILE__ ) . 'pro/class-alg-wc-pn-pro.php ' ;
81
86
}
82
87
83
88
// Include required files
@@ -97,7 +102,11 @@ function __construct() {
97
102
* @since 2.3.0
98
103
*/
99
104
function localize () {
100
- load_plugin_textdomain ( 'product-notes-for-woocommerce ' , false , dirname ( plugin_basename ( ALG_WC_PRODUCT_NOTES_FILE ) ) . '/langs/ ' );
105
+ load_plugin_textdomain (
106
+ 'product-notes-for-woocommerce ' ,
107
+ false ,
108
+ dirname ( plugin_basename ( ALG_WC_PRODUCT_NOTES_FILE ) ) . '/langs/ '
109
+ );
101
110
}
102
111
103
112
/**
@@ -110,7 +119,10 @@ function localize() {
110
119
*/
111
120
function wc_declare_compatibility () {
112
121
if ( class_exists ( '\Automattic\WooCommerce\Utilities\FeaturesUtil ' ) ) {
113
- $ files = ( defined ( 'ALG_WC_PRODUCT_NOTES_FILE_FREE ' ) ? array ( ALG_WC_PRODUCT_NOTES_FILE , ALG_WC_PRODUCT_NOTES_FILE_FREE ) : array ( ALG_WC_PRODUCT_NOTES_FILE ) );
122
+ $ files = ( defined ( 'ALG_WC_PRODUCT_NOTES_FILE_FREE ' ) ?
123
+ array ( ALG_WC_PRODUCT_NOTES_FILE , ALG_WC_PRODUCT_NOTES_FILE_FREE ) :
124
+ array ( ALG_WC_PRODUCT_NOTES_FILE )
125
+ );
114
126
foreach ( $ files as $ file ) {
115
127
\Automattic \WooCommerce \Utilities \FeaturesUtil::declare_compatibility ( 'custom_order_tables ' , $ file , true );
116
128
}
@@ -120,57 +132,114 @@ function wc_declare_compatibility() {
120
132
/**
121
133
* includes.
122
134
*
123
- * @version 2.4 .0
135
+ * @version 3.0 .0
124
136
* @since 1.0.0
125
137
*/
126
138
function includes () {
127
- $ this ->core = require_once ( 'class-alg-wc-pn-core.php ' ) ;
139
+ $ this ->core = require_once plugin_dir_path ( __FILE__ ) . 'class-alg-wc-pn-core.php ' ;
128
140
}
129
141
130
142
/**
131
143
* admin.
132
144
*
133
- * @version 2.4 .0
145
+ * @version 3.0 .0
134
146
* @since 1.0.0
135
147
*/
136
148
function admin () {
149
+
137
150
// Action links
138
151
add_filter ( 'plugin_action_links_ ' . plugin_basename ( ALG_WC_PRODUCT_NOTES_FILE ), array ( $ this , 'action_links ' ) );
152
+
153
+ // "Recommendations" page
154
+ $ this ->add_cross_selling_library ();
155
+
156
+ // WC Settings tab as WPFactory submenu item
157
+ $ this ->move_wc_settings_tab_to_wpfactory_menu ();
158
+
139
159
// Settings
140
160
add_filter ( 'woocommerce_get_settings_pages ' , array ( $ this , 'add_woocommerce_settings_tab ' ) );
161
+
141
162
// Version updated
142
163
if ( get_option ( 'alg_wc_product_notes_version ' , '' ) !== $ this ->version ) {
143
164
add_action ( 'admin_init ' , array ( $ this , 'version_updated ' ) );
144
165
}
166
+
145
167
}
146
168
147
169
/**
148
170
* action_links.
149
171
*
150
- * @version 2.4 .0
172
+ * @version 3.0 .0
151
173
* @since 1.0.0
152
174
*
153
175
* @param mixed $links
154
176
* @return array
155
177
*/
156
178
function action_links ( $ links ) {
157
179
$ custom_links = array ();
158
- $ custom_links [] = '<a href=" ' . admin_url ( 'admin.php?page=wc-settings&tab=alg_wc_product_notes ' ) . '"> ' . __ ( 'Settings ' , 'woocommerce ' ) . '</a> ' ;
180
+ $ custom_links [] = '<a href=" ' . admin_url ( 'admin.php?page=wc-settings&tab=alg_wc_product_notes ' ) . '"> ' .
181
+ __ ( 'Settings ' , 'product-notes-for-woocommerce ' ) .
182
+ '</a> ' ;
159
183
if ( 'internal-product-notes-for-woocommerce.php ' === basename ( ALG_WC_PRODUCT_NOTES_FILE ) ) {
160
184
$ custom_links [] = '<a target="_blank" style="font-weight: bold; color: green;" href="https://wpfactory.com/item/product-notes-for-woocommerce/"> ' .
161
- __ ( 'Go Pro ' , 'product-notes-for-woocommerce ' ) . '</a> ' ;
185
+ __ ( 'Go Pro ' , 'product-notes-for-woocommerce ' ) .
186
+ '</a> ' ;
162
187
}
163
188
return array_merge ( $ custom_links , $ links );
164
189
}
165
190
191
+ /**
192
+ * add_cross_selling_library.
193
+ *
194
+ * @version 3.0.0
195
+ * @since 3.0.0
196
+ */
197
+ function add_cross_selling_library () {
198
+
199
+ if ( ! class_exists ( '\WPFactory\WPFactory_Cross_Selling\WPFactory_Cross_Selling ' ) ) {
200
+ return ;
201
+ }
202
+
203
+ $ cross_selling = new \WPFactory \WPFactory_Cross_Selling \WPFactory_Cross_Selling ();
204
+ $ cross_selling ->setup ( array ( 'plugin_file_path ' => ALG_WC_PRODUCT_NOTES_FILE ) );
205
+ $ cross_selling ->init ();
206
+
207
+ }
208
+
209
+ /**
210
+ * move_wc_settings_tab_to_wpfactory_menu.
211
+ *
212
+ * @version 3.0.0
213
+ * @since 3.0.0
214
+ */
215
+ function move_wc_settings_tab_to_wpfactory_menu () {
216
+
217
+ if ( ! class_exists ( '\WPFactory\WPFactory_Admin_Menu\WPFactory_Admin_Menu ' ) ) {
218
+ return ;
219
+ }
220
+
221
+ $ wpfactory_admin_menu = \WPFactory \WPFactory_Admin_Menu \WPFactory_Admin_Menu::get_instance ();
222
+
223
+ if ( ! method_exists ( $ wpfactory_admin_menu , 'move_wc_settings_tab_to_wpfactory_menu ' ) ) {
224
+ return ;
225
+ }
226
+
227
+ $ wpfactory_admin_menu ->move_wc_settings_tab_to_wpfactory_menu ( array (
228
+ 'wc_settings_tab_id ' => 'alg_wc_product_notes ' ,
229
+ 'menu_title ' => __ ( 'Product Notes ' , 'product-notes-for-woocommerce ' ),
230
+ 'page_title ' => __ ( 'Product Notes ' , 'product-notes-for-woocommerce ' ),
231
+ ) );
232
+
233
+ }
234
+
166
235
/**
167
236
* add_woocommerce_settings_tab.
168
237
*
169
- * @version 2.4 .0
238
+ * @version 3.0 .0
170
239
* @since 1.0.0
171
240
*/
172
241
function add_woocommerce_settings_tab ( $ settings ) {
173
- $ settings [] = require_once ( 'settings/class-alg-wc-pn-settings.php ' ) ;
242
+ $ settings [] = require_once plugin_dir_path ( __FILE__ ) . 'settings/class-alg-wc-pn-settings.php ' ;
174
243
return $ settings ;
175
244
}
176
245
@@ -215,7 +284,10 @@ function plugin_path() {
215
284
* @since 2.0.0
216
285
*/
217
286
function get_id ( $ private_or_public ) {
218
- return ( 'private ' === $ private_or_public ? 'alg_wc_internal_product_note ' : 'alg_wc_public_product_note ' );
287
+ return ( 'private ' === $ private_or_public ?
288
+ 'alg_wc_internal_product_note ' :
289
+ 'alg_wc_public_product_note '
290
+ );
219
291
}
220
292
221
293
}
0 commit comments