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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
<?php
namespace AutomateWoo\Variables;
use AutomateWoo\Variable; use AutomateWoo\Customer; use AutomateWoo\Format; use WC_Points_Rewards_Manager;
defined( 'ABSPATH' ) || exit;
/** * Customer_Points class. * * @since 4.6.0 */ class Customer_Points extends Variable {
/** * Load Admin Details */ public function load_admin_details() { $this->description = __( "Displays the customer's total points.", 'automatewoo' );
$this->add_parameter_select_field( 'format', __( 'Choose whether to display the total number of points or their monetary value.', 'automatewoo' ), [ '' => __( 'Number of Points', 'automatewoo' ), 'decimal' => __( 'Point value as decimal', 'automatewoo' ), 'price' => __( 'Point value as price', 'automatewoo' ), ], false ); }
/** * Get Value method. * * @param Customer $customer * @param array $parameters * * @return string */ public function get_value( $customer, $parameters ) {
if ( ! $customer->is_registered() ) { return false; }
$format = isset( $parameters['format'] ) ? $parameters['format'] : 'total';
$return = null;
switch ( $format ) { case 'total': $return = WC_Points_Rewards_Manager::get_users_points( $customer->get_user_id() ); break; case 'decimal': $return = wc_format_localized_price( Format::decimal( WC_Points_Rewards_Manager::get_users_points_value( $customer->get_user_id() ) ) ); break; case 'price': $raw = WC_Points_Rewards_Manager::get_users_points_value( $customer->get_user_id() ); $return = wc_price( $raw ); break; }
return (string) $return; } }
|