PluginProbe
MailerLite – WooCommerce integration / 2.0
MailerLite – WooCommerce integration v2.0
3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 All 147 releases
woo-mailerlite / includes / admin / functions.php

functions.php in MailerLite – WooCommerce integration 2.0, at includes/admin/functions.php

112 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get settings page url
4 *
5 * @return string
6 */
7 function woo_ml_get_settings_page_url() {
8 return admin_url( 'admin.php?page=wc-settings&tab=integration&section=mailerlite' );
9 }
10
11 /**
12 * Get complete integration setup url
13 *
14 * @return string
15 */
16 function woo_ml_get_complete_integration_setup_url() {
17 return add_query_arg( 'woo_ml_action', 'setup_integration', woo_ml_get_settings_page_url() );
18 }
19
20 /**
21 * Update ignore product list
22 *
23 * @return boolean
24 */
25 function woo_ml_update_ignore_product_list( $products ) {
26
27 $settings = mailerlite_wp_get_shop_settings_from_db();
28
29 if ($settings !== false) {
30
31 $resubscribe = (woo_ml_get_option('resubscribe', 'no') == 'yes') ? 1 : 0;
32
33 if (isset($settings->settings->resubscribe)) {
34
35 $resubscribe = $settings->settings->resubscribe;
36 }
37
38 $results = mailerlite_wp_set_consumer_data(
39 woo_ml_get_option('consumer_key'),
40 woo_ml_get_option('consumer_secret'),
41 woo_ml_get_option('group'),
42 $resubscribe,
43 $products );
44
45 return $results;
46 }
47
48 return false;
49 }
50
51 /**
52 * Update ignore product list in ml_data table
53 *
54 * @return mixed
55 */
56 function woo_ml_update_data( $products ) {
57
58 global $wpdb;
59
60 $table = $wpdb->prefix . 'ml_data';
61
62 $tableCreated = get_option('ml_data_table');
63
64 if ($tableCreated != 1) {
65
66 woo_create_mailer_data_table();
67 }
68
69 $updateQuery = $wpdb->prepare("
70 INSERT INTO $table (data_name, data_value) VALUES ('products', %s) ON DUPLICATE KEY UPDATE data_value = %s
71 ", json_encode( $products ), json_encode( $products ) );
72
73 return $wpdb->query($updateQuery);
74 }
75
76 /**
77 * Save ignored products to WooCommerce Integration and ml_data table
78 *
79 */
80 function woo_ml_save_local_ignore_products( $products ) {
81
82 $ignore_map = woo_ml_remap_list( $products );
83
84 if ( woo_ml_update_ignore_product_list( $ignore_map ) === true ) {
85
86 // save updated ignore product list to WooCommerce Integration
87 $settings = get_option('woocommerce_mailerlite_settings');
88
89 if ( ! isset( $settings['ignore_product_list'] ) ) {
90 $settings['ignore_product_list'] = array();
91 }
92
93 $settings['ignore_product_list'] = $ignore_map;
94
95 update_option('woocommerce_mailerlite_settings', $settings);
96
97 //save product ignore list to ml_data
98 woo_ml_update_data( $products );
99 }
100 }
101
102 /**
103 * Remove product from product ignore list for ml_data
104 *
105 * @return array
106 */
107 function woo_ml_remove_product_from_list( $products, $remove_list ) {
108
109 return array_filter( $products, function( $k ) use ( $remove_list ) {
110 return ! in_array( $k, $remove_list );
111 }, ARRAY_FILTER_USE_KEY);
112 }