PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.17
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.17
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / updates / update-1.6.1.php

update-1.6.1.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.17, at includes/updates/update-1.6.1.php

102 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Update to 1.6.1
4 * Changing POS Only products to use settings rather than postmeta.
5 *
6 * @package WCPOS\WooCommercePOS
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Change POS Only products to use settings rather than postmeta.
15 * NOTE: we will leave the postmeta in place for now, but this will be removed in a future update.
16 */
17 function woocommerce_pos_update_pos_visibility_settings_to_1_6_1() {
18 global $wpdb;
19
20 $option_key = 'woocommerce_pos_settings_visibility';
21
22 // Check if the option already exists.
23 $visibility_settings = get_option( $option_key );
24
25 if ( false !== $visibility_settings ) {
26 // The option already exists, no need to update.
27 return;
28 }
29
30 // Initialize arrays for product and variation IDs.
31 $pos_only_product_ids = array();
32 $online_only_product_ids = array();
33 $pos_only_variation_ids = array();
34 $online_only_variation_ids = array();
35
36 // Query to get all products with _pos_visibility = 'pos_only'.
37 $pos_only_product_ids = $wpdb->get_col(
38 "
39 SELECT post_id
40 FROM {$wpdb->postmeta}
41 WHERE meta_key = '_pos_visibility' AND meta_value = 'pos_only' AND post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product')
42 "
43 );
44
45 // Query to get all products with _pos_visibility = 'online_only'.
46 $online_only_product_ids = $wpdb->get_col(
47 "
48 SELECT post_id
49 FROM {$wpdb->postmeta}
50 WHERE meta_key = '_pos_visibility' AND meta_value = 'online_only' AND post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product')
51 "
52 );
53
54 // Query to get all variations with _pos_visibility = 'pos_only'.
55 $pos_only_variation_ids = $wpdb->get_col(
56 "
57 SELECT post_id
58 FROM {$wpdb->postmeta}
59 WHERE meta_key = '_pos_visibility' AND meta_value = 'pos_only' AND post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product_variation')
60 "
61 );
62
63 // Query to get all variations with _pos_visibility = 'online_only'.
64 $online_only_variation_ids = $wpdb->get_col(
65 "
66 SELECT post_id
67 FROM {$wpdb->postmeta}
68 WHERE meta_key = '_pos_visibility' AND meta_value = 'online_only' AND post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product_variation')
69 "
70 );
71
72 // Prepare the new visibility settings.
73 $new_visibility_settings = array(
74 'products' => array(
75 'default' => array(
76 'pos_only' => array(
77 'ids' => array_map( 'intval', $pos_only_product_ids ),
78 ),
79 'online_only' => array(
80 'ids' => array_map( 'intval', $online_only_product_ids ),
81 ),
82 ),
83 ),
84 'variations' => array(
85 'default' => array(
86 'pos_only' => array(
87 'ids' => array_map( 'intval', $pos_only_variation_ids ),
88 ),
89 'online_only' => array(
90 'ids' => array_map( 'intval', $online_only_variation_ids ),
91 ),
92 ),
93 ),
94 );
95
96 // Update the option in the database.
97 update_option( $option_key, $new_visibility_settings, false );
98 }
99
100 // Run the update script.
101 woocommerce_pos_update_pos_visibility_settings_to_1_6_1();
102