@@ -9,63 +9,92 @@ class AJAX {
99 *
1010 * @var string[]
1111 */
12- private $ product_actions = array (
13- 'load_variations ' ,
14- 'save_variations ' ,
12+ private $ single_product_actions = array (
13+ 'woocommerce_load_variations ' ,
14+ 'woocommerce_save_variations ' ,
1515 );
1616
17+ /**
18+ * WooCommerce AJAX actions that we need to hook into on the Product admin pages.
19+ *
20+ * @var string[]
21+ */
22+ private $ list_products_actions = array (
23+ // 'inline-save', // this is a core WordPress action and it won't call our hook
24+ );
25+
1726 /**
1827 * WooCommerce AJAX actions that we need to hook into on the Order admin pages.
1928 *
2029 * @var string[]
2130 */
2231 private $ order_actions = array (
23- 'add_order_item ' ,
24- 'add_order_fee ' ,
25- 'add_order_shipping ' ,
26- 'add_order_tax ' ,
27- 'add_coupon_discount ' ,
28- 'remove_order_coupon ' ,
29- 'remove_order_item ' ,
30- 'remove_order_tax ' ,
31- 'calc_line_taxes ' ,
32- 'save_order_items ' ,
33- 'load_order_items ' ,
34- 'get_order_details ' ,
32+ 'woocommerce_add_order_item ' ,
33+ 'woocommerce_add_order_fee ' ,
34+ 'woocommerce_add_order_shipping ' ,
35+ 'woocommerce_add_order_tax ' ,
36+ 'woocommerce_add_coupon_discount ' ,
37+ 'woocommerce_remove_order_coupon ' ,
38+ 'woocommerce_remove_order_item ' ,
39+ 'woocommerce_remove_order_tax ' ,
40+ 'woocommerce_calc_line_taxes ' ,
41+ 'woocommerce_save_order_items ' ,
42+ 'woocommerce_load_order_items ' ,
43+ 'woocommerce_get_order_details ' ,
3544 );
3645
3746 /**
3847 *
3948 */
4049 public function __construct () {
41- $ this ->woocommerce_ajax_actions ();
42- }
50+ if ( ! isset ( $ _POST ['action ' ] ) ) {
51+ return ;
52+ }
4353
44- /**
45- *
46- */
47- private function woocommerce_ajax_actions () {
48- foreach ( $ this ->product_actions as $ ajax_event ) {
49- add_action ( 'wp_ajax_woocommerce_ ' . $ ajax_event , array ( $ this , 'woocommerce_product_ajax ' ), 9 , 0 );
50- }
51- foreach ( $ this ->order_actions as $ ajax_event ) {
52- add_action ( 'wp_ajax_woocommerce_ ' . $ ajax_event , array ( $ this , 'woocommerce_order_ajax ' ), 9 , 0 );
53- }
54- }
54+ if ( $ _POST ['action ' ] == 'heartbeat ' ) {
55+ return ;
56+ }
57+
58+ foreach ( $ this ->single_product_actions as $ ajax_event ) {
59+ add_action ( 'wp_ajax_ ' . $ ajax_event , array ( $ this , 'load_single_product_class ' ), 9 );
60+ }
61+ foreach ( $ this ->list_products_actions as $ ajax_event ) {
62+ add_action ( 'wp_ajax_ ' . $ ajax_event , array ( $ this , 'load_list_products_class ' ), 9 );
63+ }
64+ foreach ( $ this ->order_actions as $ ajax_event ) {
65+ add_action ( 'wp_ajax_ ' . $ ajax_event , array ( $ this , 'load_orders_class ' ), 9 );
66+ }
67+
68+ // we need to hook into these actions to save our custom fields via AJAX
69+ add_action ( 'woocommerce_product_quick_edit_save ' ,
70+ array (
71+ '\WCPOS\WooCommercePOS\Admin\Products\List_Products ' ,
72+ 'quick_edit_save ' ,
73+ )
74+ );
75+ }
5576
5677 /**
57- * The Admin\Products class is not loaded for AJAX requests.
78+ * The Admin\Products\Single_Product class is not loaded for AJAX requests.
5879 * We need to load it manually here.
5980 */
60- public function woocommerce_product_ajax () {
61- new Admin \Products ();
81+ public function load_single_product_class () {
82+ new Admin \Products \ Single_Product ();
6283 }
6384
85+ /**
86+ * The Admin\Products\List_Products class is not loaded for AJAX requests.
87+ * We need to load it manually here.
88+ */
89+ public function load_list_products_class () {
90+ //
91+ }
92+
6493 /**
6594 * The Admin\Orders class is not loaded for AJAX requests.
6695 * We need to load it manually here.
6796 */
68- public function woocommerce_order_ajax () {
97+ public function load_orders_class () {
6998 new Admin \Orders ();
7099 }
71100
0 commit comments