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