Contents
On this page
Update Promotion - Plugixa POS for WooCommerce
PUT /plugixa-pos/v1/promotions/{id}
Replace a promotion’s rules. Send the whole promotion: fields you leave out take their empty value. POST and PATCH work the same way.
Needs a user with the plugixa_pos_manage_settings capability (signed in with an Application Password, or the login cookie with an X-WP-Nonce header). Administrators hold it; other roles only when you grant it.
Note. On the way in, a
fixedvalueandmin_totalare decimal amounts ("5.00"). On the way out they are integers in minor units (500). Convert before sending a promotion you read back, or it is saved 100 times larger.
Request
PUT https://your-site.example/wp-json/plugixa-pos/v1/promotions/1
Path parameters
| Name | Type | Description |
|---|---|---|
id |
integer |
The promotion’s id |
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | Printed on the receipt. |
type |
string |
Yes | item_discount, quantity_break, buy_x_get_y or cart_threshold. |
active |
boolean |
No | On or off. |
priority |
integer |
No | Priority, a whole number. Defaults to 0. |
all |
boolean |
No | Every product. Otherwise give products or categories (not needed for cart_threshold). |
products |
integer[] |
No | Product ids. |
categories |
integer[] |
No | Category ids. |
value_type |
string |
No | percent (default) or fixed. buy_x_get_y takes percent only (100 = free). |
value |
number|string |
Yes | A whole percent from 1 to 100, or for fixed a decimal amount such as "5.00". |
min_qty |
integer |
No | quantity_break: from this many, 2 or more. |
buy |
integer |
No | buy_x_get_y: how many to buy. |
get |
integer |
No | buy_x_get_y: how many get the discount. |
min_total |
string |
No | cart_threshold: the amount the sale must reach, decimal. |
roles |
string[] |
No | Only customers with these WordPress roles. |
starts_at |
string|null |
No | YYYY-MM-DD HH:MM, shop time. |
ends_at |
string|null |
No | YYYY-MM-DD HH:MM, after starts_at. |
days |
integer[] |
No | Week days, 1 (Monday) to 7 (Sunday). |
time_from |
string|null |
No | HH:MM, start of the daily window. |
time_to |
string|null |
No | HH:MM, end of the daily window. |
{
"name": "Coffee happy hour -20%",
"type": "item_discount",
"active": false,
"categories": [119],
"value_type": "percent",
"value": 20,
"time_from": "14:00",
"time_to": "16:00"
}
Responses
200 OK. data is the promotion.
{
"success": true,
"data": {
"id": 1,
"name": "Coffee happy hour -20%",
"type": "item_discount",
"active": false,
"priority": 0,
"all": false,
"products": [],
"categories": [119],
"value_type": "percent",
"value": 20,
"min_qty": 0,
"buy": 0,
"get": 0,
"min_total": 0,
"roles": [],
"starts_at": null,
"ends_at": null,
"days": [],
"time_from": "14:00",
"time_to": "16:00",
"product_names": {}
}
}
Errors
| Status | Code | When |
|---|---|---|
404 |
plugixa_pos_not_found |
No promotion with that id. |
422 |
plugixa_pos_promotion_invalid |
A rule is broken: no name, unknown type, a percent outside 1 to 100, no products or categories, a quantity break below 2, an end before the start. The message says which. |
500 |
plugixa_pos_promotion_save |
The promotion could not be saved. |
Plus the errors every endpoint can return.
Examples
curl -s -X PUT "https://your-site.example/wp-json/plugixa-pos/v1/promotions/1" \
-u "$WP_USER:$WP_APP_PASSWORD" \
-H "Content-Type: application/json" \
-d '{"name":"Coffee happy hour -20%","type":"item_discount","active":false,"categories":[119],"value_type":"percent","value":20,"time_from":"14:00","time_to":"16:00"}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-pos/v1/promotions/1');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => getenv('WP_USER') . ':' . getenv('WP_APP_PASSWORD'),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Coffee happy hour -20%',
'type' => 'item_discount',
'active' => false,
'categories' => [119],
'value_type' => 'percent',
'value' => 20,
'time_from' => '14:00',
'time_to' => '16:00',
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-pos/v1/promotions/1', {
method: 'PUT',
headers: {
'Authorization': `Basic ${btoa(`${process.env.WP_USER}:${process.env.WP_APP_PASSWORD}`)}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ name: 'Coffee happy hour -20%', type: 'item_discount', active: false, categories: [119], value_type: 'percent', value: 20, time_from: '14:00', time_to: '16:00' }),
});
const { data } = await response.json();
Quick Links
Share