feat(admin): coupon field parity/batch and charge-card UX polish
Native coupons expose per-user limit, max discount, batch generate, enable; charge cards support expires_at, code dump after batch, search and CN labels.
This commit is contained in:
@@ -245,6 +245,42 @@ class AKSRT_Coupon {
|
||||
return $wpdb->update($this->table(), ['status' => 'disabled'], ['id' => $id], ['%s'], ['%d']) !== false;
|
||||
}
|
||||
|
||||
public function enable(int $id): bool {
|
||||
global $wpdb;
|
||||
return $wpdb->update($this->table(), ['status' => 'active'], ['id' => $id], ['%s'], ['%d']) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch-create coupons with auto-generated codes.
|
||||
*
|
||||
* @return array{created:int,codes:array<int,string>}
|
||||
*/
|
||||
public function batch_create(array $data, int $count = 1, int $length = 10, string $prefix = ''): array {
|
||||
$count = max(1, min(100, $count));
|
||||
$length = max(6, min(24, $length));
|
||||
$prefix = sanitize_text_field($prefix);
|
||||
$codes = [];
|
||||
$created = 0;
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$code = $prefix !== ''
|
||||
? $prefix . strtoupper(wp_generate_password($length, false, false))
|
||||
: strtoupper(wp_generate_password($length, false, false));
|
||||
$payload = $data;
|
||||
$payload['code'] = $code;
|
||||
$id = $this->create($payload);
|
||||
if ($id > 0) {
|
||||
$created++;
|
||||
$codes[] = $code;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'created' => $created,
|
||||
'codes' => $codes,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many times a user has used a specific coupon.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user