PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / trunk
WCPOS – Point of Sale (POS) plugin for WooCommerce vtrunk
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 1.9.13 1.9.12 1.9.11 1.9.10 1.9.9 All 158 releases
woocommerce-pos / includes / AJAX.php

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

100 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 * 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 * Constructor.
38 */
39 public function __construct() {
40 if ( ! isset( $_REQUEST['action'] ) ) {
41 return;
42 }
43
44 // ignore for WP Admin heartbeat requests.
45 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Only reading action name, no form processing.
46 if ( isset( $_POST['action'] ) && 'heartbeat' === $_POST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
47 return;
48 }
49
50 foreach ( $this->single_product_actions as $ajax_event ) {
51 add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_single_product_class' ), 9 );
52 }
53 foreach ( $this->list_products_actions as $ajax_event ) {
54 add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_list_products_class' ), 9 );
55 }
56
57 // we need to hook into these actions to save our custom fields via AJAX.
58 add_action(
59 'woocommerce_product_quick_edit_save',
60 array(
61 '\WCPOS\WooCommercePOS\Admin\Products\List_Products',
62 'quick_edit_save',
63 )
64 );
65
66 /**
67 * Fix for AJAX quick edit.
68 *
69 * @TODO - I need to fix this AJAX mess.
70 * When a quick edit is saved, WooCommerce returns a re-rendered row to replace the existing row.
71 * Because it's via AJAX, our 'manage_product_posts_custom_column' hook won't run, so it won't include our updated value.
72 *
73 * I have loaded the List_Products class here for the wp_ajax_inline_save hook .
74 */
75 if ( 'inline-save' === $_REQUEST['action'] ) {
76 new List_Products();
77 }
78 }
79
80 /**
81 * The Admin\Products\Single_Product class is not loaded for AJAX requests.
82 * We need to load it manually here.
83 *
84 * @return void
85 */
86 public function load_single_product_class() {
87 $single_product_class = apply_filters( 'woocommerce_pos_single_product_admin_ajax_class', Single_Product::class );
88 new $single_product_class();
89 }
90
91 /**
92 * The Admin\Products\List_Products class is not loaded for AJAX requests.
93 * We need to load it manually here.
94 *
95 * @return void
96 */
97 public function load_list_products_class() {
98 }
99 }
100