PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.9.15
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.9.15
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 / AJAX.php

AJAX.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.15, at includes/AJAX.php

122 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AJAX.
4 *
5 * @package WCPOS\WooCommercePOS
6 */
7
8 namespace WCPOS\WooCommercePOS;
9
10 use WCPOS\WooCommercePOS\Admin\Products\Single_Product;
11 use WCPOS\WooCommercePOS\Admin\Products\List_Products;
12
13 /**
14 * AJAX class.
15 */
16 class AJAX {
17 /**
18 * WooCommerce AJAX actions that we need to hook into on the Product admin pages.
19 *
20 * @var string[]
21 */
22 private $single_product_actions = array(
23 'woocommerce_load_variations',
24 'woocommerce_save_variations',
25 );
26
27 /**
28 * WooCommerce AJAX actions that we need to hook into on the Product admin pages.
29 *
30 * @var string[]
31 */
32 private $list_products_actions = array(
33 'inline_save', // this is a core WordPress action and it won't call our hooks?? I don't know why.
34 );
35
36 /**
37 * WooCommerce AJAX actions that we need to hook into on the Order admin pages.
38 *
39 * @phpstan-ignore-next-line
40 *
41 * @var string[]
42 */
43 private $order_actions = array(
44 'woocommerce_add_order_item',
45 'woocommerce_add_order_fee',
46 'woocommerce_add_order_shipping',
47 'woocommerce_add_order_tax',
48 'woocommerce_add_coupon_discount',
49 'woocommerce_remove_order_coupon',
50 'woocommerce_remove_order_item',
51 'woocommerce_remove_order_tax',
52 'woocommerce_calc_line_taxes',
53 'woocommerce_save_order_items',
54 'woocommerce_load_order_items',
55 'woocommerce_get_order_details',
56 );
57
58 /**
59 * Constructor.
60 */
61 public function __construct() {
62 if ( ! isset( $_REQUEST['action'] ) ) {
63 return;
64 }
65
66 // ignore for WP Admin heartbeat requests.
67 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Only reading action name, no form processing.
68 if ( isset( $_POST['action'] ) && 'heartbeat' === $_POST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
69 return;
70 }
71
72 foreach ( $this->single_product_actions as $ajax_event ) {
73 add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_single_product_class' ), 9 );
74 }
75 foreach ( $this->list_products_actions as $ajax_event ) {
76 add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_list_products_class' ), 9 );
77 }
78
79 // we need to hook into these actions to save our custom fields via AJAX.
80 add_action(
81 'woocommerce_product_quick_edit_save',
82 array(
83 '\WCPOS\WooCommercePOS\Admin\Products\List_Products',
84 'quick_edit_save',
85 )
86 );
87
88 /**
89 * Fix for AJAX quick edit.
90 *
91 * @TODO - I need to fix this AJAX mess.
92 * When a quick edit is saved, WooCommerce returns a re-rendered row to replace the existing row.
93 * Because it's via AJAX, our 'manage_product_posts_custom_column' hook won't run, so it won't include our updated value.
94 *
95 * I have loaded the List_Products class here for the wp_ajax_inline_save hook .
96 */
97 if ( 'inline-save' === $_REQUEST['action'] ) {
98 new List_Products();
99 }
100 }
101
102 /**
103 * The Admin\Products\Single_Product class is not loaded for AJAX requests.
104 * We need to load it manually here.
105 *
106 * @return void
107 */
108 public function load_single_product_class() {
109 $single_product_class = apply_filters( 'woocommerce_pos_single_product_admin_ajax_class', Single_Product::class );
110 new $single_product_class();
111 }
112
113 /**
114 * The Admin\Products\List_Products class is not loaded for AJAX requests.
115 * We need to load it manually here.
116 *
117 * @return void
118 */
119 public function load_list_products_class() {
120 }
121 }
122