Date.php
1.04 KB
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
<?php
namespace ACA\WC\Editing\OrderSubscription;
use ACP;
use ACP\Editing\View;
use Exception;
use RuntimeException;
class Date implements ACP\Editing\Service
{
private $date_key;
private $clearable;
public function __construct(string $date_key, bool $clearable = false)
{
$this->date_key = $date_key;
$this->clearable = $clearable;
}
public function get_view(string $context): ?View
{
return (new ACP\Editing\View\DateTime())->set_clear_button($this->clearable);
}
public function get_value($id)
{
return wcs_get_subscription($id)->get_date($this->date_key);
}
public function update(int $id, $data): void
{
$subscription = wcs_get_subscription($id);
try {
$subscription->update_dates([
$this->date_key => $data,
], get_option('timezone_string'));
$subscription->save();
} catch (Exception $exception) {
throw new RuntimeException($exception->getMessage());
}
}
}