@@ -27,18 +27,18 @@ 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 support for product types that have subscription scheme options. |
35 | - add_filter( 'woocommerce_is_subscription', array( __CLASS__, 'force_is_subscription' ), 10, 3 ); |
|
35 | + add_filter('woocommerce_is_subscription', array(__CLASS__, 'force_is_subscription'), 10, 3); |
|
36 | 36 | |
37 | 37 | // Adds alternative subscription price from the WooCommerce extension "Subscribe to All the Things" and returns the lowest scheme price. |
38 | - add_action( 'woocommerce_subscriptions_shortcode_get_price', array( __CLASS__, 'get_satt_lowest_price' ), 10, 1 ); |
|
38 | + add_action('woocommerce_subscriptions_shortcode_get_price', array(__CLASS__, 'get_satt_lowest_price'), 10, 1); |
|
39 | 39 | |
40 | 40 | // Adds the product types supported from the WooCommerce extension "Subscribe to All the Things". |
41 | - add_filter( 'wcss_product_types', array( __CLASS__, 'support_product_types_for_wc_satt' ), 10, 1 ); |
|
41 | + add_filter('wcss_product_types', array(__CLASS__, 'support_product_types_for_wc_satt'), 10, 1); |
|
42 | 42 | } // END init() |
43 | 43 | |
44 | 44 | /** |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | * @return array |
50 | 50 | */ |
51 | 51 | public static function get_supported_product_types() { |
52 | - return apply_filters( 'wcss_product_types', array( |
|
52 | + return apply_filters('wcss_product_types', array( |
|
53 | 53 | 'subscription', |
54 | 54 | 'subscription-variation', |
55 | - ) ); |
|
55 | + )); |
|
56 | 56 | } // END get_supported_product_types() |
57 | 57 | |
58 | 58 | /** |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | * @param object $product |
64 | 64 | * @return bool |
65 | 65 | */ |
66 | - public static function force_is_subscription( $is_subscription, $product_id, $product ) { |
|
66 | + public static function force_is_subscription($is_subscription, $product_id, $product) { |
|
67 | 67 | /*if ( is_object( $product ) ) { |
68 | 68 | $product = $product; |
69 | 69 | } elseif ( is_numeric( $product_id ) ) { |
70 | 70 | $product = wc_get_product( $product_id ); |
71 | 71 | }*/ |
72 | 72 | |
73 | - if ( in_array( $product->product_type, self::get_supported_product_types() ) ) { |
|
74 | - if ( class_exists( 'WCS_ATT_Schemes' ) && WCS_ATT_Schemes::get_product_subscription_schemes( $product ) ) { |
|
73 | + if (in_array($product->product_type, self::get_supported_product_types())) { |
|
74 | + if (class_exists('WCS_ATT_Schemes') && WCS_ATT_Schemes::get_product_subscription_schemes($product)) { |
|
75 | 75 | $is_subscription = true; |
76 | 76 | } |
77 | 77 | } |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | * @param WC_Product $product |
86 | 86 | * @return string |
87 | 87 | */ |
88 | - public static function get_price( $product ) { |
|
89 | - if ( WC_Subscriptions_Product::get_price( $product->id ) > 0 ) { |
|
88 | + public static function get_price($product) { |
|
89 | + if (WC_Subscriptions_Product::get_price($product->id) > 0) { |
|
90 | 90 | |
91 | - return ecs_html( WC_Subscriptions_Product::get_price( $product->id, array( |
|
91 | + return ecs_html(WC_Subscriptions_Product::get_price($product->id, array( |
|
92 | 92 | 'subscription_period' => false, |
93 | 93 | 'subscription_length' => false, |
94 | 94 | 'sign_up_fee' => false, |
95 | 95 | 'trial_length' => false, |
96 | - ) ) ); |
|
96 | + ))); |
|
97 | 97 | |
98 | 98 | } else { |
99 | 99 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * |
103 | 103 | * hooked: get_satt_lowest_price - 10 |
104 | 104 | */ |
105 | - do_action( 'woocommerce_subscriptions_shortcode_get_price', $product ); |
|
105 | + do_action('woocommerce_subscriptions_shortcode_get_price', $product); |
|
106 | 106 | |
107 | 107 | } |
108 | 108 | } // END get_price() |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | * @param WC_Product $product |
115 | 115 | * @return string |
116 | 116 | */ |
117 | - public static function get_satt_lowest_scheme_data( $product ) { |
|
118 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
119 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product ); |
|
117 | + public static function get_satt_lowest_scheme_data($product) { |
|
118 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
119 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product); |
|
120 | 120 | |
121 | - return WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product, $product_level_schemes ); |
|
121 | + return WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product, $product_level_schemes); |
|
122 | 122 | } |
123 | 123 | } // END get_satt_lowest_scheme() |
124 | 124 | |
@@ -129,42 +129,42 @@ discard block |
||
129 | 129 | * @param WC_Product $product |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function get_satt_lowest_price( $product ) { |
|
133 | - $scheme = self::get_satt_lowest_scheme_data( $product ); |
|
132 | + public static function get_satt_lowest_price($product) { |
|
133 | + $scheme = self::get_satt_lowest_scheme_data($product); |
|
134 | 134 | |
135 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
135 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
136 | 136 | // Override price? |
137 | - $override = $scheme['scheme']['subscription_pricing_method']; |
|
137 | + $override = $scheme[ 'scheme' ][ 'subscription_pricing_method' ]; |
|
138 | 138 | |
139 | 139 | // Discount? |
140 | - $discount = $scheme['scheme']['subscription_discount']; |
|
140 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
141 | 141 | |
142 | 142 | // Prices |
143 | 143 | $prices = array( |
144 | - 'price' => $scheme['price'], |
|
145 | - 'regular_price' => $scheme['regular_price'], |
|
146 | - 'sale_price' => $scheme['sale_price'], |
|
147 | - 'subscription_price' => $scheme['scheme']['subscription_price'], |
|
148 | - 'subscription_regular_price' => $scheme['scheme']['subscription_regular_price'], |
|
149 | - 'subscription_sale_price' => $scheme['scheme']['subscription_sale_price'] |
|
144 | + 'price' => $scheme[ 'price' ], |
|
145 | + 'regular_price' => $scheme[ 'regular_price' ], |
|
146 | + 'sale_price' => $scheme[ 'sale_price' ], |
|
147 | + 'subscription_price' => $scheme[ 'scheme' ][ 'subscription_price' ], |
|
148 | + 'subscription_regular_price' => $scheme[ 'scheme' ][ 'subscription_regular_price' ], |
|
149 | + 'subscription_sale_price' => $scheme[ 'scheme' ][ 'subscription_sale_price' ] |
|
150 | 150 | ); |
151 | 151 | |
152 | 152 | // Prepare the price |
153 | 153 | $price = ''; |
154 | 154 | |
155 | - if ( 'inherit' == $override ) { |
|
156 | - $price = empty( $discount ) ? $price : ( empty( $prices[ 'regular_price' ] ) ? $prices[ 'regular_price' ] : round( ( double ) $prices[ 'regular_price' ] * ( 100 - $discount ) / 100, wc_get_price_decimals() ) ); |
|
157 | - } else if ( 'override' == $override ) { |
|
158 | - $price = $prices['subscription_price']; |
|
155 | + if ('inherit' == $override) { |
|
156 | + $price = empty($discount) ? $price : (empty($prices[ 'regular_price' ]) ? $prices[ 'regular_price' ] : round((double) $prices[ 'regular_price' ] * (100 - $discount) / 100, wc_get_price_decimals())); |
|
157 | + } else if ('override' == $override) { |
|
158 | + $price = $prices[ 'subscription_price' ]; |
|
159 | 159 | |
160 | - if ( $prices[ 'subscription_price' ] < $prices[ 'subscription_regular_price' ] ) { |
|
160 | + if ($prices[ 'subscription_price' ] < $prices[ 'subscription_regular_price' ]) { |
|
161 | 161 | $price = $prices[ 'subscription_sale_price' ]; |
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | 165 | // If the price is returned as an array, return just the first. |
166 | - if ( is_array( $price ) ) { |
|
167 | - $price = $price[0]; |
|
166 | + if (is_array($price)) { |
|
167 | + $price = $price[ 0 ]; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return $price; |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | * @param array $atts |
181 | 181 | * @return string |
182 | 182 | */ |
183 | - public static function get_subscription_price( $atts ) { |
|
183 | + public static function get_subscription_price($atts) { |
|
184 | 184 | global $wpdb, $post; |
185 | 185 | |
186 | - $defaults = shortcode_atts( array( |
|
186 | + $defaults = shortcode_atts(array( |
|
187 | 187 | 'id' => '', |
188 | 188 | 'sku' => '', |
189 | 189 | 'period' => false, |
@@ -192,47 +192,47 @@ discard block |
||
192 | 192 | 'trial_length' => false, |
193 | 193 | 'before_price' => '<span class="price subscription-price">', |
194 | 194 | 'after_price' => '</span>', |
195 | - ), $atts ); |
|
195 | + ), $atts); |
|
196 | 196 | |
197 | - $atts = wp_parse_args( $atts, $defaults ); |
|
197 | + $atts = wp_parse_args($atts, $defaults); |
|
198 | 198 | |
199 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
200 | - $product_data = wc_get_product( $atts['id'] ); |
|
201 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
202 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
203 | - $product_data = get_post( $product_id ); |
|
199 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
200 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
201 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
202 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
203 | + $product_data = get_post($product_id); |
|
204 | 204 | } else { |
205 | - $product_data = wc_get_product( $post->ID ); |
|
205 | + $product_data = wc_get_product($post->ID); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | // Check that the product type is supported. Return blank if not supported. |
209 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
209 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
210 | 210 | return ''; |
211 | 211 | } |
212 | 212 | |
213 | 213 | ob_start(); |
214 | 214 | |
215 | - $price_html = WC_Subscriptions_Product::get_price_string( $product_data->id, array( |
|
216 | - 'price' => self::get_price( $product_data ), |
|
217 | - 'subscription_period' => isset( $atts['period'] ) ? $atts['period'] : true, |
|
218 | - 'subscription_length' => isset( $atts['length'] ) ? $atts['length'] : true, |
|
219 | - 'sign_up_fee' => isset( $atts['sign_up_fee'] ) ? $atts['sign_up_fee'] : true, |
|
220 | - 'trial_length' => isset( $atts['trial_length'] ) ? $atts['trial_length'] : true, |
|
221 | - ) ); |
|
215 | + $price_html = WC_Subscriptions_Product::get_price_string($product_data->id, array( |
|
216 | + 'price' => self::get_price($product_data), |
|
217 | + 'subscription_period' => isset($atts[ 'period' ]) ? $atts[ 'period' ] : true, |
|
218 | + 'subscription_length' => isset($atts[ 'length' ]) ? $atts[ 'length' ] : true, |
|
219 | + 'sign_up_fee' => isset($atts[ 'sign_up_fee' ]) ? $atts[ 'sign_up_fee' ] : true, |
|
220 | + 'trial_length' => isset($atts[ 'trial_length' ]) ? $atts[ 'trial_length' ] : true, |
|
221 | + )); |
|
222 | 222 | |
223 | 223 | // Clean the subscription price wrapper. |
224 | 224 | $price_html = str_replace('<span class="subscription-details">', '', $price_html); |
225 | 225 | $price_html = str_replace('</span">', '', $price_html); |
226 | 226 | |
227 | 227 | // Trim the whitespace. |
228 | - $price_html = trim( $price_html ); |
|
228 | + $price_html = trim($price_html); |
|
229 | 229 | |
230 | 230 | // Convert to Price Tag. |
231 | - $price_html = wc_price( $price_html ); |
|
231 | + $price_html = wc_price($price_html); |
|
232 | 232 | |
233 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $price_html, $atts['after_price'] ); |
|
233 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $price_html, $atts[ 'after_price' ]); |
|
234 | 234 | |
235 | - echo html_entity_decode( $price_html ); |
|
235 | + echo html_entity_decode($price_html); |
|
236 | 236 | |
237 | 237 | return ob_get_clean(); |
238 | 238 | } // END get_subscription_price() |
@@ -245,72 +245,72 @@ discard block |
||
245 | 245 | * @param array $atts |
246 | 246 | * @return string |
247 | 247 | */ |
248 | - public static function get_subscription_price_meta( $atts ) { |
|
248 | + public static function get_subscription_price_meta($atts) { |
|
249 | 249 | global $wpdb, $post; |
250 | 250 | |
251 | - $defaults = shortcode_atts( array( |
|
251 | + $defaults = shortcode_atts(array( |
|
252 | 252 | 'id' => '', |
253 | 253 | 'sku' => '', |
254 | 254 | 'meta' => 'both', |
255 | 255 | 'before_price' => '', |
256 | 256 | 'after_price' => '', |
257 | - ), $atts ); |
|
257 | + ), $atts); |
|
258 | 258 | |
259 | - $atts = wp_parse_args( $atts, $defaults ); |
|
259 | + $atts = wp_parse_args($atts, $defaults); |
|
260 | 260 | |
261 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
262 | - $product_data = wc_get_product( $atts['id'] ); |
|
263 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
264 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
265 | - $product_data = get_post( $product_id ); |
|
261 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
262 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
263 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
264 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
265 | + $product_data = get_post($product_id); |
|
266 | 266 | } else { |
267 | - $product_data = wc_get_product( $post->ID ); |
|
267 | + $product_data = wc_get_product($post->ID); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | // Check that the product type is supported. Return blank if not supported. |
271 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
271 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
272 | 272 | return ''; |
273 | 273 | } |
274 | 274 | |
275 | 275 | ob_start(); |
276 | 276 | |
277 | - $price = WC_Subscriptions_Product::get_price( $product_data->id ); |
|
277 | + $price = WC_Subscriptions_Product::get_price($product_data->id); |
|
278 | 278 | |
279 | 279 | // Remove the subscription price wrapper. |
280 | 280 | $price_html = str_replace('<span class="subscription-details">', '', $price); |
281 | 281 | $price = str_replace('</span">', '', $price_html); |
282 | 282 | |
283 | 283 | // If the subscription product has no price, then look for alternative. |
284 | - if ( empty( $price ) ) { |
|
285 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
284 | + if (empty($price)) { |
|
285 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
286 | 286 | |
287 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
287 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
288 | 288 | |
289 | 289 | $prices = array( |
290 | - 'price' => $scheme['price'], |
|
291 | - 'regular_price' => $scheme['regular_price'], |
|
292 | - 'sale_price' => $scheme['sale_price'], |
|
293 | - 'method' => $scheme['scheme']['subscription_pricing_method'], |
|
294 | - 'subscription_price' => $scheme['scheme']['subscription_price'], |
|
295 | - 'subscription_regular_price' => $scheme['scheme']['subscription_regular_price'], |
|
296 | - 'subscription_sale_price' => $scheme['scheme']['subscription_sale_price'] |
|
290 | + 'price' => $scheme[ 'price' ], |
|
291 | + 'regular_price' => $scheme[ 'regular_price' ], |
|
292 | + 'sale_price' => $scheme[ 'sale_price' ], |
|
293 | + 'method' => $scheme[ 'scheme' ][ 'subscription_pricing_method' ], |
|
294 | + 'subscription_price' => $scheme[ 'scheme' ][ 'subscription_price' ], |
|
295 | + 'subscription_regular_price' => $scheme[ 'scheme' ][ 'subscription_regular_price' ], |
|
296 | + 'subscription_sale_price' => $scheme[ 'scheme' ][ 'subscription_sale_price' ] |
|
297 | 297 | ); |
298 | 298 | |
299 | 299 | // Return the subscription price based on the pricing method. |
300 | - switch( $prices['method'] ) { |
|
300 | + switch ($prices[ 'method' ]) { |
|
301 | 301 | case 'override': |
302 | - $price = $prices['subscription_price']; |
|
303 | - $regular_price = $prices['subscription_regular_price']; |
|
304 | - $sale_price = $prices['subscription_sale_price']; |
|
302 | + $price = $prices[ 'subscription_price' ]; |
|
303 | + $regular_price = $prices[ 'subscription_regular_price' ]; |
|
304 | + $sale_price = $prices[ 'subscription_sale_price' ]; |
|
305 | 305 | break; |
306 | 306 | case 'inherit': |
307 | - $discount = $scheme['scheme']['subscription_discount']; |
|
308 | - $price = $prices['price']; |
|
309 | - $regular_price = $prices['regular_price']; |
|
310 | - $sale_price = $prices['sale_price']; |
|
307 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
308 | + $price = $prices[ 'price' ]; |
|
309 | + $regular_price = $prices[ 'regular_price' ]; |
|
310 | + $sale_price = $prices[ 'sale_price' ]; |
|
311 | 311 | |
312 | - if ( !empty( $discount ) && $discount > 0 ) { |
|
313 | - $sale_price = round( ( double ) $regular_price * ( 100 - $discount ) / 100, wc_get_price_decimals() ); |
|
312 | + if ( ! empty($discount) && $discount > 0) { |
|
313 | + $sale_price = round((double) $regular_price * (100 - $discount) / 100, wc_get_price_decimals()); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | break; |
@@ -318,39 +318,39 @@ discard block |
||
318 | 318 | |
319 | 319 | // Display both the regular price striked out and the sale price |
320 | 320 | // should the active price be less than the regular price. |
321 | - if ( $atts['meta'] != 'active' && !empty( $sale_price ) && $price < $regular_price ) { |
|
322 | - $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>'; |
|
321 | + if ($atts[ 'meta' ] != 'active' && ! empty($sale_price) && $price < $regular_price) { |
|
322 | + $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>'; |
|
323 | 323 | |
324 | 324 | // Trim the whitespace. |
325 | - $price = trim( $price ); |
|
325 | + $price = trim($price); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Override the value should only one value be returned. |
329 | - if ( $atts['meta'] != 'both' ) { |
|
330 | - if ( $atts['meta'] == 'active' ) { |
|
329 | + if ($atts[ 'meta' ] != 'both') { |
|
330 | + if ($atts[ 'meta' ] == 'active') { |
|
331 | 331 | $price = $price; |
332 | 332 | } |
333 | 333 | |
334 | - if ( $atts['meta'] == 'regular' ) { |
|
334 | + if ($atts[ 'meta' ] == 'regular') { |
|
335 | 335 | $price = $regular_price; |
336 | 336 | } |
337 | 337 | |
338 | - if ( $atts['meta'] == 'sale' ) { |
|
338 | + if ($atts[ 'meta' ] == 'sale') { |
|
339 | 339 | $price = $sale_price; |
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
343 | - if ( is_numeric( $price ) ) { |
|
344 | - $price = wc_price( $price ); |
|
343 | + if (is_numeric($price)) { |
|
344 | + $price = wc_price($price); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | } |
348 | 348 | |
349 | 349 | } |
350 | 350 | |
351 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $price, $atts['after_price'] ); |
|
351 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $price, $atts[ 'after_price' ]); |
|
352 | 352 | |
353 | - echo html_entity_decode( $price_html ); |
|
353 | + echo html_entity_decode($price_html); |
|
354 | 354 | |
355 | 355 | return ob_get_clean(); |
356 | 356 | } // END get_subscription_price_meta() |
@@ -363,27 +363,27 @@ discard block |
||
363 | 363 | * @param array $atts |
364 | 364 | * @return string |
365 | 365 | */ |
366 | - public static function get_subscription_discount( $atts ) { |
|
366 | + public static function get_subscription_discount($atts) { |
|
367 | 367 | global $wpdb, $post; |
368 | 368 | |
369 | - $defaults = shortcode_atts( array( |
|
369 | + $defaults = shortcode_atts(array( |
|
370 | 370 | 'id' => '', |
371 | 371 | 'sku' => '', |
372 | - ), $atts ); |
|
372 | + ), $atts); |
|
373 | 373 | |
374 | - $atts = wp_parse_args( $atts, $defaults ); |
|
374 | + $atts = wp_parse_args($atts, $defaults); |
|
375 | 375 | |
376 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
377 | - $product_data = wc_get_product( $atts['id'] ); |
|
378 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
379 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
380 | - $product_data = get_post( $product_id ); |
|
376 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
377 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
378 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
379 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
380 | + $product_data = get_post($product_id); |
|
381 | 381 | } else { |
382 | - $product_data = wc_get_product( $post->ID ); |
|
382 | + $product_data = wc_get_product($post->ID); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | // Check that the product type is supported. Return blank if not supported. |
386 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
386 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
387 | 387 | return ''; |
388 | 388 | } |
389 | 389 | |
@@ -392,18 +392,18 @@ discard block |
||
392 | 392 | $discount = ''; // Returns empty by default. |
393 | 393 | |
394 | 394 | // Get Subscription Discount - Only available with the WooCommerce extension "Subscribe to All the Things". |
395 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
395 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
396 | 396 | |
397 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
397 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
398 | 398 | // Override price? |
399 | - $override = $scheme['scheme']['subscription_pricing_method']; |
|
399 | + $override = $scheme[ 'scheme' ][ 'subscription_pricing_method' ]; |
|
400 | 400 | |
401 | 401 | // Discount ? |
402 | - $discount = $scheme['scheme']['subscription_discount']; |
|
402 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
403 | 403 | } |
404 | 404 | |
405 | - if ( ! empty( $discount ) && is_numeric( $discount ) && $override == 'inherit' ) { |
|
406 | - $discount = sprintf( __( '%s%s %s', WCSS::TEXT_DOMAIN ), $discount, '%', apply_filters( 'wcs_shortcodes_sub_discount_string', __( 'discount', WCSS::TEXT_DOMAIN ) ) ); |
|
405 | + if ( ! empty($discount) && is_numeric($discount) && $override == 'inherit') { |
|
406 | + $discount = sprintf(__('%s%s %s', WCSS::TEXT_DOMAIN), $discount, '%', apply_filters('wcs_shortcodes_sub_discount_string', __('discount', WCSS::TEXT_DOMAIN))); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | echo $discount; |
@@ -417,47 +417,47 @@ discard block |
||
417 | 417 | * @param array $atts |
418 | 418 | * @return string |
419 | 419 | */ |
420 | - public static function get_subscription_period( $atts ) { |
|
420 | + public static function get_subscription_period($atts) { |
|
421 | 421 | global $wpdb, $post; |
422 | 422 | |
423 | - $defaults = shortcode_atts( array( |
|
423 | + $defaults = shortcode_atts(array( |
|
424 | 424 | 'id' => '', |
425 | 425 | 'sku' => '', |
426 | 426 | 'raw' => false |
427 | - ), $atts ); |
|
427 | + ), $atts); |
|
428 | 428 | |
429 | - $atts = wp_parse_args( $atts, $defaults ); |
|
429 | + $atts = wp_parse_args($atts, $defaults); |
|
430 | 430 | |
431 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
432 | - $product_data = wc_get_product( $atts['id'] ); |
|
433 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
434 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
435 | - $product_data = get_post( $product_id ); |
|
431 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
432 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
433 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
434 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
435 | + $product_data = get_post($product_id); |
|
436 | 436 | } else { |
437 | - $product_data = wc_get_product( $post->ID ); |
|
437 | + $product_data = wc_get_product($post->ID); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | // Check that the product type is supported. Return blank if not supported. |
441 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
441 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
442 | 442 | return ''; |
443 | 443 | } |
444 | 444 | |
445 | 445 | ob_start(); |
446 | 446 | |
447 | 447 | // Get Subscription Period |
448 | - $period = WC_Subscriptions_Product::get_period( $product_data ); |
|
448 | + $period = WC_Subscriptions_Product::get_period($product_data); |
|
449 | 449 | |
450 | 450 | // If the period is empty, look for alternative. |
451 | - if ( empty( $period ) ) { |
|
452 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
451 | + if (empty($period)) { |
|
452 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
453 | 453 | |
454 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
455 | - $period = $scheme['scheme']['subscription_period']; |
|
454 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
455 | + $period = $scheme[ 'scheme' ][ 'subscription_period' ]; |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
459 | - if ( ! $atts['raw'] ) { |
|
460 | - $period = sprintf( __( 'Per %s', WCSS::TEXT_DOMAIN ), $period ); |
|
459 | + if ( ! $atts[ 'raw' ]) { |
|
460 | + $period = sprintf(__('Per %s', WCSS::TEXT_DOMAIN), $period); |
|
461 | 461 | $period = ucwords($period); |
462 | 462 | } |
463 | 463 | |
@@ -472,41 +472,41 @@ discard block |
||
472 | 472 | * @param array $atts |
473 | 473 | * @return string |
474 | 474 | */ |
475 | - public static function get_subscription_period_interval( $atts ) { |
|
475 | + public static function get_subscription_period_interval($atts) { |
|
476 | 476 | global $wpdb, $post; |
477 | 477 | |
478 | - $defaults = shortcode_atts( array( |
|
478 | + $defaults = shortcode_atts(array( |
|
479 | 479 | 'id' => '', |
480 | 480 | 'sku' => '', |
481 | - ), $atts ); |
|
481 | + ), $atts); |
|
482 | 482 | |
483 | - $atts = wp_parse_args( $atts, $defaults ); |
|
483 | + $atts = wp_parse_args($atts, $defaults); |
|
484 | 484 | |
485 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
486 | - $product_data = wc_get_product( $atts['id'] ); |
|
487 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
488 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
489 | - $product_data = get_post( $product_id ); |
|
485 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
486 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
487 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
488 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
489 | + $product_data = get_post($product_id); |
|
490 | 490 | } else { |
491 | - $product_data = wc_get_product( $post->ID ); |
|
491 | + $product_data = wc_get_product($post->ID); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | // Check that the product type is supported. Return blank if not supported. |
495 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
495 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
496 | 496 | return ''; |
497 | 497 | } |
498 | 498 | |
499 | 499 | ob_start(); |
500 | 500 | |
501 | 501 | // Get Subscription Period Interval |
502 | - $period_interval = WC_Subscriptions_Product::get_interval( $product_data ); |
|
502 | + $period_interval = WC_Subscriptions_Product::get_interval($product_data); |
|
503 | 503 | |
504 | 504 | // If the period is empty, look for alternative. |
505 | - if ( empty( $period_interval ) ) { |
|
506 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
505 | + if (empty($period_interval)) { |
|
506 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
507 | 507 | |
508 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
509 | - $period_interval = $scheme['scheme']['subscription_period_interval']; |
|
508 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
509 | + $period_interval = $scheme[ 'scheme' ][ 'subscription_period_interval' ]; |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
@@ -521,52 +521,52 @@ discard block |
||
521 | 521 | * @param array $atts |
522 | 522 | * @return string |
523 | 523 | */ |
524 | - public static function get_subscription_length( $atts ) { |
|
524 | + public static function get_subscription_length($atts) { |
|
525 | 525 | global $wpdb, $post; |
526 | 526 | |
527 | - $defaults = shortcode_atts( array( |
|
527 | + $defaults = shortcode_atts(array( |
|
528 | 528 | 'id' => '', |
529 | 529 | 'sku' => '', |
530 | 530 | 'raw' => false, |
531 | - ), $atts ); |
|
531 | + ), $atts); |
|
532 | 532 | |
533 | - $atts = wp_parse_args( $atts, $defaults ); |
|
533 | + $atts = wp_parse_args($atts, $defaults); |
|
534 | 534 | |
535 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
536 | - $product_data = wc_get_product( $atts['id'] ); |
|
537 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
538 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
539 | - $product_data = get_post( $product_id ); |
|
535 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
536 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
537 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
538 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
539 | + $product_data = get_post($product_id); |
|
540 | 540 | } else { |
541 | - $product_data = wc_get_product( $post->ID ); |
|
541 | + $product_data = wc_get_product($post->ID); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | // Check that the product type is supported. Return blank if not supported. |
545 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
545 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
546 | 546 | return ''; |
547 | 547 | } |
548 | 548 | |
549 | 549 | ob_start(); |
550 | 550 | |
551 | 551 | // Get Subscription Length |
552 | - $length = WC_Subscriptions_Product::get_length( $product_data ); |
|
552 | + $length = WC_Subscriptions_Product::get_length($product_data); |
|
553 | 553 | |
554 | 554 | // If the length is empty, look for alternative. |
555 | - if ( empty( $length ) ) { |
|
556 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
555 | + if (empty($length)) { |
|
556 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
557 | 557 | |
558 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
558 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
559 | 559 | |
560 | - $period = self::get_subscription_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
561 | - $length = $scheme['scheme']['subscription_length']; |
|
560 | + $period = self::get_subscription_period(array('id' => $product_data->id, 'raw' => true)); |
|
561 | + $length = $scheme[ 'scheme' ][ 'subscription_length' ]; |
|
562 | 562 | |
563 | 563 | // If we are not returning raw data then making it readable for humans. |
564 | - if ( ! $atts['raw'] ) { |
|
564 | + if ( ! $atts[ 'raw' ]) { |
|
565 | 565 | |
566 | - if ( $length > 0 ) { |
|
567 | - $length = sprintf( '%s %s', $length, $period ); |
|
566 | + if ($length > 0) { |
|
567 | + $length = sprintf('%s %s', $length, $period); |
|
568 | 568 | } else { |
569 | - $length = sprintf( __( 'Every %s', WCSS::TEXT_DOMAIN ), $period ); |
|
569 | + $length = sprintf(__('Every %s', WCSS::TEXT_DOMAIN), $period); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | $length = ucfirst($length); |
@@ -588,56 +588,56 @@ discard block |
||
588 | 588 | * @param array $atts |
589 | 589 | * @return string |
590 | 590 | */ |
591 | - public static function get_subscription_sign_up_fee( $atts ) { |
|
591 | + public static function get_subscription_sign_up_fee($atts) { |
|
592 | 592 | global $wpdb, $post; |
593 | 593 | |
594 | - $defaults = shortcode_atts( array( |
|
594 | + $defaults = shortcode_atts(array( |
|
595 | 595 | 'id' => '', |
596 | 596 | 'sku' => '', |
597 | 597 | 'raw' => false, |
598 | 598 | 'before_price' => '', |
599 | 599 | 'after_price' => '', |
600 | - ), $atts ); |
|
600 | + ), $atts); |
|
601 | 601 | |
602 | - $atts = wp_parse_args( $atts, $defaults ); |
|
602 | + $atts = wp_parse_args($atts, $defaults); |
|
603 | 603 | |
604 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
605 | - $product_data = wc_get_product( $atts['id'] ); |
|
606 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
607 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
608 | - $product_data = get_post( $product_id ); |
|
604 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
605 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
606 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
607 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
608 | + $product_data = get_post($product_id); |
|
609 | 609 | } else { |
610 | - $product_data = wc_get_product( $post->ID ); |
|
610 | + $product_data = wc_get_product($post->ID); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | // Check that the product type is supported. Return blank if not supported. |
614 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
614 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
615 | 615 | return ''; |
616 | 616 | } |
617 | 617 | |
618 | 618 | ob_start(); |
619 | 619 | |
620 | 620 | // Get Subscription Sign Up Fee |
621 | - $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product_data ); |
|
621 | + $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product_data); |
|
622 | 622 | |
623 | 623 | // If the sign up fee is empty, look for alternative. |
624 | - if ( empty( $sign_up_fee ) ) { |
|
625 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
624 | + if (empty($sign_up_fee)) { |
|
625 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
626 | 626 | |
627 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
628 | - $sign_up_fee = $scheme['scheme']['subscription_sign_up_fee']; |
|
627 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
628 | + $sign_up_fee = $scheme[ 'scheme' ][ 'subscription_sign_up_fee' ]; |
|
629 | 629 | } |
630 | 630 | } |
631 | 631 | |
632 | - if ( ! $atts['raw'] ) { |
|
632 | + if ( ! $atts[ 'raw' ]) { |
|
633 | 633 | // Convert number into a price tag. |
634 | - if ( is_numeric( $sign_up_fee ) ) { |
|
635 | - $sign_up_fee = wc_price( $sign_up_fee ); |
|
634 | + if (is_numeric($sign_up_fee)) { |
|
635 | + $sign_up_fee = wc_price($sign_up_fee); |
|
636 | 636 | } |
637 | 637 | |
638 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $sign_up_fee, $atts['after_price'] ); |
|
638 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $sign_up_fee, $atts[ 'after_price' ]); |
|
639 | 639 | |
640 | - $sign_up_fee = html_entity_decode( $price_html ); |
|
640 | + $sign_up_fee = html_entity_decode($price_html); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | echo $sign_up_fee; |
@@ -651,55 +651,55 @@ discard block |
||
651 | 651 | * @param array $atts |
652 | 652 | * @return string |
653 | 653 | */ |
654 | - public static function get_subscription_trial_string( $atts ) { |
|
654 | + public static function get_subscription_trial_string($atts) { |
|
655 | 655 | global $wpdb, $post; |
656 | 656 | |
657 | - $defaults = shortcode_atts( array( |
|
657 | + $defaults = shortcode_atts(array( |
|
658 | 658 | 'id' => '', |
659 | 659 | 'sku' => '', |
660 | - ), $atts ); |
|
660 | + ), $atts); |
|
661 | 661 | |
662 | - $atts = wp_parse_args( $atts, $defaults ); |
|
662 | + $atts = wp_parse_args($atts, $defaults); |
|
663 | 663 | |
664 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
665 | - $product_data = wc_get_product( $atts['id'] ); |
|
666 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
667 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
668 | - $product_data = get_post( $product_id ); |
|
664 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
665 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
666 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
667 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
668 | + $product_data = get_post($product_id); |
|
669 | 669 | } else { |
670 | - $product_data = wc_get_product( $post->ID ); |
|
670 | + $product_data = wc_get_product($post->ID); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | // Check that the product type is supported. Return blank if not supported. |
674 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
674 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
675 | 675 | return ''; |
676 | 676 | } |
677 | 677 | |
678 | 678 | ob_start(); |
679 | 679 | |
680 | 680 | // Get Subscription Trial Length |
681 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
681 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
682 | 682 | |
683 | 683 | // Get Subscription Trial Period |
684 | - $trial_period = self::get_subscription_trial_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
684 | + $trial_period = self::get_subscription_trial_period(array('id' => $product_data->id, 'raw' => true)); |
|
685 | 685 | |
686 | - if ( ! empty( $trial_length ) && $trial_length > 0 ) { |
|
686 | + if ( ! empty($trial_length) && $trial_length > 0) { |
|
687 | 687 | |
688 | - switch ( $trial_period ) { |
|
688 | + switch ($trial_period) { |
|
689 | 689 | case 'day': |
690 | - echo sprintf( _n( '%s day', '%s days', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
690 | + echo sprintf(_n('%s day', '%s days', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
691 | 691 | break; |
692 | 692 | |
693 | 693 | case 'week': |
694 | - echo sprintf( _n( '%s week', '%s weeks', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
694 | + echo sprintf(_n('%s week', '%s weeks', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
695 | 695 | break; |
696 | 696 | |
697 | 697 | case 'month': |
698 | - echo sprintf( _n( '%s month', '%s months', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
698 | + echo sprintf(_n('%s month', '%s months', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
699 | 699 | break; |
700 | 700 | |
701 | 701 | case 'year': |
702 | - echo sprintf( _n( '%s year', '%s years', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
702 | + echo sprintf(_n('%s year', '%s years', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
703 | 703 | break; |
704 | 704 | } |
705 | 705 | |
@@ -714,41 +714,41 @@ discard block |
||
714 | 714 | * @param array $atts |
715 | 715 | * @return string |
716 | 716 | */ |
717 | - public static function get_subscription_trial_length( $atts ) { |
|
717 | + public static function get_subscription_trial_length($atts) { |
|
718 | 718 | global $wpdb, $post; |
719 | 719 | |
720 | - $defaults = shortcode_atts( array( |
|
720 | + $defaults = shortcode_atts(array( |
|
721 | 721 | 'id' => '', |
722 | 722 | 'sku' => '', |
723 | - ), $atts ); |
|
723 | + ), $atts); |
|
724 | 724 | |
725 | - $atts = wp_parse_args( $atts, $defaults ); |
|
725 | + $atts = wp_parse_args($atts, $defaults); |
|
726 | 726 | |
727 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
728 | - $product_data = wc_get_product( $atts['id'] ); |
|
729 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
730 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
731 | - $product_data = get_post( $product_id ); |
|
727 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
728 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
729 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
730 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
731 | + $product_data = get_post($product_id); |
|
732 | 732 | } else { |
733 | - $product_data = wc_get_product( $post->ID ); |
|
733 | + $product_data = wc_get_product($post->ID); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | // Check that the product type is supported. Return blank if not supported. |
737 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
737 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
738 | 738 | return ''; |
739 | 739 | } |
740 | 740 | |
741 | 741 | ob_start(); |
742 | 742 | |
743 | 743 | // Get Subscription Trial Length |
744 | - $trial_length = WC_Subscriptions_Product::get_trial_length( $product_data ); |
|
744 | + $trial_length = WC_Subscriptions_Product::get_trial_length($product_data); |
|
745 | 745 | |
746 | 746 | // If the trial length is empty, look for alternative. |
747 | - if ( empty( $trial_length ) ) { |
|
748 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
747 | + if (empty($trial_length)) { |
|
748 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
749 | 749 | |
750 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
751 | - $trial_length = $scheme['scheme']['subscription_trial_length']; |
|
750 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
751 | + $trial_length = $scheme[ 'scheme' ][ 'subscription_trial_length' ]; |
|
752 | 752 | } |
753 | 753 | } |
754 | 754 | |
@@ -763,52 +763,52 @@ discard block |
||
763 | 763 | * @param array $atts |
764 | 764 | * @return string |
765 | 765 | */ |
766 | - public static function get_subscription_trial_period( $atts ) { |
|
766 | + public static function get_subscription_trial_period($atts) { |
|
767 | 767 | global $wpdb, $post; |
768 | 768 | |
769 | - $defaults = shortcode_atts( array( |
|
769 | + $defaults = shortcode_atts(array( |
|
770 | 770 | 'id' => '', |
771 | 771 | 'sku' => '', |
772 | 772 | 'raw' => false, |
773 | - ), $atts ); |
|
773 | + ), $atts); |
|
774 | 774 | |
775 | - $atts = wp_parse_args( $atts, $defaults ); |
|
775 | + $atts = wp_parse_args($atts, $defaults); |
|
776 | 776 | |
777 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
778 | - $product_data = wc_get_product( $atts['id'] ); |
|
779 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
780 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
781 | - $product_data = get_post( $product_id ); |
|
777 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
778 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
779 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
780 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
781 | + $product_data = get_post($product_id); |
|
782 | 782 | } else { |
783 | - $product_data = wc_get_product( $post->ID ); |
|
783 | + $product_data = wc_get_product($post->ID); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | // Check that the product type is supported. Return blank if not supported. |
787 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
787 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
788 | 788 | return ''; |
789 | 789 | } |
790 | 790 | |
791 | 791 | ob_start(); |
792 | 792 | |
793 | 793 | // Get Subscription Trial Length |
794 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
794 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
795 | 795 | |
796 | 796 | // Get Subscription Trial Period |
797 | - $trial_period = WC_Subscriptions_Product::get_trial_period( $product_data ); |
|
797 | + $trial_period = WC_Subscriptions_Product::get_trial_period($product_data); |
|
798 | 798 | |
799 | 799 | // If the trial length is empty or is not zero, look for alternative. |
800 | - if ( empty( $trial_length ) || $trial_length != 0 ) { |
|
801 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
800 | + if (empty($trial_length) || $trial_length != 0) { |
|
801 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
802 | 802 | |
803 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
804 | - $trial_length = $scheme['scheme']['subscription_trial_length']; |
|
805 | - $trial_period = $scheme['scheme']['subscription_trial_period']; |
|
803 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
804 | + $trial_length = $scheme[ 'scheme' ][ 'subscription_trial_length' ]; |
|
805 | + $trial_period = $scheme[ 'scheme' ][ 'subscription_trial_period' ]; |
|
806 | 806 | } |
807 | 807 | } |
808 | 808 | |
809 | - if ( ! empty( $trial_length ) && $trial_length > 0 ) { |
|
809 | + if ( ! empty($trial_length) && $trial_length > 0) { |
|
810 | 810 | |
811 | - if ( ! $atts['raw'] ) { |
|
811 | + if ( ! $atts[ 'raw' ]) { |
|
812 | 812 | $trial_period = ucfirst($trial_period); |
813 | 813 | } |
814 | 814 | |
@@ -825,84 +825,84 @@ discard block |
||
825 | 825 | * @param array $atts |
826 | 826 | * @return string |
827 | 827 | */ |
828 | - public static function get_subscription_first_payment( $atts ) { |
|
828 | + public static function get_subscription_first_payment($atts) { |
|
829 | 829 | global $wpdb, $post; |
830 | 830 | |
831 | - $defaults = shortcode_atts( array( |
|
831 | + $defaults = shortcode_atts(array( |
|
832 | 832 | 'id' => '', |
833 | 833 | 'sku' => '', |
834 | 834 | 'show_time' => false, |
835 | 835 | 'from_date' => '', |
836 | 836 | 'timezone' => 'gmt', |
837 | 837 | 'format' => 'timestamp' |
838 | - ), $atts ); |
|
838 | + ), $atts); |
|
839 | 839 | |
840 | - $atts = wp_parse_args( $atts, $defaults ); |
|
840 | + $atts = wp_parse_args($atts, $defaults); |
|
841 | 841 | |
842 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
843 | - $product_data = wc_get_product( $atts['id'] ); |
|
844 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
845 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
846 | - $product_data = get_post( $product_id ); |
|
842 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
843 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
844 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
845 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
846 | + $product_data = get_post($product_id); |
|
847 | 847 | } else { |
848 | - $product_data = wc_get_product( $post->ID ); |
|
848 | + $product_data = wc_get_product($post->ID); |
|
849 | 849 | } |
850 | 850 | |
851 | 851 | // Check that the product type is supported. Return blank if not supported. |
852 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
852 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
853 | 853 | return ''; |
854 | 854 | } |
855 | 855 | |
856 | 856 | ob_start(); |
857 | 857 | |
858 | - $billing_interval = self::get_subscription_period_interval( array( 'id' => $product_data->id ) ); |
|
859 | - $billing_length = self::get_subscription_length( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
860 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
858 | + $billing_interval = self::get_subscription_period_interval(array('id' => $product_data->id)); |
|
859 | + $billing_length = self::get_subscription_length(array('id' => $product_data->id, 'raw' => true)); |
|
860 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
861 | 861 | |
862 | - $from_date = $atts['from_date']; |
|
862 | + $from_date = $atts[ 'from_date' ]; |
|
863 | 863 | |
864 | - if ( $billing_interval != $billing_length || $trial_length > 0 ) { |
|
865 | - if ( empty( $from_date ) ) { |
|
866 | - $from_date = gmdate( 'Y-m-d H:i:s' ); |
|
864 | + if ($billing_interval != $billing_length || $trial_length > 0) { |
|
865 | + if (empty($from_date)) { |
|
866 | + $from_date = gmdate('Y-m-d H:i:s'); |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | // If the subscription has a free trial period, the first renewal is the same as the expiration of the free trial |
870 | - if ( $trial_length > 0 ) { |
|
871 | - $first_renewal_timestamp = strtotime( WC_Subscriptions_Product::get_trial_expiration_date( $product_data->id, $from_date ) ); |
|
870 | + if ($trial_length > 0) { |
|
871 | + $first_renewal_timestamp = strtotime(WC_Subscriptions_Product::get_trial_expiration_date($product_data->id, $from_date)); |
|
872 | 872 | } else { |
873 | - $from_timestamp = strtotime( $from_date ); |
|
874 | - $billing_period = self::get_subscription_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
873 | + $from_timestamp = strtotime($from_date); |
|
874 | + $billing_period = self::get_subscription_period(array('id' => $product_data->id, 'raw' => true)); |
|
875 | 875 | |
876 | - if ( 'month' == $billing_period ) { |
|
877 | - $first_renewal_timestamp = wcs_add_months( $from_timestamp, $billing_interval ); |
|
876 | + if ('month' == $billing_period) { |
|
877 | + $first_renewal_timestamp = wcs_add_months($from_timestamp, $billing_interval); |
|
878 | 878 | } else { |
879 | - $first_renewal_timestamp = strtotime( "+ $billing_interval {$billing_period}s", $from_timestamp ); |
|
879 | + $first_renewal_timestamp = strtotime("+ $billing_interval {$billing_period}s", $from_timestamp); |
|
880 | 880 | } |
881 | 881 | |
882 | - if ( 'site' == $atts['timezone'] ) { |
|
883 | - $first_renewal_timestamp += ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
882 | + if ('site' == $atts[ 'timezone' ]) { |
|
883 | + $first_renewal_timestamp += (get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
884 | 884 | } |
885 | 885 | } |
886 | 886 | } else { |
887 | 887 | $first_renewal_timestamp = 0; |
888 | 888 | } |
889 | 889 | |
890 | - if ( $first_renewal_timestamp > 0 ) { |
|
891 | - if ( $atts['show_time'] ) { |
|
892 | - if ( 'timestamp' == $atts['format'] ) { |
|
890 | + if ($first_renewal_timestamp > 0) { |
|
891 | + if ($atts[ 'show_time' ]) { |
|
892 | + if ('timestamp' == $atts[ 'format' ]) { |
|
893 | 893 | $date_format = 'Y-m-d H:i:s'; |
894 | - } else if ( 'string' == $atts['format'] ) { |
|
894 | + } else if ('string' == $atts[ 'format' ]) { |
|
895 | 895 | $date_format = 'D jS M Y H:i A'; |
896 | 896 | } |
897 | 897 | } else { |
898 | - if ( 'timestamp' == $atts['format'] ) { |
|
898 | + if ('timestamp' == $atts[ 'format' ]) { |
|
899 | 899 | $date_format = 'Y-m-d'; |
900 | - } else if ( 'string' == $atts['format'] ) { |
|
900 | + } else if ('string' == $atts[ 'format' ]) { |
|
901 | 901 | $date_format = 'D jS M Y'; |
902 | 902 | } |
903 | 903 | } |
904 | 904 | |
905 | - $first_payment = date( $date_format, $first_renewal_timestamp ); |
|
905 | + $first_payment = date($date_format, $first_renewal_timestamp); |
|
906 | 906 | } else { |
907 | 907 | $first_payment = ''; |
908 | 908 | } |
@@ -918,61 +918,61 @@ discard block |
||
918 | 918 | * @param array $atts |
919 | 919 | * @return string |
920 | 920 | */ |
921 | - public static function get_subscription_initial( $atts ) { |
|
921 | + public static function get_subscription_initial($atts) { |
|
922 | 922 | global $wpdb, $post; |
923 | 923 | |
924 | - $defaults = shortcode_atts( array( |
|
924 | + $defaults = shortcode_atts(array( |
|
925 | 925 | 'id' => '', |
926 | 926 | 'sku' => '', |
927 | 927 | 'total' => false |
928 | - ), $atts ); |
|
928 | + ), $atts); |
|
929 | 929 | |
930 | - $atts = wp_parse_args( $atts, $defaults ); |
|
930 | + $atts = wp_parse_args($atts, $defaults); |
|
931 | 931 | |
932 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
933 | - $product_data = wc_get_product( $atts['id'] ); |
|
934 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
935 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
936 | - $product_data = get_post( $product_id ); |
|
932 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
933 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
934 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
935 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
936 | + $product_data = get_post($product_id); |
|
937 | 937 | } else { |
938 | - $product_data = wc_get_product( $post->ID ); |
|
938 | + $product_data = wc_get_product($post->ID); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | // Check that the product type is supported. Return blank if not supported. |
942 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
942 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
943 | 943 | return ''; |
944 | 944 | } |
945 | 945 | |
946 | 946 | ob_start(); |
947 | 947 | |
948 | 948 | // Subscription Active Price |
949 | - $initial_payment = self::get_subscription_price_meta( array( 'id' => $product_data->id, 'meta' => 'active' ) ); |
|
949 | + $initial_payment = self::get_subscription_price_meta(array('id' => $product_data->id, 'meta' => 'active')); |
|
950 | 950 | |
951 | 951 | // Free Trial ? |
952 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
952 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
953 | 953 | |
954 | 954 | // If there is a free trial then the initial payment is Zero. |
955 | - if ( $trial_length > 0 ) { |
|
955 | + if ($trial_length > 0) { |
|
956 | 956 | $initial_payment = 0; |
957 | 957 | } |
958 | 958 | |
959 | 959 | // Sign up fee ? |
960 | - $sign_up_fee = self::get_subscription_sign_up_fee( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
960 | + $sign_up_fee = self::get_subscription_sign_up_fee(array('id' => $product_data->id, 'raw' => true)); |
|
961 | 961 | |
962 | 962 | // Apply the sign up fee if it exists. |
963 | - if ( !empty( $sign_up_fee ) && $sign_up_fee > 0 ) { |
|
963 | + if ( ! empty($sign_up_fee) && $sign_up_fee > 0) { |
|
964 | 964 | |
965 | - if ( ! $atts['total'] ) { |
|
966 | - $initial_payment = sprintf( __( '%s with a %s sign up fee.', WCSS::TEXT_DOMAIN ), wc_price( $initial_payment ), wc_price( $sign_up_fee ) ); |
|
965 | + if ( ! $atts[ 'total' ]) { |
|
966 | + $initial_payment = sprintf(__('%s with a %s sign up fee.', WCSS::TEXT_DOMAIN), wc_price($initial_payment), wc_price($sign_up_fee)); |
|
967 | 967 | } else { |
968 | - $initial_payment = round( ( double ) $initial_payment+$sign_up_fee, wc_get_price_decimals() ); |
|
968 | + $initial_payment = round((double) $initial_payment + $sign_up_fee, wc_get_price_decimals()); |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | } |
972 | 972 | |
973 | 973 | // Convert number into a price tag. |
974 | - if ( is_numeric( $initial_payment ) ) { |
|
975 | - $initial_payment = wc_price( $initial_payment ); |
|
974 | + if (is_numeric($initial_payment)) { |
|
975 | + $initial_payment = wc_price($initial_payment); |
|
976 | 976 | } |
977 | 977 | |
978 | 978 | echo $initial_payment; |
@@ -986,11 +986,11 @@ discard block |
||
986 | 986 | * @param $product_types |
987 | 987 | * @return array |
988 | 988 | */ |
989 | - public static function support_product_types_for_wc_satt( $product_types ) { |
|
989 | + public static function support_product_types_for_wc_satt($product_types) { |
|
990 | 990 | // Only add the product types from the WooCommerce extension "Subscribe to All the Things" if it is active. |
991 | - if ( class_exists( 'WCS_ATT' ) ) { |
|
991 | + if (class_exists('WCS_ATT')) { |
|
992 | 992 | $satt_product_types = WCS_ATT()->get_supported_product_types(); |
993 | - $product_types = array_merge( $satt_product_types, $product_types ); |
|
993 | + $product_types = array_merge($satt_product_types, $product_types); |
|
994 | 994 | } |
995 | 995 | |
996 | 996 | return $product_types; |