@@ 56-92 (lines=37) @@ | ||
53 | * @param array $args |
|
54 | * @return string |
|
55 | */ |
|
56 | protected function evaluate_cost( $sum, $args = array() ) { |
|
57 | include_once( 'includes/class-wc-eval-math.php' ); |
|
58 | ||
59 | $locale = localeconv(); |
|
60 | $decimals = array( wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] ); |
|
61 | ||
62 | $this->fee_cost = $args['cost']; |
|
63 | ||
64 | // Expand shortcodes |
|
65 | add_shortcode( 'fee', array( $this, 'fee' ) ); |
|
66 | ||
67 | $sum = do_shortcode( str_replace( |
|
68 | array( |
|
69 | '[qty]', |
|
70 | '[cost]' |
|
71 | ), |
|
72 | array( |
|
73 | $args['qty'], |
|
74 | $args['cost'] |
|
75 | ), |
|
76 | $sum |
|
77 | ) ); |
|
78 | ||
79 | remove_shortcode( 'fee', array( $this, 'fee' ) ); |
|
80 | ||
81 | // Remove whitespace from string |
|
82 | $sum = preg_replace( '/\s+/', '', $sum ); |
|
83 | ||
84 | // Remove locale from string |
|
85 | $sum = str_replace( $decimals, '.', $sum ); |
|
86 | ||
87 | // Trim invalid start/end characters |
|
88 | $sum = rtrim( ltrim( $sum, "\t\n\r\0\x0B+*/" ), "\t\n\r\0\x0B+-*/" ); |
|
89 | ||
90 | // Do the math |
|
91 | return $sum ? WC_Eval_Math::evaluate( $sum ) : 0; |
|
92 | } |
|
93 | ||
94 | /** |
|
95 | * Work out fee (shortcode). |
@@ 74-110 (lines=37) @@ | ||
71 | * @param array $args |
|
72 | * @return string |
|
73 | */ |
|
74 | protected function evaluate_cost( $sum, $args = array() ) { |
|
75 | include_once( 'includes/class-wc-eval-math.php' ); |
|
76 | ||
77 | $locale = localeconv(); |
|
78 | $decimals = array( wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] ); |
|
79 | ||
80 | $this->fee_cost = $args['cost']; |
|
81 | ||
82 | // Expand shortcodes |
|
83 | add_shortcode( 'fee', array( $this, 'fee' ) ); |
|
84 | ||
85 | $sum = do_shortcode( str_replace( |
|
86 | array( |
|
87 | '[qty]', |
|
88 | '[cost]' |
|
89 | ), |
|
90 | array( |
|
91 | $args['qty'], |
|
92 | $args['cost'] |
|
93 | ), |
|
94 | $sum |
|
95 | ) ); |
|
96 | ||
97 | remove_shortcode( 'fee', array( $this, 'fee' ) ); |
|
98 | ||
99 | // Remove whitespace from string |
|
100 | $sum = preg_replace( '/\s+/', '', $sum ); |
|
101 | ||
102 | // Remove locale from string |
|
103 | $sum = str_replace( $decimals, '.', $sum ); |
|
104 | ||
105 | // Trim invalid start/end characters |
|
106 | $sum = rtrim( ltrim( $sum, "\t\n\r\0\x0B+*/" ), "\t\n\r\0\x0B+-*/" ); |
|
107 | ||
108 | // Do the math |
|
109 | return $sum ? WC_Eval_Math::evaluate( $sum ) : 0; |
|
110 | } |
|
111 | ||
112 | /** |
|
113 | * Work out fee (shortcode). |