Rounding.php
846 Bytes
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
<?php
namespace ACA\WC;
use AC;
use AC\Ajax;
final class Rounding implements AC\Registerable {
public function register() {
$this->get_ajax_handler()->register();
}
/**
* @return Ajax\Handler
*/
protected function get_ajax_handler() {
$handler = new Ajax\Handler();
$handler->set_action( 'acp-rounding' )
->set_callback( [ $this, 'ajax_send_feedback' ] );
return $handler;
}
public function ajax_send_feedback() {
$price = filter_input( INPUT_GET, 'price' );
$decimals = filter_input( INPUT_GET, 'decimals' );
$rounding = new Helper\Price\Rounding();
switch ( filter_input( INPUT_GET, 'type' ) ) {
case 'roundup':
echo $rounding->up( $price, $decimals );
exit;
case 'rounddown':
echo $rounding->down( $price, $decimals );
exit;
default :
echo $price;
exit;
}
}
}