@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | 'subscription_initial_payment' => 'get_subscription_initial', |
28 | 28 | ); |
29 | 29 | |
30 | - foreach ( $shortcodes as $shortcode => $function ) { |
|
31 | - add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), array( __CLASS__, $function ) ); |
|
30 | + foreach ($shortcodes as $shortcode => $function) { |
|
31 | + add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), array(__CLASS__, $function)); |
|
32 | 32 | } // END foreach() |
33 | 33 | |
34 | 34 | // Adds alternative subscription price from the WooCommerce extension "Subscribe to All the Things" and returns the lowest scheme price. |
35 | - add_action( 'woocommerce_subscriptions_shortcode_get_price', array( __CLASS__, 'get_satt_lowest_price' ), 10, 1 ); |
|
35 | + add_action('woocommerce_subscriptions_shortcode_get_price', array(__CLASS__, 'get_satt_lowest_price'), 10, 1); |
|
36 | 36 | |
37 | 37 | // Adds the product types supported from the WooCommerce extension "Subscribe to All the Things". |
38 | - add_filter( 'wcss_product_types', array( __CLASS__, 'support_product_types_for_wc_satt' ), 10, 1 ); |
|
38 | + add_filter('wcss_product_types', array(__CLASS__, 'support_product_types_for_wc_satt'), 10, 1); |
|
39 | 39 | } // END init() |
40 | 40 | |
41 | 41 | /** |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | * @return array |
47 | 47 | */ |
48 | 48 | public static function get_supported_product_types() { |
49 | - return apply_filters( 'wcss_product_types', array( |
|
49 | + return apply_filters('wcss_product_types', array( |
|
50 | 50 | 'subscription', |
51 | 51 | 'subscription-variation', |
52 | - ) ); |
|
52 | + )); |
|
53 | 53 | } // END get_supported_product_types() |
54 | 54 | |
55 | 55 | /** |
@@ -58,15 +58,15 @@ discard block |
||
58 | 58 | * @param WC_Product $product |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - public static function get_price( $product ) { |
|
62 | - if ( WC_Subscriptions_Product::get_price( $product->id ) > 0 ) { |
|
61 | + public static function get_price($product) { |
|
62 | + if (WC_Subscriptions_Product::get_price($product->id) > 0) { |
|
63 | 63 | |
64 | - return ecs_html( WC_Subscriptions_Product::get_price( $product->id, array( |
|
64 | + return ecs_html(WC_Subscriptions_Product::get_price($product->id, array( |
|
65 | 65 | 'subscription_period' => false, |
66 | 66 | 'subscription_length' => false, |
67 | 67 | 'sign_up_fee' => false, |
68 | 68 | 'trial_length' => false, |
69 | - ) ) ); |
|
69 | + ))); |
|
70 | 70 | |
71 | 71 | } else { |
72 | 72 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * hooked: get_satt_lowest_price - 10 |
77 | 77 | */ |
78 | - do_action( 'woocommerce_subscriptions_shortcode_get_price', $product ); |
|
78 | + do_action('woocommerce_subscriptions_shortcode_get_price', $product); |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | } // END get_price() |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | * @param WC_Product $product |
88 | 88 | * @return string |
89 | 89 | */ |
90 | - public static function get_satt_lowest_scheme_data( $product ) { |
|
91 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
92 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product ); |
|
90 | + public static function get_satt_lowest_scheme_data($product) { |
|
91 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
92 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product); |
|
93 | 93 | |
94 | - return WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product, $product_level_schemes ); |
|
94 | + return WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product, $product_level_schemes); |
|
95 | 95 | } |
96 | 96 | } // END get_satt_lowest_scheme() |
97 | 97 | |
@@ -102,42 +102,42 @@ discard block |
||
102 | 102 | * @param WC_Product $product |
103 | 103 | * @return string |
104 | 104 | */ |
105 | - public static function get_satt_lowest_price( $product ) { |
|
106 | - $scheme = self::get_satt_lowest_scheme_data( $product ); |
|
105 | + public static function get_satt_lowest_price($product) { |
|
106 | + $scheme = self::get_satt_lowest_scheme_data($product); |
|
107 | 107 | |
108 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
108 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
109 | 109 | // Override price? |
110 | - $override = $scheme['scheme']['subscription_pricing_method']; |
|
110 | + $override = $scheme[ 'scheme' ][ 'subscription_pricing_method' ]; |
|
111 | 111 | |
112 | 112 | // Discount? |
113 | - $discount = $scheme['scheme']['subscription_discount']; |
|
113 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
114 | 114 | |
115 | 115 | // Prices |
116 | 116 | $prices = array( |
117 | - 'price' => $scheme['price'], |
|
118 | - 'regular_price' => $scheme['regular_price'], |
|
119 | - 'sale_price' => $scheme['sale_price'], |
|
120 | - 'subscription_price' => $scheme['scheme']['subscription_price'], |
|
121 | - 'subscription_regular_price' => $scheme['scheme']['subscription_regular_price'], |
|
122 | - 'subscription_sale_price' => $scheme['scheme']['subscription_sale_price'] |
|
117 | + 'price' => $scheme[ 'price' ], |
|
118 | + 'regular_price' => $scheme[ 'regular_price' ], |
|
119 | + 'sale_price' => $scheme[ 'sale_price' ], |
|
120 | + 'subscription_price' => $scheme[ 'scheme' ][ 'subscription_price' ], |
|
121 | + 'subscription_regular_price' => $scheme[ 'scheme' ][ 'subscription_regular_price' ], |
|
122 | + 'subscription_sale_price' => $scheme[ 'scheme' ][ 'subscription_sale_price' ] |
|
123 | 123 | ); |
124 | 124 | |
125 | 125 | // Prepare the price |
126 | 126 | $price = ''; |
127 | 127 | |
128 | - if ( 'inherit' == $override ) { |
|
129 | - $price = empty( $discount ) ? $price : ( empty( $prices[ 'regular_price' ] ) ? $prices[ 'regular_price' ] : round( ( double ) $prices[ 'regular_price' ] * ( 100 - $discount ) / 100, wc_get_price_decimals() ) ); |
|
130 | - } else if ( 'override' == $override ) { |
|
131 | - $price = $prices['subscription_price']; |
|
128 | + if ('inherit' == $override) { |
|
129 | + $price = empty($discount) ? $price : (empty($prices[ 'regular_price' ]) ? $prices[ 'regular_price' ] : round((double) $prices[ 'regular_price' ] * (100 - $discount) / 100, wc_get_price_decimals())); |
|
130 | + } else if ('override' == $override) { |
|
131 | + $price = $prices[ 'subscription_price' ]; |
|
132 | 132 | |
133 | - if ( $prices[ 'subscription_price' ] < $prices[ 'subscription_regular_price' ] ) { |
|
133 | + if ($prices[ 'subscription_price' ] < $prices[ 'subscription_regular_price' ]) { |
|
134 | 134 | $price = $prices[ 'subscription_sale_price' ]; |
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | 138 | // If the price is returned as an array, return just the first. |
139 | - if ( is_array( $price ) ) { |
|
140 | - $price = $price[0]; |
|
139 | + if (is_array($price)) { |
|
140 | + $price = $price[ 0 ]; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | return $price; |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | * @param array $atts |
154 | 154 | * @return string |
155 | 155 | */ |
156 | - public static function get_subscription_price( $atts ) { |
|
156 | + public static function get_subscription_price($atts) { |
|
157 | 157 | global $wpdb, $post; |
158 | 158 | |
159 | - $defaults = shortcode_atts( array( |
|
159 | + $defaults = shortcode_atts(array( |
|
160 | 160 | 'id' => '', |
161 | 161 | 'sku' => '', |
162 | 162 | 'period' => false, |
@@ -165,47 +165,47 @@ discard block |
||
165 | 165 | 'trial_length' => false, |
166 | 166 | 'before_price' => '<span class="price subscription-price">', |
167 | 167 | 'after_price' => '</span>', |
168 | - ), $atts ); |
|
168 | + ), $atts); |
|
169 | 169 | |
170 | - $atts = wp_parse_args( $atts, $defaults ); |
|
170 | + $atts = wp_parse_args($atts, $defaults); |
|
171 | 171 | |
172 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
173 | - $product_data = wc_get_product( $atts['id'] ); |
|
174 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
175 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
176 | - $product_data = get_post( $product_id ); |
|
172 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
173 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
174 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
175 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
176 | + $product_data = get_post($product_id); |
|
177 | 177 | } else { |
178 | - $product_data = wc_get_product( $post->ID ); |
|
178 | + $product_data = wc_get_product($post->ID); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | // Check that the product type is supported. Return blank if not supported. |
182 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
182 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
183 | 183 | return ''; |
184 | 184 | } |
185 | 185 | |
186 | 186 | ob_start(); |
187 | 187 | |
188 | - $price_html = WC_Subscriptions_Product::get_price_string( $product_data->id, array( |
|
189 | - 'price' => self::get_price( $product_data ), |
|
190 | - 'subscription_period' => isset( $atts['period'] ) ? $atts['period'] : true, |
|
191 | - 'subscription_length' => isset( $atts['length'] ) ? $atts['length'] : true, |
|
192 | - 'sign_up_fee' => isset( $atts['sign_up_fee'] ) ? $atts['sign_up_fee'] : true, |
|
193 | - 'trial_length' => isset( $atts['trial_length'] ) ? $atts['trial_length'] : true, |
|
194 | - ) ); |
|
188 | + $price_html = WC_Subscriptions_Product::get_price_string($product_data->id, array( |
|
189 | + 'price' => self::get_price($product_data), |
|
190 | + 'subscription_period' => isset($atts[ 'period' ]) ? $atts[ 'period' ] : true, |
|
191 | + 'subscription_length' => isset($atts[ 'length' ]) ? $atts[ 'length' ] : true, |
|
192 | + 'sign_up_fee' => isset($atts[ 'sign_up_fee' ]) ? $atts[ 'sign_up_fee' ] : true, |
|
193 | + 'trial_length' => isset($atts[ 'trial_length' ]) ? $atts[ 'trial_length' ] : true, |
|
194 | + )); |
|
195 | 195 | |
196 | 196 | // Clean the subscription price wrapper. |
197 | 197 | $price_html = str_replace('<span class="subscription-details">', '', $price_html); |
198 | 198 | $price_html = str_replace('</span">', '', $price_html); |
199 | 199 | |
200 | 200 | // Trim the whitespace. |
201 | - $price_html = trim( $price_html ); |
|
201 | + $price_html = trim($price_html); |
|
202 | 202 | |
203 | 203 | // Convert to Price Tag. |
204 | - $price_html = wc_price( $price_html ); |
|
204 | + $price_html = wc_price($price_html); |
|
205 | 205 | |
206 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $price_html, $atts['after_price'] ); |
|
206 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $price_html, $atts[ 'after_price' ]); |
|
207 | 207 | |
208 | - echo html_entity_decode( $price_html ); |
|
208 | + echo html_entity_decode($price_html); |
|
209 | 209 | |
210 | 210 | return ob_get_clean(); |
211 | 211 | } // END get_subscription_price() |
@@ -218,46 +218,46 @@ discard block |
||
218 | 218 | * @param array $atts |
219 | 219 | * @return string |
220 | 220 | */ |
221 | - public static function get_subscription_price_meta( $atts ) { |
|
221 | + public static function get_subscription_price_meta($atts) { |
|
222 | 222 | global $wpdb, $post; |
223 | 223 | |
224 | - $defaults = shortcode_atts( array( |
|
224 | + $defaults = shortcode_atts(array( |
|
225 | 225 | 'id' => '', |
226 | 226 | 'sku' => '', |
227 | 227 | 'meta' => 'both', |
228 | 228 | 'before_price' => '', |
229 | 229 | 'after_price' => '', |
230 | - ), $atts ); |
|
230 | + ), $atts); |
|
231 | 231 | |
232 | - $atts = wp_parse_args( $atts, $defaults ); |
|
232 | + $atts = wp_parse_args($atts, $defaults); |
|
233 | 233 | |
234 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
235 | - $product_data = wc_get_product( $atts['id'] ); |
|
236 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
237 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
238 | - $product_data = get_post( $product_id ); |
|
234 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
235 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
236 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
237 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
238 | + $product_data = get_post($product_id); |
|
239 | 239 | } else { |
240 | - $product_data = wc_get_product( $post->ID ); |
|
240 | + $product_data = wc_get_product($post->ID); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Check that the product type is supported. Return blank if not supported. |
244 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
244 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
245 | 245 | return ''; |
246 | 246 | } |
247 | 247 | |
248 | 248 | ob_start(); |
249 | 249 | |
250 | - $price = WC_Subscriptions_Product::get_price( $product_data->id ); |
|
250 | + $price = WC_Subscriptions_Product::get_price($product_data->id); |
|
251 | 251 | |
252 | 252 | // Remove the subscription price wrapper. |
253 | 253 | $price_html = str_replace('<span class="subscription-details">', '', $price); |
254 | 254 | $price = str_replace('</span">', '', $price_html); |
255 | 255 | |
256 | 256 | // If the subscription product has no price, then look for alternative. |
257 | - if ( empty( $price ) ) { |
|
258 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
257 | + if (empty($price)) { |
|
258 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
259 | 259 | |
260 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
260 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
261 | 261 | |
262 | 262 | // These values will be overridden. They are defined here to acknowledge their existence. |
263 | 263 | $price = ''; |
@@ -265,30 +265,30 @@ discard block |
||
265 | 265 | $sale_price = ''; |
266 | 266 | |
267 | 267 | $prices = array( |
268 | - 'price' => $scheme['price'], |
|
269 | - 'regular_price' => $scheme['regular_price'], |
|
270 | - 'sale_price' => $scheme['sale_price'], |
|
271 | - 'method' => $scheme['scheme']['subscription_pricing_method'], |
|
272 | - 'subscription_price' => $scheme['scheme']['subscription_price'], |
|
273 | - 'subscription_regular_price' => $scheme['scheme']['subscription_regular_price'], |
|
274 | - 'subscription_sale_price' => $scheme['scheme']['subscription_sale_price'] |
|
268 | + 'price' => $scheme[ 'price' ], |
|
269 | + 'regular_price' => $scheme[ 'regular_price' ], |
|
270 | + 'sale_price' => $scheme[ 'sale_price' ], |
|
271 | + 'method' => $scheme[ 'scheme' ][ 'subscription_pricing_method' ], |
|
272 | + 'subscription_price' => $scheme[ 'scheme' ][ 'subscription_price' ], |
|
273 | + 'subscription_regular_price' => $scheme[ 'scheme' ][ 'subscription_regular_price' ], |
|
274 | + 'subscription_sale_price' => $scheme[ 'scheme' ][ 'subscription_sale_price' ] |
|
275 | 275 | ); |
276 | 276 | |
277 | 277 | // Return the subscription price based on the pricing method. |
278 | - switch( $prices['method'] ) { |
|
278 | + switch ($prices[ 'method' ]) { |
|
279 | 279 | case 'override': |
280 | - $price = $prices['subscription_price']; |
|
281 | - $regular_price = $prices['subscription_regular_price']; |
|
282 | - $sale_price = $prices['subscription_sale_price']; |
|
280 | + $price = $prices[ 'subscription_price' ]; |
|
281 | + $regular_price = $prices[ 'subscription_regular_price' ]; |
|
282 | + $sale_price = $prices[ 'subscription_sale_price' ]; |
|
283 | 283 | break; |
284 | 284 | case 'inherit': |
285 | - $discount = $scheme['scheme']['subscription_discount']; |
|
286 | - $price = $prices['price']; |
|
287 | - $regular_price = $prices['regular_price']; |
|
288 | - $sale_price = $prices['sale_price']; |
|
285 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
286 | + $price = $prices[ 'price' ]; |
|
287 | + $regular_price = $prices[ 'regular_price' ]; |
|
288 | + $sale_price = $prices[ 'sale_price' ]; |
|
289 | 289 | |
290 | - if ( !empty( $discount ) && $discount > 0 ) { |
|
291 | - $sale_price = round( ( double ) $regular_price * ( 100 - $discount ) / 100, wc_get_price_decimals() ); |
|
290 | + if ( ! empty($discount) && $discount > 0) { |
|
291 | + $sale_price = round((double) $regular_price * (100 - $discount) / 100, wc_get_price_decimals()); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | break; |
@@ -296,42 +296,42 @@ discard block |
||
296 | 296 | |
297 | 297 | // Display both the regular price striked out and the sale price |
298 | 298 | // should the active price be less than the regular price. |
299 | - if ( $atts['meta'] != 'active' && !empty( $sale_price ) && $price < $regular_price ) { |
|
300 | - $price = '<del>' . ( ( is_numeric( $regular_price ) ) ? wc_price( $regular_price ) : $regular_price ) . '</del> <ins>' . ( ( is_numeric( $sale_price ) ) ? wc_price( $sale_price ) : $sale_price ) . '</ins>'; |
|
299 | + if ($atts[ 'meta' ] != 'active' && ! empty($sale_price) && $price < $regular_price) { |
|
300 | + $price = '<del>' . ((is_numeric($regular_price)) ? wc_price($regular_price) : $regular_price) . '</del> <ins>' . ((is_numeric($sale_price)) ? wc_price($sale_price) : $sale_price) . '</ins>'; |
|
301 | 301 | |
302 | 302 | // Trim the whitespace. |
303 | - $price = trim( $price ); |
|
303 | + $price = trim($price); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | // Override the value should only one value be returned. |
307 | - if ( $atts['meta'] != 'both' ) { |
|
308 | - if ( $atts['meta'] == 'active' ) { |
|
307 | + if ($atts[ 'meta' ] != 'both') { |
|
308 | + if ($atts[ 'meta' ] == 'active') { |
|
309 | 309 | $price = $price; |
310 | 310 | } |
311 | 311 | |
312 | - if ( $atts['meta'] == 'regular' ) { |
|
312 | + if ($atts[ 'meta' ] == 'regular') { |
|
313 | 313 | $price = $regular_price; |
314 | 314 | } |
315 | 315 | |
316 | - if ( $atts['meta'] == 'sale' ) { |
|
316 | + if ($atts[ 'meta' ] == 'sale') { |
|
317 | 317 | $price = $sale_price; |
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
321 | - if ( is_numeric( $price ) ) { |
|
322 | - $price = wc_price( $price ); |
|
321 | + if (is_numeric($price)) { |
|
322 | + $price = wc_price($price); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | // Clean the price tag. |
326 | - $price = self::clean_wc_price( $price ); |
|
326 | + $price = self::clean_wc_price($price); |
|
327 | 327 | |
328 | 328 | } |
329 | 329 | |
330 | 330 | } |
331 | 331 | |
332 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $price, $atts['after_price'] ); |
|
332 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $price, $atts[ 'after_price' ]); |
|
333 | 333 | |
334 | - echo html_entity_decode( $price_html ); |
|
334 | + echo html_entity_decode($price_html); |
|
335 | 335 | |
336 | 336 | return ob_get_clean(); |
337 | 337 | } // END get_subscription_price_meta() |
@@ -344,27 +344,27 @@ discard block |
||
344 | 344 | * @param array $atts |
345 | 345 | * @return string |
346 | 346 | */ |
347 | - public static function get_subscription_discount( $atts ) { |
|
347 | + public static function get_subscription_discount($atts) { |
|
348 | 348 | global $wpdb, $post; |
349 | 349 | |
350 | - $defaults = shortcode_atts( array( |
|
350 | + $defaults = shortcode_atts(array( |
|
351 | 351 | 'id' => '', |
352 | 352 | 'sku' => '', |
353 | - ), $atts ); |
|
353 | + ), $atts); |
|
354 | 354 | |
355 | - $atts = wp_parse_args( $atts, $defaults ); |
|
355 | + $atts = wp_parse_args($atts, $defaults); |
|
356 | 356 | |
357 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
358 | - $product_data = wc_get_product( $atts['id'] ); |
|
359 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
360 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
361 | - $product_data = get_post( $product_id ); |
|
357 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
358 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
359 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
360 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
361 | + $product_data = get_post($product_id); |
|
362 | 362 | } else { |
363 | - $product_data = wc_get_product( $post->ID ); |
|
363 | + $product_data = wc_get_product($post->ID); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | // Check that the product type is supported. Return blank if not supported. |
367 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
367 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
368 | 368 | return ''; |
369 | 369 | } |
370 | 370 | |
@@ -374,18 +374,18 @@ discard block |
||
374 | 374 | $discount = ''; // Returns empty by default. |
375 | 375 | |
376 | 376 | // Get Subscription Discount - Only available with the WooCommerce extension "Subscribe to All the Things". |
377 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
377 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
378 | 378 | |
379 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
379 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
380 | 380 | // Override price? |
381 | - $override = $scheme['scheme']['subscription_pricing_method']; |
|
381 | + $override = $scheme[ 'scheme' ][ 'subscription_pricing_method' ]; |
|
382 | 382 | |
383 | 383 | // Discount ? |
384 | - $discount = $scheme['scheme']['subscription_discount']; |
|
384 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( ! empty( $discount ) && is_numeric( $discount ) && $override == 'inherit' ) { |
|
388 | - $discount = sprintf( __( '%s%s %s', WCSS::TEXT_DOMAIN ), $discount, '%', apply_filters( 'wcs_shortcodes_sub_discount_string', __( 'discount', WCSS::TEXT_DOMAIN ) ) ); |
|
387 | + if ( ! empty($discount) && is_numeric($discount) && $override == 'inherit') { |
|
388 | + $discount = sprintf(__('%s%s %s', WCSS::TEXT_DOMAIN), $discount, '%', apply_filters('wcs_shortcodes_sub_discount_string', __('discount', WCSS::TEXT_DOMAIN))); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | echo $discount; |
@@ -399,47 +399,47 @@ discard block |
||
399 | 399 | * @param array $atts |
400 | 400 | * @return string |
401 | 401 | */ |
402 | - public static function get_subscription_period( $atts ) { |
|
402 | + public static function get_subscription_period($atts) { |
|
403 | 403 | global $wpdb, $post; |
404 | 404 | |
405 | - $defaults = shortcode_atts( array( |
|
405 | + $defaults = shortcode_atts(array( |
|
406 | 406 | 'id' => '', |
407 | 407 | 'sku' => '', |
408 | 408 | 'raw' => false |
409 | - ), $atts ); |
|
409 | + ), $atts); |
|
410 | 410 | |
411 | - $atts = wp_parse_args( $atts, $defaults ); |
|
411 | + $atts = wp_parse_args($atts, $defaults); |
|
412 | 412 | |
413 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
414 | - $product_data = wc_get_product( $atts['id'] ); |
|
415 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
416 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
417 | - $product_data = get_post( $product_id ); |
|
413 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
414 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
415 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
416 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
417 | + $product_data = get_post($product_id); |
|
418 | 418 | } else { |
419 | - $product_data = wc_get_product( $post->ID ); |
|
419 | + $product_data = wc_get_product($post->ID); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | // Check that the product type is supported. Return blank if not supported. |
423 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
423 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
424 | 424 | return ''; |
425 | 425 | } |
426 | 426 | |
427 | 427 | ob_start(); |
428 | 428 | |
429 | 429 | // Get Subscription Period |
430 | - $period = WC_Subscriptions_Product::get_period( $product_data ); |
|
430 | + $period = WC_Subscriptions_Product::get_period($product_data); |
|
431 | 431 | |
432 | 432 | // If the period is empty, look for alternative. |
433 | - if ( empty( $period ) ) { |
|
434 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
433 | + if (empty($period)) { |
|
434 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
435 | 435 | |
436 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
437 | - $period = $scheme['scheme']['subscription_period']; |
|
436 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
437 | + $period = $scheme[ 'scheme' ][ 'subscription_period' ]; |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | - if ( ! $atts['raw'] ) { |
|
442 | - $period = sprintf( __( 'Per %s', WCSS::TEXT_DOMAIN ), $period ); |
|
441 | + if ( ! $atts[ 'raw' ]) { |
|
442 | + $period = sprintf(__('Per %s', WCSS::TEXT_DOMAIN), $period); |
|
443 | 443 | $period = ucwords($period); |
444 | 444 | } |
445 | 445 | |
@@ -454,41 +454,41 @@ discard block |
||
454 | 454 | * @param array $atts |
455 | 455 | * @return string |
456 | 456 | */ |
457 | - public static function get_subscription_period_interval( $atts ) { |
|
457 | + public static function get_subscription_period_interval($atts) { |
|
458 | 458 | global $wpdb, $post; |
459 | 459 | |
460 | - $defaults = shortcode_atts( array( |
|
460 | + $defaults = shortcode_atts(array( |
|
461 | 461 | 'id' => '', |
462 | 462 | 'sku' => '', |
463 | - ), $atts ); |
|
463 | + ), $atts); |
|
464 | 464 | |
465 | - $atts = wp_parse_args( $atts, $defaults ); |
|
465 | + $atts = wp_parse_args($atts, $defaults); |
|
466 | 466 | |
467 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
468 | - $product_data = wc_get_product( $atts['id'] ); |
|
469 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
470 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
471 | - $product_data = get_post( $product_id ); |
|
467 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
468 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
469 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
470 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
471 | + $product_data = get_post($product_id); |
|
472 | 472 | } else { |
473 | - $product_data = wc_get_product( $post->ID ); |
|
473 | + $product_data = wc_get_product($post->ID); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | // Check that the product type is supported. Return blank if not supported. |
477 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
477 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
478 | 478 | return ''; |
479 | 479 | } |
480 | 480 | |
481 | 481 | ob_start(); |
482 | 482 | |
483 | 483 | // Get Subscription Period Interval |
484 | - $period_interval = WC_Subscriptions_Product::get_interval( $product_data ); |
|
484 | + $period_interval = WC_Subscriptions_Product::get_interval($product_data); |
|
485 | 485 | |
486 | 486 | // If the period is empty, look for alternative. |
487 | - if ( empty( $period_interval ) ) { |
|
488 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
487 | + if (empty($period_interval)) { |
|
488 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
489 | 489 | |
490 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
491 | - $period_interval = $scheme['scheme']['subscription_period_interval']; |
|
490 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
491 | + $period_interval = $scheme[ 'scheme' ][ 'subscription_period_interval' ]; |
|
492 | 492 | } |
493 | 493 | } |
494 | 494 | |
@@ -503,52 +503,52 @@ discard block |
||
503 | 503 | * @param array $atts |
504 | 504 | * @return string |
505 | 505 | */ |
506 | - public static function get_subscription_length( $atts ) { |
|
506 | + public static function get_subscription_length($atts) { |
|
507 | 507 | global $wpdb, $post; |
508 | 508 | |
509 | - $defaults = shortcode_atts( array( |
|
509 | + $defaults = shortcode_atts(array( |
|
510 | 510 | 'id' => '', |
511 | 511 | 'sku' => '', |
512 | 512 | 'raw' => false, |
513 | - ), $atts ); |
|
513 | + ), $atts); |
|
514 | 514 | |
515 | - $atts = wp_parse_args( $atts, $defaults ); |
|
515 | + $atts = wp_parse_args($atts, $defaults); |
|
516 | 516 | |
517 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
518 | - $product_data = wc_get_product( $atts['id'] ); |
|
519 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
520 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
521 | - $product_data = get_post( $product_id ); |
|
517 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
518 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
519 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
520 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
521 | + $product_data = get_post($product_id); |
|
522 | 522 | } else { |
523 | - $product_data = wc_get_product( $post->ID ); |
|
523 | + $product_data = wc_get_product($post->ID); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | // Check that the product type is supported. Return blank if not supported. |
527 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
527 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
528 | 528 | return ''; |
529 | 529 | } |
530 | 530 | |
531 | 531 | ob_start(); |
532 | 532 | |
533 | 533 | // Get Subscription Length |
534 | - $length = WC_Subscriptions_Product::get_length( $product_data ); |
|
534 | + $length = WC_Subscriptions_Product::get_length($product_data); |
|
535 | 535 | |
536 | 536 | // If the length is empty, look for alternative. |
537 | - if ( empty( $length ) ) { |
|
538 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
537 | + if (empty($length)) { |
|
538 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
539 | 539 | |
540 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
540 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
541 | 541 | |
542 | - $period = self::get_subscription_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
543 | - $length = $scheme['scheme']['subscription_length']; |
|
542 | + $period = self::get_subscription_period(array('id' => $product_data->id, 'raw' => true)); |
|
543 | + $length = $scheme[ 'scheme' ][ 'subscription_length' ]; |
|
544 | 544 | |
545 | 545 | // If we are not returning raw data then making it readable for humans. |
546 | - if ( ! $atts['raw'] ) { |
|
546 | + if ( ! $atts[ 'raw' ]) { |
|
547 | 547 | |
548 | - if ( $length > 0 ) { |
|
549 | - $length = sprintf( '%s %s', $length, $period ); |
|
548 | + if ($length > 0) { |
|
549 | + $length = sprintf('%s %s', $length, $period); |
|
550 | 550 | } else { |
551 | - $length = sprintf( __( 'Every %s', WCSS::TEXT_DOMAIN ), $period ); |
|
551 | + $length = sprintf(__('Every %s', WCSS::TEXT_DOMAIN), $period); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | $length = ucfirst($length); |
@@ -570,59 +570,59 @@ discard block |
||
570 | 570 | * @param array $atts |
571 | 571 | * @return string |
572 | 572 | */ |
573 | - public static function get_subscription_sign_up_fee( $atts ) { |
|
573 | + public static function get_subscription_sign_up_fee($atts) { |
|
574 | 574 | global $wpdb, $post; |
575 | 575 | |
576 | - $defaults = shortcode_atts( array( |
|
576 | + $defaults = shortcode_atts(array( |
|
577 | 577 | 'id' => '', |
578 | 578 | 'sku' => '', |
579 | 579 | 'raw' => false, |
580 | 580 | 'before_price' => '', |
581 | 581 | 'after_price' => '', |
582 | - ), $atts ); |
|
582 | + ), $atts); |
|
583 | 583 | |
584 | - $atts = wp_parse_args( $atts, $defaults ); |
|
584 | + $atts = wp_parse_args($atts, $defaults); |
|
585 | 585 | |
586 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
587 | - $product_data = wc_get_product( $atts['id'] ); |
|
588 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
589 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
590 | - $product_data = get_post( $product_id ); |
|
586 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
587 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
588 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
589 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
590 | + $product_data = get_post($product_id); |
|
591 | 591 | } else { |
592 | - $product_data = wc_get_product( $post->ID ); |
|
592 | + $product_data = wc_get_product($post->ID); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | // Check that the product type is supported. Return blank if not supported. |
596 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
596 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
597 | 597 | return ''; |
598 | 598 | } |
599 | 599 | |
600 | 600 | ob_start(); |
601 | 601 | |
602 | 602 | // Get Subscription Sign Up Fee |
603 | - $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product_data ); |
|
603 | + $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product_data); |
|
604 | 604 | |
605 | 605 | // If the sign up fee is empty, look for alternative. |
606 | - if ( empty( $sign_up_fee ) ) { |
|
607 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
606 | + if (empty($sign_up_fee)) { |
|
607 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
608 | 608 | |
609 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
610 | - $sign_up_fee = $scheme['scheme']['subscription_sign_up_fee']; |
|
609 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
610 | + $sign_up_fee = $scheme[ 'scheme' ][ 'subscription_sign_up_fee' ]; |
|
611 | 611 | } |
612 | 612 | } |
613 | 613 | |
614 | - if ( ! $atts['raw'] ) { |
|
614 | + if ( ! $atts[ 'raw' ]) { |
|
615 | 615 | // Convert number into a price tag. |
616 | - if ( is_numeric( $sign_up_fee ) ) { |
|
617 | - $sign_up_fee = wc_price( $sign_up_fee ); |
|
616 | + if (is_numeric($sign_up_fee)) { |
|
617 | + $sign_up_fee = wc_price($sign_up_fee); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | // Clean the price tag. |
621 | - $sign_up_fee = self::clean_wc_price( $sign_up_fee ); |
|
621 | + $sign_up_fee = self::clean_wc_price($sign_up_fee); |
|
622 | 622 | |
623 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $sign_up_fee, $atts['after_price'] ); |
|
623 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $sign_up_fee, $atts[ 'after_price' ]); |
|
624 | 624 | |
625 | - $sign_up_fee = html_entity_decode( $price_html ); |
|
625 | + $sign_up_fee = html_entity_decode($price_html); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | echo $sign_up_fee; |
@@ -636,55 +636,55 @@ discard block |
||
636 | 636 | * @param array $atts |
637 | 637 | * @return string |
638 | 638 | */ |
639 | - public static function get_subscription_trial_string( $atts ) { |
|
639 | + public static function get_subscription_trial_string($atts) { |
|
640 | 640 | global $wpdb, $post; |
641 | 641 | |
642 | - $defaults = shortcode_atts( array( |
|
642 | + $defaults = shortcode_atts(array( |
|
643 | 643 | 'id' => '', |
644 | 644 | 'sku' => '', |
645 | - ), $atts ); |
|
645 | + ), $atts); |
|
646 | 646 | |
647 | - $atts = wp_parse_args( $atts, $defaults ); |
|
647 | + $atts = wp_parse_args($atts, $defaults); |
|
648 | 648 | |
649 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
650 | - $product_data = wc_get_product( $atts['id'] ); |
|
651 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
652 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
653 | - $product_data = get_post( $product_id ); |
|
649 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
650 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
651 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
652 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
653 | + $product_data = get_post($product_id); |
|
654 | 654 | } else { |
655 | - $product_data = wc_get_product( $post->ID ); |
|
655 | + $product_data = wc_get_product($post->ID); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | // Check that the product type is supported. Return blank if not supported. |
659 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
659 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
660 | 660 | return ''; |
661 | 661 | } |
662 | 662 | |
663 | 663 | ob_start(); |
664 | 664 | |
665 | 665 | // Get Subscription Trial Length |
666 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
666 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
667 | 667 | |
668 | 668 | // Get Subscription Trial Period |
669 | - $trial_period = self::get_subscription_trial_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
669 | + $trial_period = self::get_subscription_trial_period(array('id' => $product_data->id, 'raw' => true)); |
|
670 | 670 | |
671 | - if ( ! empty( $trial_length ) && $trial_length > 0 ) { |
|
671 | + if ( ! empty($trial_length) && $trial_length > 0) { |
|
672 | 672 | |
673 | - switch ( $trial_period ) { |
|
673 | + switch ($trial_period) { |
|
674 | 674 | case 'day': |
675 | - echo sprintf( _n( '%s day', '%s days', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
675 | + echo sprintf(_n('%s day', '%s days', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
676 | 676 | break; |
677 | 677 | |
678 | 678 | case 'week': |
679 | - echo sprintf( _n( '%s week', '%s weeks', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
679 | + echo sprintf(_n('%s week', '%s weeks', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
680 | 680 | break; |
681 | 681 | |
682 | 682 | case 'month': |
683 | - echo sprintf( _n( '%s month', '%s months', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
683 | + echo sprintf(_n('%s month', '%s months', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
684 | 684 | break; |
685 | 685 | |
686 | 686 | case 'year': |
687 | - echo sprintf( _n( '%s year', '%s years', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
687 | + echo sprintf(_n('%s year', '%s years', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
688 | 688 | break; |
689 | 689 | } |
690 | 690 | |
@@ -699,41 +699,41 @@ discard block |
||
699 | 699 | * @param array $atts |
700 | 700 | * @return string |
701 | 701 | */ |
702 | - public static function get_subscription_trial_length( $atts ) { |
|
702 | + public static function get_subscription_trial_length($atts) { |
|
703 | 703 | global $wpdb, $post; |
704 | 704 | |
705 | - $defaults = shortcode_atts( array( |
|
705 | + $defaults = shortcode_atts(array( |
|
706 | 706 | 'id' => '', |
707 | 707 | 'sku' => '', |
708 | - ), $atts ); |
|
708 | + ), $atts); |
|
709 | 709 | |
710 | - $atts = wp_parse_args( $atts, $defaults ); |
|
710 | + $atts = wp_parse_args($atts, $defaults); |
|
711 | 711 | |
712 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
713 | - $product_data = wc_get_product( $atts['id'] ); |
|
714 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
715 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
716 | - $product_data = get_post( $product_id ); |
|
712 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
713 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
714 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
715 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
716 | + $product_data = get_post($product_id); |
|
717 | 717 | } else { |
718 | - $product_data = wc_get_product( $post->ID ); |
|
718 | + $product_data = wc_get_product($post->ID); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | // Check that the product type is supported. Return blank if not supported. |
722 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
722 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
723 | 723 | return ''; |
724 | 724 | } |
725 | 725 | |
726 | 726 | ob_start(); |
727 | 727 | |
728 | 728 | // Get Subscription Trial Length |
729 | - $trial_length = WC_Subscriptions_Product::get_trial_length( $product_data ); |
|
729 | + $trial_length = WC_Subscriptions_Product::get_trial_length($product_data); |
|
730 | 730 | |
731 | 731 | // If the trial length is empty, look for alternative. |
732 | - if ( empty( $trial_length ) ) { |
|
733 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
732 | + if (empty($trial_length)) { |
|
733 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
734 | 734 | |
735 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
736 | - $trial_length = $scheme['scheme']['subscription_trial_length']; |
|
735 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
736 | + $trial_length = $scheme[ 'scheme' ][ 'subscription_trial_length' ]; |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
@@ -748,52 +748,52 @@ discard block |
||
748 | 748 | * @param array $atts |
749 | 749 | * @return string |
750 | 750 | */ |
751 | - public static function get_subscription_trial_period( $atts ) { |
|
751 | + public static function get_subscription_trial_period($atts) { |
|
752 | 752 | global $wpdb, $post; |
753 | 753 | |
754 | - $defaults = shortcode_atts( array( |
|
754 | + $defaults = shortcode_atts(array( |
|
755 | 755 | 'id' => '', |
756 | 756 | 'sku' => '', |
757 | 757 | 'raw' => false, |
758 | - ), $atts ); |
|
758 | + ), $atts); |
|
759 | 759 | |
760 | - $atts = wp_parse_args( $atts, $defaults ); |
|
760 | + $atts = wp_parse_args($atts, $defaults); |
|
761 | 761 | |
762 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
763 | - $product_data = wc_get_product( $atts['id'] ); |
|
764 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
765 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
766 | - $product_data = get_post( $product_id ); |
|
762 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
763 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
764 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
765 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
766 | + $product_data = get_post($product_id); |
|
767 | 767 | } else { |
768 | - $product_data = wc_get_product( $post->ID ); |
|
768 | + $product_data = wc_get_product($post->ID); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | // Check that the product type is supported. Return blank if not supported. |
772 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
772 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
773 | 773 | return ''; |
774 | 774 | } |
775 | 775 | |
776 | 776 | ob_start(); |
777 | 777 | |
778 | 778 | // Get Subscription Trial Length |
779 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
779 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
780 | 780 | |
781 | 781 | // Get Subscription Trial Period |
782 | - $trial_period = WC_Subscriptions_Product::get_trial_period( $product_data ); |
|
782 | + $trial_period = WC_Subscriptions_Product::get_trial_period($product_data); |
|
783 | 783 | |
784 | 784 | // If the trial length is empty or is not zero, look for alternative. |
785 | - if ( empty( $trial_length ) || $trial_length != 0 ) { |
|
786 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
785 | + if (empty($trial_length) || $trial_length != 0) { |
|
786 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
787 | 787 | |
788 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
789 | - $trial_length = $scheme['scheme']['subscription_trial_length']; |
|
790 | - $trial_period = $scheme['scheme']['subscription_trial_period']; |
|
788 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
789 | + $trial_length = $scheme[ 'scheme' ][ 'subscription_trial_length' ]; |
|
790 | + $trial_period = $scheme[ 'scheme' ][ 'subscription_trial_period' ]; |
|
791 | 791 | } |
792 | 792 | } |
793 | 793 | |
794 | - if ( ! empty( $trial_length ) && $trial_length > 0 ) { |
|
794 | + if ( ! empty($trial_length) && $trial_length > 0) { |
|
795 | 795 | |
796 | - if ( ! $atts['raw'] ) { |
|
796 | + if ( ! $atts[ 'raw' ]) { |
|
797 | 797 | $trial_period = ucfirst($trial_period); |
798 | 798 | } |
799 | 799 | |
@@ -810,62 +810,62 @@ discard block |
||
810 | 810 | * @param array $atts |
811 | 811 | * @return string |
812 | 812 | */ |
813 | - public static function get_subscription_first_payment( $atts ) { |
|
813 | + public static function get_subscription_first_payment($atts) { |
|
814 | 814 | global $wpdb, $post; |
815 | 815 | |
816 | - $defaults = shortcode_atts( array( |
|
816 | + $defaults = shortcode_atts(array( |
|
817 | 817 | 'id' => '', |
818 | 818 | 'sku' => '', |
819 | 819 | 'show_time' => false, |
820 | 820 | 'from_date' => '', |
821 | 821 | 'timezone' => 'gmt', |
822 | 822 | 'format' => 'timestamp' |
823 | - ), $atts ); |
|
823 | + ), $atts); |
|
824 | 824 | |
825 | - $atts = wp_parse_args( $atts, $defaults ); |
|
825 | + $atts = wp_parse_args($atts, $defaults); |
|
826 | 826 | |
827 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
828 | - $product_data = wc_get_product( $atts['id'] ); |
|
829 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
830 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
831 | - $product_data = get_post( $product_id ); |
|
827 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
828 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
829 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
830 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
831 | + $product_data = get_post($product_id); |
|
832 | 832 | } else { |
833 | - $product_data = wc_get_product( $post->ID ); |
|
833 | + $product_data = wc_get_product($post->ID); |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | // Check that the product type is supported. Return blank if not supported. |
837 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
837 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
838 | 838 | return ''; |
839 | 839 | } |
840 | 840 | |
841 | 841 | ob_start(); |
842 | 842 | |
843 | - $billing_interval = self::get_subscription_period_interval( array( 'id' => $product_data->id ) ); |
|
844 | - $billing_length = self::get_subscription_length( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
845 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
843 | + $billing_interval = self::get_subscription_period_interval(array('id' => $product_data->id)); |
|
844 | + $billing_length = self::get_subscription_length(array('id' => $product_data->id, 'raw' => true)); |
|
845 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
846 | 846 | |
847 | - $from_date = $atts['from_date']; |
|
847 | + $from_date = $atts[ 'from_date' ]; |
|
848 | 848 | |
849 | - if ( $billing_interval !== $billing_length || $trial_length > 0 ) { |
|
850 | - if ( empty( $from_date ) ) { |
|
851 | - $from_date = gmdate( 'Y-m-d H:i:s' ); |
|
849 | + if ($billing_interval !== $billing_length || $trial_length > 0) { |
|
850 | + if (empty($from_date)) { |
|
851 | + $from_date = gmdate('Y-m-d H:i:s'); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | // If the subscription has a free trial period, the first renewal is the same as the expiration of the free trial. |
855 | - if ( $trial_length > 0 ) { |
|
856 | - $first_renewal_timestamp = strtotime( self::get_trial_expiration_date( $product_data->id, $from_date ) ); |
|
855 | + if ($trial_length > 0) { |
|
856 | + $first_renewal_timestamp = strtotime(self::get_trial_expiration_date($product_data->id, $from_date)); |
|
857 | 857 | } else { |
858 | - $from_timestamp = strtotime( $from_date ); |
|
859 | - $billing_period = self::get_subscription_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
858 | + $from_timestamp = strtotime($from_date); |
|
859 | + $billing_period = self::get_subscription_period(array('id' => $product_data->id, 'raw' => true)); |
|
860 | 860 | |
861 | - if ( 'month' == $billing_period ) { |
|
862 | - $first_renewal_timestamp = wcs_add_months( $from_timestamp, $billing_interval ); |
|
861 | + if ('month' == $billing_period) { |
|
862 | + $first_renewal_timestamp = wcs_add_months($from_timestamp, $billing_interval); |
|
863 | 863 | } else { |
864 | - $first_renewal_timestamp = strtotime( "+ $billing_interval {$billing_period}s", $from_timestamp ); |
|
864 | + $first_renewal_timestamp = strtotime("+ $billing_interval {$billing_period}s", $from_timestamp); |
|
865 | 865 | } |
866 | 866 | |
867 | - if ( 'site' == $atts['timezone'] ) { |
|
868 | - $first_renewal_timestamp += ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
867 | + if ('site' == $atts[ 'timezone' ]) { |
|
868 | + $first_renewal_timestamp += (get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
869 | 869 | } |
870 | 870 | } |
871 | 871 | } else { |
@@ -874,24 +874,24 @@ discard block |
||
874 | 874 | |
875 | 875 | $date_format = ''; // Will be overridden later on. |
876 | 876 | |
877 | - if ( $first_renewal_timestamp > 0 ) { |
|
878 | - if ( $atts['show_time'] ) { |
|
879 | - if ( 'timestamp' == $atts['format'] ) { |
|
877 | + if ($first_renewal_timestamp > 0) { |
|
878 | + if ($atts[ 'show_time' ]) { |
|
879 | + if ('timestamp' == $atts[ 'format' ]) { |
|
880 | 880 | $date_format = 'Y-m-d H:i:s'; |
881 | - } else if ( 'string' == $atts['format'] ) { |
|
881 | + } else if ('string' == $atts[ 'format' ]) { |
|
882 | 882 | $date_format = 'D jS F Y H:i A'; |
883 | 883 | } |
884 | 884 | } else { |
885 | - if ( 'timestamp' == $atts['format'] ) { |
|
885 | + if ('timestamp' == $atts[ 'format' ]) { |
|
886 | 886 | $date_format = 'Y-m-d'; |
887 | - } else if ( 'string' == $atts['format'] ) { |
|
887 | + } else if ('string' == $atts[ 'format' ]) { |
|
888 | 888 | $date_format = 'D jS F Y'; |
889 | 889 | } |
890 | 890 | } |
891 | 891 | |
892 | - $date_format = apply_filters( 'wcss_first_payment_date_format', $date_format, $atts ); |
|
892 | + $date_format = apply_filters('wcss_first_payment_date_format', $date_format, $atts); |
|
893 | 893 | |
894 | - $first_payment = date( $date_format, $first_renewal_timestamp ); |
|
894 | + $first_payment = date($date_format, $first_renewal_timestamp); |
|
895 | 895 | } else { |
896 | 896 | $first_payment = ''; |
897 | 897 | } |
@@ -907,65 +907,65 @@ discard block |
||
907 | 907 | * @param array $atts |
908 | 908 | * @return string |
909 | 909 | */ |
910 | - public static function get_subscription_initial( $atts ) { |
|
910 | + public static function get_subscription_initial($atts) { |
|
911 | 911 | global $wpdb, $post; |
912 | 912 | |
913 | - $defaults = shortcode_atts( array( |
|
913 | + $defaults = shortcode_atts(array( |
|
914 | 914 | 'id' => '', |
915 | 915 | 'sku' => '', |
916 | 916 | 'total' => false |
917 | - ), $atts ); |
|
917 | + ), $atts); |
|
918 | 918 | |
919 | - $atts = wp_parse_args( $atts, $defaults ); |
|
919 | + $atts = wp_parse_args($atts, $defaults); |
|
920 | 920 | |
921 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
922 | - $product_data = wc_get_product( $atts['id'] ); |
|
923 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
924 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
925 | - $product_data = get_post( $product_id ); |
|
921 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
922 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
923 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
924 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
925 | + $product_data = get_post($product_id); |
|
926 | 926 | } else { |
927 | - $product_data = wc_get_product( $post->ID ); |
|
927 | + $product_data = wc_get_product($post->ID); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | // Check that the product type is supported. Return blank if not supported. |
931 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
931 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
932 | 932 | return ''; |
933 | 933 | } |
934 | 934 | |
935 | 935 | ob_start(); |
936 | 936 | |
937 | 937 | // Subscription Active Price |
938 | - $initial_payment = self::get_subscription_price_meta( array( 'id' => $product_data->id, 'meta' => 'active' ) ); |
|
938 | + $initial_payment = self::get_subscription_price_meta(array('id' => $product_data->id, 'meta' => 'active')); |
|
939 | 939 | |
940 | 940 | // Free Trial ? |
941 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
941 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
942 | 942 | |
943 | 943 | // If there is a free trial then the initial payment is Zero. |
944 | - if ( $trial_length > 0 ) { |
|
944 | + if ($trial_length > 0) { |
|
945 | 945 | $initial_payment = 0; |
946 | 946 | } |
947 | 947 | |
948 | 948 | // Sign up fee ? |
949 | - $sign_up_fee = self::get_subscription_sign_up_fee( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
949 | + $sign_up_fee = self::get_subscription_sign_up_fee(array('id' => $product_data->id, 'raw' => true)); |
|
950 | 950 | |
951 | 951 | // Apply the sign up fee if it exists. |
952 | - if ( !empty( $sign_up_fee ) && $sign_up_fee > 0 ) { |
|
952 | + if ( ! empty($sign_up_fee) && $sign_up_fee > 0) { |
|
953 | 953 | |
954 | - if ( ! $atts['total'] ) { |
|
955 | - $initial_payment = sprintf( __( '%s with a %s sign up fee.', WCSS::TEXT_DOMAIN ), wc_price( $initial_payment ), wc_price( $sign_up_fee ) ); |
|
954 | + if ( ! $atts[ 'total' ]) { |
|
955 | + $initial_payment = sprintf(__('%s with a %s sign up fee.', WCSS::TEXT_DOMAIN), wc_price($initial_payment), wc_price($sign_up_fee)); |
|
956 | 956 | } else { |
957 | - $initial_payment = round( ( double ) $initial_payment+$sign_up_fee, wc_get_price_decimals() ); |
|
957 | + $initial_payment = round((double) $initial_payment + $sign_up_fee, wc_get_price_decimals()); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | } |
961 | 961 | |
962 | 962 | // Convert number into a price tag. |
963 | - if ( is_numeric( $initial_payment ) ) { |
|
964 | - $initial_payment = wc_price( $initial_payment ); |
|
963 | + if (is_numeric($initial_payment)) { |
|
964 | + $initial_payment = wc_price($initial_payment); |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | // Clean the price tag. |
968 | - $initial_payment = self::clean_wc_price( $initial_payment ); |
|
968 | + $initial_payment = self::clean_wc_price($initial_payment); |
|
969 | 969 | |
970 | 970 | echo $initial_payment; |
971 | 971 | |
@@ -978,11 +978,11 @@ discard block |
||
978 | 978 | * @param $product_types |
979 | 979 | * @return array |
980 | 980 | */ |
981 | - public static function support_product_types_for_wc_satt( $product_types ) { |
|
981 | + public static function support_product_types_for_wc_satt($product_types) { |
|
982 | 982 | // Only add the product types from the WooCommerce extension "Subscribe to All the Things" if it is active. |
983 | - if ( class_exists( 'WCS_ATT' ) ) { |
|
983 | + if (class_exists('WCS_ATT')) { |
|
984 | 984 | $satt_product_types = WCS_ATT()->get_supported_product_types(); |
985 | - $product_types = array_merge( $satt_product_types, $product_types ); |
|
985 | + $product_types = array_merge($satt_product_types, $product_types); |
|
986 | 986 | } |
987 | 987 | |
988 | 988 | return $product_types; |
@@ -996,10 +996,10 @@ discard block |
||
996 | 996 | * @global $woocommerce |
997 | 997 | * @return string |
998 | 998 | */ |
999 | - public static function clean_wc_price( $price ) { |
|
999 | + public static function clean_wc_price($price) { |
|
1000 | 1000 | global $woocommerce; |
1001 | 1001 | |
1002 | - if ( version_compare( $woocommerce->version, '2.6.0' ) >= 0 ) { |
|
1002 | + if (version_compare($woocommerce->version, '2.6.0') >= 0) { |
|
1003 | 1003 | |
1004 | 1004 | $find = array( |
1005 | 1005 | '<span class="woocommerce-Price-amount amount">', |
@@ -1007,8 +1007,8 @@ discard block |
||
1007 | 1007 | '</span>' |
1008 | 1008 | ); |
1009 | 1009 | |
1010 | - foreach( $find as $remove ) { |
|
1011 | - $price = str_replace( $remove, '', $price ); |
|
1010 | + foreach ($find as $remove) { |
|
1011 | + $price = str_replace($remove, '', $price); |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | } |
@@ -1024,25 +1024,25 @@ discard block |
||
1024 | 1024 | * @param int $product_id The product/post ID of the subscription |
1025 | 1025 | * @param mixed $from_date A MySQL formatted date/time string from which to calculate the expiration date (in UTC timezone), or empty (default), which will use today's date/time (in UTC timezone). |
1026 | 1026 | */ |
1027 | - public static function get_trial_expiration_date( $product_id, $from_date = '' ) { |
|
1028 | - $trial_expiration_date = WC_Subscriptions_Product::get_trial_expiration_date( $product_id, $from_date ); |
|
1027 | + public static function get_trial_expiration_date($product_id, $from_date = '') { |
|
1028 | + $trial_expiration_date = WC_Subscriptions_Product::get_trial_expiration_date($product_id, $from_date); |
|
1029 | 1029 | |
1030 | 1030 | // If returned empty then try alternative. |
1031 | - if ( empty( $trial_expiration_date ) ) { |
|
1031 | + if (empty($trial_expiration_date)) { |
|
1032 | 1032 | |
1033 | - $trial_period = self::get_subscription_trial_period( array( 'id' => $product_id, 'raw' => true ) ); |
|
1034 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_id ) ); |
|
1033 | + $trial_period = self::get_subscription_trial_period(array('id' => $product_id, 'raw' => true)); |
|
1034 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_id)); |
|
1035 | 1035 | |
1036 | - if ( $trial_length > 0 ) { |
|
1036 | + if ($trial_length > 0) { |
|
1037 | 1037 | |
1038 | - if ( empty( $from_date ) ) { |
|
1039 | - $from_date = gmdate( 'Y-m-d H:i:s' ); |
|
1038 | + if (empty($from_date)) { |
|
1039 | + $from_date = gmdate('Y-m-d H:i:s'); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | - if ( 'month' == $trial_period ) { |
|
1043 | - $trial_expiration_date = date( 'Y-m-d H:i:s', wcs_add_months( strtotime( $from_date ), $trial_length ) ); |
|
1042 | + if ('month' == $trial_period) { |
|
1043 | + $trial_expiration_date = date('Y-m-d H:i:s', wcs_add_months(strtotime($from_date), $trial_length)); |
|
1044 | 1044 | } else { // Safe to just add the billing periods |
1045 | - $trial_expiration_date = date( 'Y-m-d H:i:s', strtotime( "+ {$trial_length} {$trial_period}s", strtotime( $from_date ) ) ); |
|
1045 | + $trial_expiration_date = date('Y-m-d H:i:s', strtotime("+ {$trial_length} {$trial_period}s", strtotime($from_date))); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | } else { |