--- a/woo-order-splitter/inc/functions-troubleshooting.php
+++ b/woo-order-splitter/inc/functions-troubleshooting.php
@@ -1,126 +1,140 @@
<?php
function wos_troubleshooting() {
- extract($_POST);
- $ret = array();
-
- $order = wc_get_order($order_id);
- if (!$order) {
- wp_send_json_error('Order not found');
- }
-
- global $wc_os_settings, $wos_actions_arr;
-
- $hex = '#' . wc_os_random_color();
- list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
- $ret['color'] = ['r' => $r, 'g' => $g, 'b' => $b];
- $ret['color_hex'] = $hex;
- $ret['order_id'] = $order_id;
- $ret['split_method'] = $wc_os_settings['wc_os_ie'];
-
- $meta = wc_os_get_order_meta($order_id);
- $wc_os_meta_keys = get_option('wc_os_meta_keys', array());
- $items = $order->get_items();
- $shipping_items = $order->get_items('shipping');
- $split_method_key = $ret['split_method'];
- $split_method_label = $wos_actions_arr[ $split_method_key ]['action'] ?? ucfirst(str_replace('_', ' ', $split_method_key));
+ $ret = array('html'=>'');
-
-
- $debug_output = [];
-
- $debug_output[] = '<div class="wos-troubleshoot-method"><h3>Split Method: ' . esc_html($split_method_key) . ' — ' . esc_html($split_method_label) . '</h3></div>';
- $debug_output[] = '<div class="wos-meta-keys"><h4>Configured Meta Keys for Grouping:</h4><pre>' . print_r($wc_os_meta_keys, true) . '</pre></div>';
-
- $wc_os_order_splitter = new wc_os_order_splitter;
-
- $debug_output[] = '<div class="wos-split-order-logic"><h4>Expected Output:</h4><pre>'.print_r($wc_os_order_splitter->split_order_logic($order_id, false, true), true).'</pre></div>';
-
- // Generic items listing
- foreach ($items as $item_id => $item) {
- $product_id = $item->get_product_id();
- $product = wc_get_product($product_id);
- $vendor_id = get_post_field('post_author', $product_id);
- $vendor_name = get_the_author_meta('display_name', $vendor_id);
-
- $debug_output[] = '<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px;">';
-
- $debug_output[] = '<div style="margin-bottom:5px;"><strong>Item ID:</strong> ' . $item_id . '</div>';
+ if ( ! isset($_POST['wc_os_nonce']) || ! wp_verify_nonce($_POST['wc_os_nonce'], 'wc_os_nonce_action') ) {
- $debug_output[] = '<div style="margin-bottom:5px;"><strong>Product ID:</strong> ' . $product_id . ' - ' . esc_html($product->get_name()) . '</div>';
+ wp_send_json_error(__('Sorry, your nonce did not verify.', 'woo-order-splitter'));
- $debug_output[] = '<div style="margin-bottom:5px;"><strong>Vendor ID:</strong> ' . $vendor_id . ' (' . esc_html($vendor_name) . ')</div>';
+ } elseif ( ! current_user_can('manage_woocommerce') && ! current_user_can('edit_shop_orders') ) {
- $debug_output[] = '<div style="margin-bottom:5px;"><strong>Item Meta:</strong><pre style="margin:0;">' . print_r($item->get_meta_data(), true) . '</pre></div>';
+ wp_send_json_error(__('You do not have permission to access this resource.', 'woo-order-splitter'));
+ } else {
+
+ extract($_POST);
+ $order_id = isset($_POST['order_id']) ? intval($_POST['order_id']) : 0;
+
+
+ $order = wc_get_order($order_id);
+ if (!$order) {
+ wp_send_json_error('Order not found');
+ }
+
+ global $wc_os_settings, $wos_actions_arr;
+
+ $hex = '#' . wc_os_random_color();
+ list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
+ $ret['color'] = ['r' => $r, 'g' => $g, 'b' => $b];
+ $ret['color_hex'] = $hex;
+ $ret['order_id'] = $order_id;
+ $ret['split_method'] = $wc_os_settings['wc_os_ie'];
+
+ $meta = wc_os_get_order_meta($order_id);
+ $wc_os_meta_keys = get_option('wc_os_meta_keys', array());
+ $items = $order->get_items();
+ $shipping_items = $order->get_items('shipping');
- $debug_output[] = '</div>';
+ $split_method_key = $ret['split_method'];
+ $split_method_label = $wos_actions_arr[ $split_method_key ]['action'] ?? ucfirst(str_replace('_', ' ', $split_method_key));
-
-
- // Add conditional rendering for known split methods
- switch ($ret['split_method']) {
- case 'group_by_order_item_meta':
- case 'group_by_gf_meta':
- $meta_keys = get_option('wc_os_gf_meta_keys', []);
- $debug_output[] = '<span style="color:red">[!] Missing Group-by Meta Keys?</span>';
- $debug_output[] = '<pre>' . print_r($meta_keys, true) . '</pre>';
- break;
- case 'group_by_attributes_value':
- $debug_output[] = '<span style="color:red">[!] Attributes Value Grouping Check Needed</span>';
- break;
- case 'group_by_woo_vendors':
- $vendor_term = wp_get_post_terms($product_id, 'wcpv_product_vendors');
- $group_letter = '';
- if (!empty($vendor_term)) {
- $term_id = $vendor_term[0]->term_id;
- foreach ((array) $wc_os_settings['wc_os_woo_vendors'] as $letter => $vendor_ids) {
- if (in_array($term_id, (array) $vendor_ids)) {
- $group_letter = strtoupper($letter);
- break;
+
+ $debug_output = [];
+
+ $debug_output[] = '<div class="wos-troubleshoot-method"><h3>Split Method: ' . esc_html($split_method_key) . ' — ' . esc_html($split_method_label) . '</h3></div>';
+ $debug_output[] = '<div class="wos-meta-keys"><h4>Configured Meta Keys for Grouping:</h4><pre>' . print_r($wc_os_meta_keys, true) . '</pre></div>';
+
+ $wc_os_order_splitter = new wc_os_order_splitter;
+
+ $debug_output[] = '<div class="wos-split-order-logic"><h4>Expected Output:</h4><pre>'.print_r($wc_os_order_splitter->split_order_logic($order_id, false, true), true).'</pre></div>';
+
+ // Generic items listing
+ foreach ($items as $item_id => $item) {
+ $product_id = $item->get_product_id();
+ $product = wc_get_product($product_id);
+ $vendor_id = get_post_field('post_author', $product_id);
+ $vendor_name = get_the_author_meta('display_name', $vendor_id);
+
+ $debug_output[] = '<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px;">';
+
+ $debug_output[] = '<div style="margin-bottom:5px;"><strong>Item ID:</strong> ' . $item_id . '</div>';
+
+ $debug_output[] = '<div style="margin-bottom:5px;"><strong>Product ID:</strong> ' . $product_id . ' - ' . esc_html($product->get_name()) . '</div>';
+
+ $debug_output[] = '<div style="margin-bottom:5px;"><strong>Vendor ID:</strong> ' . $vendor_id . ' (' . esc_html($vendor_name) . ')</div>';
+
+ $debug_output[] = '<div style="margin-bottom:5px;"><strong>Item Meta:</strong><pre style="margin:0;">' . print_r($item->get_meta_data(), true) . '</pre></div>';
+
+
+ $debug_output[] = '</div>';
+
+
+
+
+ // Add conditional rendering for known split methods
+ switch ($ret['split_method']) {
+ case 'group_by_order_item_meta':
+ case 'group_by_gf_meta':
+ $meta_keys = get_option('wc_os_gf_meta_keys', []);
+ $debug_output[] = '<span style="color:red">[!] Missing Group-by Meta Keys?</span>';
+ $debug_output[] = '<pre>' . print_r($meta_keys, true) . '</pre>';
+ break;
+ case 'group_by_attributes_value':
+ $debug_output[] = '<span style="color:red">[!] Attributes Value Grouping Check Needed</span>';
+ break;
+ case 'group_by_woo_vendors':
+ $vendor_term = wp_get_post_terms($product_id, 'wcpv_product_vendors');
+ $group_letter = '';
+ if (!empty($vendor_term)) {
+ $term_id = $vendor_term[0]->term_id;
+ foreach ((array) $wc_os_settings['wc_os_woo_vendors'] as $letter => $vendor_ids) {
+ if (in_array($term_id, (array) $vendor_ids)) {
+ $group_letter = strtoupper($letter);
+ break;
+ }
}
}
- }
- $debug_output[] = '<div class="wos-vendor-group"><strong>Vendor Group:</strong> <span class="vendor-group-letter">' . esc_html($group_letter) . '</span></div>';
- $debug_output[] = '<div class="wos-vendor-terms"><strong>Vendor Terms:</strong><pre>' . print_r($vendor_term, true) . '</pre></div>';
- break;
-
- case 'group_by_vendors':
- $vendor_term = wp_get_post_terms($product_id, 'wcpv_product_vendors');
- $debug_output[] = '<strong>Vendor Terms:</strong><pre>' . print_r($vendor_term, true) . '</pre>';
- break;
- case 'quantity_split':
- $debug_output[] = '<span style="color:red">[!] Quantity Ratio or Threshold Info Missing?</span>';
- break;
- case 'group_by_partial_payment':
- $debug_output[] = '<span style="color:red">[!] Booking/Partial Payment Meta Missing?</span>';
- break;
- case 'subscription_split':
- $debug_output[] = '<span style="color:red">[!] Delivery Date Check?</span>';
- break;
- case 'group_by_acf_group_fields':
- $acf_value = get_post_meta($product_id, 'acf_group_field', true);
- $debug_output[] = '<strong>ACF Value:</strong><pre>' . print_r($acf_value, true) . '</pre>';
- break;
- default:
- $debug_output[] = '<span style="color:red">[!] Custom check not defined for method: ' . esc_html($ret['split_method']) . '</span>';
- break;
+ $debug_output[] = '<div class="wos-vendor-group"><strong>Vendor Group:</strong> <span class="vendor-group-letter">' . esc_html($group_letter) . '</span></div>';
+ $debug_output[] = '<div class="wos-vendor-terms"><strong>Vendor Terms:</strong><pre>' . print_r($vendor_term, true) . '</pre></div>';
+ break;
+
+ case 'group_by_vendors':
+ $vendor_term = wp_get_post_terms($product_id, 'wcpv_product_vendors');
+ $debug_output[] = '<strong>Vendor Terms:</strong><pre>' . print_r($vendor_term, true) . '</pre>';
+ break;
+ case 'quantity_split':
+ $debug_output[] = '<span style="color:red">[!] Quantity Ratio or Threshold Info Missing?</span>';
+ break;
+ case 'group_by_partial_payment':
+ $debug_output[] = '<span style="color:red">[!] Booking/Partial Payment Meta Missing?</span>';
+ break;
+ case 'subscription_split':
+ $debug_output[] = '<span style="color:red">[!] Delivery Date Check?</span>';
+ break;
+ case 'group_by_acf_group_fields':
+ $acf_value = get_post_meta($product_id, 'acf_group_field', true);
+ $debug_output[] = '<strong>ACF Value:</strong><pre>' . print_r($acf_value, true) . '</pre>';
+ break;
+ default:
+ $debug_output[] = '<span style="color:red">[!] Custom check not defined for method: ' . esc_html($ret['split_method']) . '</span>';
+ break;
+ }
}
- }
-
- $debug_output[] = '<h4>Order Meta:</h4>';
- $debug_output[] = '<pre>' . print_r($meta, true) . '</pre>';
-
- $debug_output[] = '<h4>Shipping Items:</h4>';
- $debug_output[] = '<pre>' . print_r($shipping_items, true) . '</pre>';
- $debug_output[] = '<h4>$wc_os_settings:</h4>';
- $debug_output[] = '<pre>' . print_r($wc_os_settings, true) . '</pre>';
-
- $ret['html'] = implode("n", $debug_output);
-
+ $debug_output[] = '<h4>Order Meta:</h4>';
+ $debug_output[] = '<pre>' . print_r($meta, true) . '</pre>';
+
+ $debug_output[] = '<h4>Shipping Items:</h4>';
+ $debug_output[] = '<pre>' . print_r($shipping_items, true) . '</pre>';
+
+ $debug_output[] = '<h4>$wc_os_settings:</h4>';
+ $debug_output[] = '<pre>' . print_r($wc_os_settings, true) . '</pre>';
+
+ $ret['html'] = implode("n", $debug_output);
+ }
wp_send_json($ret);
}
--- a/woo-order-splitter/index.php
+++ b/woo-order-splitter/index.php
@@ -3,7 +3,7 @@
Plugin Name: Order Splitter for WooCommerce
Plugin URI: https://wordpress.org/plugins/woo-order-splitter
Description: Split, merge, clone, your crowd/combined/bulk orders using intelligent rules.
- Version: 5.3.5
+ Version: 5.3.6
Author: Fahad Mahmood
Author URI: http://androidbubble.com/blog/
Text Domain: woo-order-splitter