-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwoocommerce-refund-and-exchange-lite.php
executable file
·365 lines (340 loc) · 16.1 KB
/
woocommerce-refund-and-exchange-lite.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://wpswings.com/
* @since 1.0.0
* @package woo-refund-and-exchange-lite
*
* @wordpress-plugin
* Plugin Name: Return Refund and Exchange for WooCommerce
* Plugin URI: https://wordpress.org/plugins/woo-refund-and-exchange-lite/
* Description: <code><strong>Return Refund and Exchange for WooCommerce</strong></code> allows users to submit product refund. The plugin provides a dedicated mailing system that would help to communicate better between store owner and customers.This is lite version of WooCommerce Refund And Exchange. <a target="_blank" href="https://wpswings.com/woocommerce-plugins/?utm_source=wpswings-rma-shop&utm_medium=rma-org-backend&utm_campaign=shop-page">Elevate your e-commerce store by exploring more on WP Swings</a>
* Version: 4.4.4
* Author: WP Swings
* Author URI: https://wpswings.com/?utm_source=wpswings-rma-official&utm_medium=rma-org-page&utm_campaign=official
* Text Domain: woo-refund-and-exchange-lite
* Domain Path: /languages
* Requires Plugins: woocommerce
*
* Requires at least: 5.5.0
* Tested up to: 6.7.1
* WC requires at least: 6.5
* WC tested up to: 9.5.1
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
die;
}
use Automattic\WooCommerce\Utilities\OrderUtil;
$activated = false;
$active_plugins = get_option( 'active_plugins', array() );
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
$active_network_wide = get_site_option( 'active_sitewide_plugins', array() );
if ( ! empty( $active_network_wide ) ) {
foreach ( $active_network_wide as $key => $value ) {
$active_plugins[] = $key;
}
}
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
if ( file_exists( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php' ) && in_array( 'woocommerce/woocommerce.php', $active_plugins, true ) ) {
$activated = true;
}
} elseif ( file_exists( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php' ) && in_array( 'woocommerce/woocommerce.php', $active_plugins, true ) ) {
$activated = true;
}
if ( $activated ) {
/**
* Define plugin constants.
*
* @since 1.0.0
*/
function define_woo_refund_and_exchange_lite_constants() {
woo_refund_and_exchange_lite_constants( 'WOO_REFUND_AND_EXCHANGE_LITE_VERSION', '4.4.4' );
woo_refund_and_exchange_lite_constants( 'WOO_REFUND_AND_EXCHANGE_LITE_DIR_PATH', plugin_dir_path( __FILE__ ) );
woo_refund_and_exchange_lite_constants( 'WOO_REFUND_AND_EXCHANGE_LITE_DIR_URL', plugin_dir_url( __FILE__ ) );
woo_refund_and_exchange_lite_constants( 'WOO_REFUND_AND_EXCHANGE_LITE_SERVER_URL', 'https://wpswings.com' );
woo_refund_and_exchange_lite_constants( 'WOO_REFUND_AND_EXCHANGE_LITE_ITEM_REFERENCE', 'Woo Refund And Exchange Lite' );
}
/**
* Define wps-site update feature.
*
* @since 1.0.0
*/
function auto_update_woo_refund_and_exchange_lite() {
if ( ! defined( 'WOO_REFUND_AND_EXCHANGE_LITE_SPECIAL_SECRET_KEY' ) ) {
define( 'WOO_REFUND_AND_EXCHANGE_LITE_SPECIAL_SECRET_KEY', '59f32ad2f20102.74284991' );
}
if ( ! defined( 'WOO_REFUND_AND_EXCHANGE_LITE_LICENSE_SERVER_URL' ) ) {
define( 'WOO_REFUND_AND_EXCHANGE_LITE_LICENSE_SERVER_URL', 'https://wpswings.com' );
}
if ( ! defined( 'WOO_REFUND_AND_EXCHANGE_LITE_ITEM_REFERENCE' ) ) {
define( 'WOO_REFUND_AND_EXCHANGE_LITE_ITEM_REFERENCE', 'Woo Refund And Exchange Lite' );
}
woo_refund_and_exchange_lite_constants( 'WOO_REFUND_AND_EXCHANGE_LITE_BASE_FILE', __FILE__ );
}
/**
* Callable function for defining plugin constants.
*
* @param String $key Key for contant.
* @param String $value value for contant.
* @since 1.0.0
*/
function woo_refund_and_exchange_lite_constants( $key, $value ) {
if ( ! defined( $key ) ) {
define( $key, $value );
}
}
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-woo-refund-and-exchange-lite-activator.php
*
* @param string $network_wide .
*/
function activate_woo_refund_and_exchange_lite( $network_wide ) {
include_once plugin_dir_path( __FILE__ ) . 'includes/class-woo-refund-and-exchange-lite-activator.php';
Woo_Refund_And_Exchange_Lite_Activator::woo_refund_and_exchange_lite_activate( $network_wide );
$wps_rma_active_plugin = get_option( 'wps_all_plugins_active', false );
if ( is_array( $wps_rma_active_plugin ) && ! empty( $wps_rma_active_plugin ) ) {
$wps_rma_active_plugin['woo-refund-and-exchange-lite'] = array(
'plugin_name' => esc_html__( 'Woo Refund And Exchange Lite', 'woo-refund-and-exchange-lite' ),
'active' => '1',
);
} else {
$wps_rma_active_plugin = array();
$wps_rma_active_plugin['woo-refund-and-exchange-lite'] = array(
'plugin_name' => esc_html__( 'Woo Refund And Exchange Lite', 'woo-refund-and-exchange-lite' ),
'active' => '1',
);
}
update_option( 'wps_all_plugins_active', $wps_rma_active_plugin );
}
add_action(
'before_woocommerce_init',
function () {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
);
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-woo-refund-and-exchange-lite-deactivator.php
*
* @param string $network_wide .
*/
function deactivate_woo_refund_and_exchange_lite( $network_wide ) {
include_once plugin_dir_path( __FILE__ ) . 'includes/class-woo-refund-and-exchange-lite-deactivator.php';
Woo_Refund_And_Exchange_Lite_Deactivator::woo_refund_and_exchange_lite_deactivate( $network_wide );
$wps_rma_deactive_plugin = get_option( 'wps_all_plugins_active', false );
if ( is_array( $wps_rma_deactive_plugin ) && ! empty( $wps_rma_deactive_plugin ) ) {
foreach ( $wps_rma_deactive_plugin as $wps_rma_deactive_key => $wps_rma_deactive ) {
if ( 'woo-refund-and-exchange-lite' === $wps_rma_deactive_key ) {
$wps_rma_deactive_plugin[ $wps_rma_deactive_key ]['active'] = '0';
}
}
}
update_option( 'wps_all_plugins_active', $wps_rma_deactive_plugin );
}
register_activation_hook( __FILE__, 'activate_woo_refund_and_exchange_lite' );
register_deactivation_hook( __FILE__, 'deactivate_woo_refund_and_exchange_lite' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-woo-refund-and-exchange-lite.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
function run_woo_refund_and_exchange_lite() {
define_woo_refund_and_exchange_lite_constants();
auto_update_woo_refund_and_exchange_lite();
$wps_rma_plugin_standard = new Woo_Refund_And_Exchange_Lite();
$wps_rma_plugin_standard->wrael_run();
$GLOBALS['wrael_wps_rma_obj'] = $wps_rma_plugin_standard;
if ( function_exists( 'vc_lean_map' ) ) {
include_once WOO_REFUND_AND_EXCHANGE_LITE_DIR_PATH . 'wp-bakery-widgets/class-wps-rma-vc-widgets.php';
}
include_once WOO_REFUND_AND_EXCHANGE_LITE_DIR_PATH . 'includes/woo-refund-and-exchange-lite-common-functions.php';
}
run_woo_refund_and_exchange_lite();
/**
* Adding custom setting links at the plugin activation list.
*
* @param array $links_array array containing the links to plugin.
* @param string $plugin_file_name plugin file name.
* @return array
*/
function woo_refund_and_exchange_lite_custom_settings_at_plugin_tab( $links_array, $plugin_file_name ) {
if ( strpos( $plugin_file_name, basename( __FILE__ ) ) ) {
$links_array[] = '<a class="wps_wrma_link" target="_blank" href="https://demo.wpswings.com/rma-return-refund-exchange-for-woocommerce-pro/?utm_source=wpswings-rma-demo&utm_medium=rma-org-backend&utm_campaign=demo"><img src="' . esc_url( WOO_REFUND_AND_EXCHANGE_LITE_DIR_URL ) . 'admin/image/Demo.svg" class="wps-info-img" alt="Demo image">' . esc_html__( 'Demo', 'woo-refund-and-exchange-lite' ) . '</a>';
$links_array[] = '<a class="wps_wrma_link" href="https://docs.wpswings.com/woocommerce-refund-and-exchange-lite/?utm_source=wpswings-rma-doc&utm_medium=rma-org-backend&utm_campaign=rma-doc/" target="_blank"><img src="' . esc_html( WOO_REFUND_AND_EXCHANGE_LITE_DIR_URL ) . 'admin/image/Documentation.svg" class="wps-info-img" alt="documentation image">' . esc_html__( 'Documentation', 'woo-refund-and-exchange-lite' ) . '</a>';
$links_array[] = '<a style ="white-space:nowrap;" href="https://youtu.be/GQhXfBtzLE0" target="_blank"><img src="' . esc_html( WOO_REFUND_AND_EXCHANGE_LITE_DIR_URL ) . 'admin/image/YouTube_32px.svg" class="wps-info-img" alt="video image">' . esc_html__( 'Video', 'woo-refund-and-exchange-lite' ) . '</a>';
$links_array[] = '<a class="wps_wrma_link" href="https://wpswings.com/submit-query/?utm_source=wpswings-rma-support&utm_medium=rma-org-backend&utm_campaign=support/" target="_blank"><img src="' . esc_html( WOO_REFUND_AND_EXCHANGE_LITE_DIR_URL ) . 'admin/image/Support.svg" class="wps-info-img" alt="support image">' . esc_html__( 'Support', 'woo-refund-and-exchange-lite' ) . '</a>';
$links_array[] = '<a class="wps_wrma_link" href="https://wpswings.com/woocommerce-services/?utm_source=wpswings-rma-services&utm_medium=rma-org-backend&utm_campaign=woocommerce-services" target="_blank"><img src="' . esc_html( WOO_REFUND_AND_EXCHANGE_LITE_DIR_URL ) . 'admin/image/Icon_services.svg" class="wps-info-img" alt="services image">' . esc_html__( 'Services', 'woo-refund-and-exchange-lite' ) . '</a>';
}
return $links_array;
}
add_filter( 'plugin_row_meta', 'woo_refund_and_exchange_lite_custom_settings_at_plugin_tab', 10, 2 );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wps_rma_lite_settings_link' );
/**
* Settings tab of the plugin.
*
* @name wps_rma_lite_settings_link
* @param array $links array of the links.
* @since 1.0.0
*/
function wps_rma_lite_settings_link( $links ) {
if ( ! is_plugin_active( 'woocommerce-rma-for-return-refund-and-exchange/mwb-woocommerce-rma.php' ) ) {
$links['goPro'] = '<a style="background: #05d5d8;color: white;font-weight: 700;padding: 2px 5px;border: 1px solid #05d5d8;border-radius: 5px;" target="_blank" href="https://wpswings.com/product/rma-return-refund-exchange-for-woocommerce-pro?utm_source=wpswings-rma-pro&utm_medium=rma-org-backend&utm_campaign=go-pro">' . esc_html__( 'GO PRO', 'woo-refund-and-exchange-lite' ) . '</a>';
}
$my_link['setting'] = '<a href="' . admin_url( 'admin.php?page=woo_refund_and_exchange_lite_menu' ) . '">' . esc_html__( 'Settings', 'woo-refund-and-exchange-lite' ) . '</a>';
return array_merge( $my_link, $links );
}
/**
*
* Get the data from the order table if hpos enabled otherwise default working.
*
* @param int $id .
* @param string $key .
* @param int $v .
*/
function wps_rma_get_meta_data( $id, $key, $v ) {
if ( 'shop_order' === OrderUtil::get_order_type( $id ) && OrderUtil::custom_orders_table_usage_is_enabled() ) {
// HPOS usage is enabled.
$order = wc_get_order( $id );
if ( '_customer_user' === $key ) {
return $order->get_customer_id();
}
$meta_val = $order->get_meta( $key );
return $meta_val;
} else {
// Traditional CPT-based orders are in use.
$meta_val = get_post_meta( $id, $key, $v );
return $meta_val;
}
}
/**
*
* Update the data into the order table if hpos enabled otherwise default working.
*
* @param int $id .
* @param string $key .
* @param init|array|object $value .
*/
function wps_rma_update_meta_data( $id, $key, $value ) {
if ( 'shop_order' === OrderUtil::get_order_type( $id ) && OrderUtil::custom_orders_table_usage_is_enabled() ) {
// HPOS usage is enabled.
$order = wc_get_order( $id );
$order->update_meta_data( $key, $value );
$order->save();
} else {
// Traditional CPT-based orders are in use.
update_post_meta( $id, $key, $value );
}
}
add_action( 'admin_notices', 'wps_banner_notification_plugin_html' );
if ( ! function_exists( 'wps_banner_notification_plugin_html' ) ) {
/**
* Common Function To show banner image.
*
* @return void
*/
function wps_banner_notification_plugin_html() {
$screen = get_current_screen();
if ( isset( $screen->id ) ) {
$pagescreen = $screen->id;
}
if ( ( isset( $pagescreen ) && 'plugins' === $pagescreen ) || ( 'wp-swings_page_home' == $pagescreen ) ) {
$banner_id = get_option( 'wps_wgm_notify_new_banner_id', false );
if ( isset( $banner_id ) && '' !== $banner_id ) {
$hidden_banner_id = get_option( 'wps_wgm_notify_hide_baneer_notification', false );
$banner_image = get_option( 'wps_wgm_notify_new_banner_image', '' );
$banner_url = get_option( 'wps_wgm_notify_new_banner_url', '' );
if ( isset( $hidden_banner_id ) && $hidden_banner_id < $banner_id ) {
if ( '' !== $banner_image && '' !== $banner_url ) {
?>
<div class="wps-offer-notice notice notice-warning is-dismissible">
<div class="notice-container">
<a href="<?php echo esc_url( $banner_url ); ?>" target="_blank"><img src="<?php echo esc_url( $banner_image ); ?>" alt="Subscription cards"/></a>
</div>
<button type="button" class="notice-dismiss dismiss_banner" id="dismiss-banner"><span class="screen-reader-text">Dismiss this notice.</span></button>
</div>
<?php
}
}
}
}
}
}
add_action( 'admin_notices', 'wps_rma_banner_notification_html' );
/**
* Function to show banner image based on subscription.
*
* @return void
*/
function wps_rma_banner_notification_html() {
$screen = get_current_screen();
if ( isset( $screen->id ) && 'wp-swings_page_woo_refund_and_exchange_lite_menu' === $screen->id ) {
$banner_id = get_option( 'wps_wgm_notify_new_banner_id', false );
if ( isset( $banner_id ) && '' !== $banner_id ) {
$hidden_banner_id = get_option( 'wps_wgm_notify_hide_baneer_notification', false );
$banner_image = get_option( 'wps_wgm_notify_new_banner_image', '' );
$banner_url = get_option( 'wps_wgm_notify_new_banner_url', '' );
if ( isset( $hidden_banner_id ) && $hidden_banner_id < $banner_id ) {
if ( '' !== $banner_image && '' !== $banner_url ) {
?>
<div class="wps-offer-notice notice notice-warning is-dismissible">
<div class="notice-container">
<a href="<?php echo esc_url( $banner_url ); ?>"target="_blank"><img src="<?php echo esc_url( $banner_image ); ?>" alt="RMA cards"/></a>
</div>
<button type="button" class="notice-dismiss dismiss_banner" id="dismiss-banner"><span class="screen-reader-text">Dismiss this notice.</span></button>
</div>
<?php
}
}
}
}
}
} else {
/**
* Show warning message if woocommerce is not install
*/
function wps_rma_plugin_error_notice_lite() {
?>
<div class="error notice is-dismissible">
<p><?php esc_html_e( 'Woocommerce is not activated, Please activate Woocommerce first to install WooCommerce Refund and Exchange Lite.', 'woo-refund-and-exchange-lite' ); ?></p>
</div>
<style>
#message{display:none;}
</style>
<?php
}
add_action( 'admin_init', 'wps_rma_plugin_deactivate_lite' );
/**
* Call Admin notices
*
* @name ced_rnx_plugin_deactivate_lite()
* @author Wp Swings<[email protected]>
* @link http://www.wpswings.com/
*/
function wps_rma_plugin_deactivate_lite() {
deactivate_plugins( plugin_basename( __FILE__ ) );
add_action( 'network_admin_notices', 'wps_rma_plugin_error_notice_lite' );
add_action( 'admin_notices', 'wps_rma_plugin_error_notice_lite' );
}
}