PluginProbe
Tiered Pricing Table for WooCommerce / 2.2.3
Tiered Pricing Table for WooCommerce v2.2.3
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
← All changes | freemius/includes/entities/class-fs-payment.php +58 -0 2.2.1 → 2.2.3 View file →
@@ -42,8 +42,15 @@
42 42 * @var float
43 43 */
44 44 public $gross;
45 45 /**
46 + * @author Leo Fajardo (@leorw)
47 + * @since 2.3.0
48 + *
49 + * @var string One of the following: `usd`, `gbp`, `eur`.
50 + */
51 + public $currency;
52 + /**
46 53 * @var number
47 54 */
48 55 public $bound_payment_id;
49 56 /**
@@ -74,8 +81,12 @@
74 81 public $source = 0;
75 82
76 83 #endregion Properties
77 84
85 + const CURRENCY_USD = 'usd';
86 + const CURRENCY_GBP = 'gbp';
87 + const CURRENCY_EUR = 'eur';
88 +
78 89 /**
79 90 * @param object|bool $payment
80 91 */
81 92 function __construct( $payment = false ) {
@@ -105,6 +116,53 @@
105 116 * @return bool
106 117 */
107 118 function is_migrated() {
108 119 return ( 0 != $this->source );
120 + }
121 +
122 + /**
123 + * Returns the gross in this format:
124 + * `{symbol}{amount | 2 decimal digits} {currency | uppercase}`
125 + *
126 + * Examples: £9.99 GBP, -£9.99 GBP.
127 + *
128 + * @author Leo Fajardo (@leorw)
129 + * @since 2.3.0
130 + *
131 + * @return string
132 + */
133 + function formatted_gross()
134 + {
135 + return (
136 + ( $this->gross < 0 ? '-' : '' ) .
137 + $this->get_symbol() .
138 + number_format( abs( $this->gross ), 2, '.', ',' ) . ' ' .
139 + strtoupper( $this->currency )
140 + );
141 + }
142 +
143 + /**
144 + * A map between supported currencies with their symbols.
145 + *
146 + * @var array<string,string>
147 + */
148 + static $CURRENCY_2_SYMBOL;
149 +
150 + /**
151 + * @author Leo Fajardo (@leorw)
152 + * @since 2.3.0
153 + *
154 + * @return string
155 + */
156 + private function get_symbol() {
157 + if ( ! isset( self::$CURRENCY_2_SYMBOL ) ) {
158 + // Lazy load.
159 + self::$CURRENCY_2_SYMBOL = array(
160 + self::CURRENCY_USD => '$',
161 + self::CURRENCY_GBP => '£',
162 + self::CURRENCY_EUR => '€',
163 + );
164 + }
165 +
166 + return self::$CURRENCY_2_SYMBOL[ $this->currency ];
109 167 }
110 168 }