-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathupdate_invt.php
39 lines (27 loc) · 865 Bytes
/
update_invt.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
// function to update quantities based on array of SKUS and qtys
function update_product_quantity($sku_quantity_array) {
foreach ($sku_quantity_array as $sku => $quantity) {
$product = wc_get_product_id_by_sku($sku);
if ($product) {
$product->set_stock_quantity($quantity);
$product->save();
}
}
}
/* Example:
$sku_quantity_array = array(
'SKU001' => 10,
'SKU002' => 5,
'SKU003' => 2
);
update_product_quantity($sku_quantity_array);
*/
add_action( 'woocommerce_api_my_endpoint', 'my_api_endpoint_callback' );
function my_api_endpoint_callback() {
$sku = $_GET['sku'];
$quantity = $_GET['quantity'];
// Your code to update inventory quantity based on the provided SKU and quantity
}
/* example http call:
https://example.com/wc-api/v3/my_endpoint?sku=SKU001&quantity=10
*/