@@ -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,13 +63,13 @@ 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 ) { |
|
| 67 | - if ( ! is_object( $product ) ) { |
|
| 68 | - $product = wc_get_product( $product_id ); |
|
| 66 | + public static function force_is_subscription($is_subscription, $product_id, $product) { |
|
| 67 | + if ( ! is_object($product)) { |
|
| 68 | + $product = wc_get_product($product_id); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if ( in_array( $product->product_type, self::get_supported_product_types() ) ) { |
|
| 72 | - if ( class_exists( 'WCS_ATT_Schemes' ) && WCS_ATT_Schemes::get_product_subscription_schemes( $product ) ) { |
|
| 71 | + if (in_array($product->product_type, self::get_supported_product_types())) { |
|
| 72 | + if (class_exists('WCS_ATT_Schemes') && WCS_ATT_Schemes::get_product_subscription_schemes($product)) { |
|
| 73 | 73 | $is_subscription = true; |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -83,15 +83,15 @@ discard block |
||
| 83 | 83 | * @param WC_Product $product |
| 84 | 84 | * @return string |
| 85 | 85 | */ |
| 86 | - public static function get_price( $product ) { |
|
| 87 | - if ( WC_Subscriptions_Product::get_price( $product->id ) > 0 ) { |
|
| 86 | + public static function get_price($product) { |
|
| 87 | + if (WC_Subscriptions_Product::get_price($product->id) > 0) { |
|
| 88 | 88 | |
| 89 | - return ecs_html( WC_Subscriptions_Product::get_price( $product->id, array( |
|
| 89 | + return ecs_html(WC_Subscriptions_Product::get_price($product->id, array( |
|
| 90 | 90 | 'subscription_period' => false, |
| 91 | 91 | 'subscription_length' => false, |
| 92 | 92 | 'sign_up_fee' => false, |
| 93 | 93 | 'trial_length' => false, |
| 94 | - ) ) ); |
|
| 94 | + ))); |
|
| 95 | 95 | |
| 96 | 96 | } else { |
| 97 | 97 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * hooked: get_satt_lowest_price - 10 |
| 102 | 102 | */ |
| 103 | - do_action( 'woocommerce_subscriptions_shortcode_get_price', $product ); |
|
| 103 | + do_action('woocommerce_subscriptions_shortcode_get_price', $product); |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | } // END get_price() |
@@ -112,11 +112,11 @@ discard block |
||
| 112 | 112 | * @param WC_Product $product |
| 113 | 113 | * @return string |
| 114 | 114 | */ |
| 115 | - public static function get_satt_lowest_scheme_data( $product ) { |
|
| 116 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 117 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product ); |
|
| 115 | + public static function get_satt_lowest_scheme_data($product) { |
|
| 116 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 117 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product); |
|
| 118 | 118 | |
| 119 | - return WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product, $product_level_schemes ); |
|
| 119 | + return WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product, $product_level_schemes); |
|
| 120 | 120 | } |
| 121 | 121 | } // END get_satt_lowest_scheme() |
| 122 | 122 | |
@@ -127,42 +127,42 @@ discard block |
||
| 127 | 127 | * @param WC_Product $product |
| 128 | 128 | * @return string |
| 129 | 129 | */ |
| 130 | - public static function get_satt_lowest_price( $product ) { |
|
| 131 | - $scheme = self::get_satt_lowest_scheme_data( $product ); |
|
| 130 | + public static function get_satt_lowest_price($product) { |
|
| 131 | + $scheme = self::get_satt_lowest_scheme_data($product); |
|
| 132 | 132 | |
| 133 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 133 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 134 | 134 | // Override price? |
| 135 | - $override = $scheme['scheme']['subscription_pricing_method']; |
|
| 135 | + $override = $scheme[ 'scheme' ][ 'subscription_pricing_method' ]; |
|
| 136 | 136 | |
| 137 | 137 | // Discount? |
| 138 | - $discount = $scheme['scheme']['subscription_discount']; |
|
| 138 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
| 139 | 139 | |
| 140 | 140 | // Prices |
| 141 | 141 | $prices = array( |
| 142 | - 'price' => $scheme['price'], |
|
| 143 | - 'regular_price' => $scheme['regular_price'], |
|
| 144 | - 'sale_price' => $scheme['sale_price'], |
|
| 145 | - 'subscription_price' => $scheme['scheme']['subscription_price'], |
|
| 146 | - 'subscription_regular_price' => $scheme['scheme']['subscription_regular_price'], |
|
| 147 | - 'subscription_sale_price' => $scheme['scheme']['subscription_sale_price'] |
|
| 142 | + 'price' => $scheme[ 'price' ], |
|
| 143 | + 'regular_price' => $scheme[ 'regular_price' ], |
|
| 144 | + 'sale_price' => $scheme[ 'sale_price' ], |
|
| 145 | + 'subscription_price' => $scheme[ 'scheme' ][ 'subscription_price' ], |
|
| 146 | + 'subscription_regular_price' => $scheme[ 'scheme' ][ 'subscription_regular_price' ], |
|
| 147 | + 'subscription_sale_price' => $scheme[ 'scheme' ][ 'subscription_sale_price' ] |
|
| 148 | 148 | ); |
| 149 | 149 | |
| 150 | 150 | // Prepare the price |
| 151 | 151 | $price = ''; |
| 152 | 152 | |
| 153 | - if ( 'inherit' == $override ) { |
|
| 154 | - $price = empty( $discount ) ? $price : ( empty( $prices[ 'regular_price' ] ) ? $prices[ 'regular_price' ] : round( ( double ) $prices[ 'regular_price' ] * ( 100 - $discount ) / 100, wc_get_price_decimals() ) ); |
|
| 155 | - } else if ( 'override' == $override ) { |
|
| 156 | - $price = $prices['subscription_price']; |
|
| 153 | + if ('inherit' == $override) { |
|
| 154 | + $price = empty($discount) ? $price : (empty($prices[ 'regular_price' ]) ? $prices[ 'regular_price' ] : round((double) $prices[ 'regular_price' ] * (100 - $discount) / 100, wc_get_price_decimals())); |
|
| 155 | + } else if ('override' == $override) { |
|
| 156 | + $price = $prices[ 'subscription_price' ]; |
|
| 157 | 157 | |
| 158 | - if ( $prices[ 'subscription_price' ] < $prices[ 'subscription_regular_price' ] ) { |
|
| 158 | + if ($prices[ 'subscription_price' ] < $prices[ 'subscription_regular_price' ]) { |
|
| 159 | 159 | $price = $prices[ 'subscription_sale_price' ]; |
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // If the price is returned as an array, return just the first. |
| 164 | - if ( is_array( $price ) ) { |
|
| 165 | - $price = $price[0]; |
|
| 164 | + if (is_array($price)) { |
|
| 165 | + $price = $price[ 0 ]; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | return $price; |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | * @param array $atts |
| 179 | 179 | * @return string |
| 180 | 180 | */ |
| 181 | - public static function get_subscription_price( $atts ) { |
|
| 181 | + public static function get_subscription_price($atts) { |
|
| 182 | 182 | global $wpdb, $post; |
| 183 | 183 | |
| 184 | - $defaults = shortcode_atts( array( |
|
| 184 | + $defaults = shortcode_atts(array( |
|
| 185 | 185 | 'id' => '', |
| 186 | 186 | 'sku' => '', |
| 187 | 187 | 'period' => false, |
@@ -190,47 +190,47 @@ discard block |
||
| 190 | 190 | 'trial_length' => false, |
| 191 | 191 | 'before_price' => '<span class="price subscription-price">', |
| 192 | 192 | 'after_price' => '</span>', |
| 193 | - ), $atts ); |
|
| 193 | + ), $atts); |
|
| 194 | 194 | |
| 195 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 195 | + $atts = wp_parse_args($atts, $defaults); |
|
| 196 | 196 | |
| 197 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 198 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 199 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 200 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 201 | - $product_data = get_post( $product_id ); |
|
| 197 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 198 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 199 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 200 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 201 | + $product_data = get_post($product_id); |
|
| 202 | 202 | } else { |
| 203 | - $product_data = wc_get_product( $post->ID ); |
|
| 203 | + $product_data = wc_get_product($post->ID); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // Check that the product type is supported. Return blank if not supported. |
| 207 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 207 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 208 | 208 | return ''; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | ob_start(); |
| 212 | 212 | |
| 213 | - $price_html = WC_Subscriptions_Product::get_price_string( $product_data->id, array( |
|
| 214 | - 'price' => self::get_price( $product_data ), |
|
| 215 | - 'subscription_period' => isset( $atts['period'] ) ? $atts['period'] : true, |
|
| 216 | - 'subscription_length' => isset( $atts['length'] ) ? $atts['length'] : true, |
|
| 217 | - 'sign_up_fee' => isset( $atts['sign_up_fee'] ) ? $atts['sign_up_fee'] : true, |
|
| 218 | - 'trial_length' => isset( $atts['trial_length'] ) ? $atts['trial_length'] : true, |
|
| 219 | - ) ); |
|
| 213 | + $price_html = WC_Subscriptions_Product::get_price_string($product_data->id, array( |
|
| 214 | + 'price' => self::get_price($product_data), |
|
| 215 | + 'subscription_period' => isset($atts[ 'period' ]) ? $atts[ 'period' ] : true, |
|
| 216 | + 'subscription_length' => isset($atts[ 'length' ]) ? $atts[ 'length' ] : true, |
|
| 217 | + 'sign_up_fee' => isset($atts[ 'sign_up_fee' ]) ? $atts[ 'sign_up_fee' ] : true, |
|
| 218 | + 'trial_length' => isset($atts[ 'trial_length' ]) ? $atts[ 'trial_length' ] : true, |
|
| 219 | + )); |
|
| 220 | 220 | |
| 221 | 221 | // Clean the subscription price wrapper. |
| 222 | 222 | $price_html = str_replace('<span class="subscription-details">', '', $price_html); |
| 223 | 223 | $price_html = str_replace('</span">', '', $price_html); |
| 224 | 224 | |
| 225 | 225 | // Trim the whitespace. |
| 226 | - $price_html = trim( $price_html ); |
|
| 226 | + $price_html = trim($price_html); |
|
| 227 | 227 | |
| 228 | 228 | // Convert to Price Tag. |
| 229 | - $price_html = wc_price( $price_html ); |
|
| 229 | + $price_html = wc_price($price_html); |
|
| 230 | 230 | |
| 231 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $price_html, $atts['after_price'] ); |
|
| 231 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $price_html, $atts[ 'after_price' ]); |
|
| 232 | 232 | |
| 233 | - echo html_entity_decode( $price_html ); |
|
| 233 | + echo html_entity_decode($price_html); |
|
| 234 | 234 | |
| 235 | 235 | return ob_get_clean(); |
| 236 | 236 | } // END get_subscription_price() |
@@ -243,46 +243,46 @@ discard block |
||
| 243 | 243 | * @param array $atts |
| 244 | 244 | * @return string |
| 245 | 245 | */ |
| 246 | - public static function get_subscription_price_meta( $atts ) { |
|
| 246 | + public static function get_subscription_price_meta($atts) { |
|
| 247 | 247 | global $wpdb, $post; |
| 248 | 248 | |
| 249 | - $defaults = shortcode_atts( array( |
|
| 249 | + $defaults = shortcode_atts(array( |
|
| 250 | 250 | 'id' => '', |
| 251 | 251 | 'sku' => '', |
| 252 | 252 | 'meta' => 'both', |
| 253 | 253 | 'before_price' => '', |
| 254 | 254 | 'after_price' => '', |
| 255 | - ), $atts ); |
|
| 255 | + ), $atts); |
|
| 256 | 256 | |
| 257 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 257 | + $atts = wp_parse_args($atts, $defaults); |
|
| 258 | 258 | |
| 259 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 260 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 261 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 262 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 263 | - $product_data = get_post( $product_id ); |
|
| 259 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 260 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 261 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 262 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 263 | + $product_data = get_post($product_id); |
|
| 264 | 264 | } else { |
| 265 | - $product_data = wc_get_product( $post->ID ); |
|
| 265 | + $product_data = wc_get_product($post->ID); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | // Check that the product type is supported. Return blank if not supported. |
| 269 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 269 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 270 | 270 | return ''; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | ob_start(); |
| 274 | 274 | |
| 275 | - $price = WC_Subscriptions_Product::get_price( $product_data->id ); |
|
| 275 | + $price = WC_Subscriptions_Product::get_price($product_data->id); |
|
| 276 | 276 | |
| 277 | 277 | // Remove the subscription price wrapper. |
| 278 | 278 | $price_html = str_replace('<span class="subscription-details">', '', $price); |
| 279 | 279 | $price = str_replace('</span">', '', $price_html); |
| 280 | 280 | |
| 281 | 281 | // If the subscription product has no price, then look for alternative. |
| 282 | - if ( empty( $price ) ) { |
|
| 283 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
| 282 | + if (empty($price)) { |
|
| 283 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
| 284 | 284 | |
| 285 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 285 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 286 | 286 | |
| 287 | 287 | // These values will be overridden. They are defined here to acknowledge their existence. |
| 288 | 288 | $price = ''; |
@@ -290,30 +290,30 @@ discard block |
||
| 290 | 290 | $sale_price = ''; |
| 291 | 291 | |
| 292 | 292 | $prices = array( |
| 293 | - 'price' => $scheme['price'], |
|
| 294 | - 'regular_price' => $scheme['regular_price'], |
|
| 295 | - 'sale_price' => $scheme['sale_price'], |
|
| 296 | - 'method' => $scheme['scheme']['subscription_pricing_method'], |
|
| 297 | - 'subscription_price' => $scheme['scheme']['subscription_price'], |
|
| 298 | - 'subscription_regular_price' => $scheme['scheme']['subscription_regular_price'], |
|
| 299 | - 'subscription_sale_price' => $scheme['scheme']['subscription_sale_price'] |
|
| 293 | + 'price' => $scheme[ 'price' ], |
|
| 294 | + 'regular_price' => $scheme[ 'regular_price' ], |
|
| 295 | + 'sale_price' => $scheme[ 'sale_price' ], |
|
| 296 | + 'method' => $scheme[ 'scheme' ][ 'subscription_pricing_method' ], |
|
| 297 | + 'subscription_price' => $scheme[ 'scheme' ][ 'subscription_price' ], |
|
| 298 | + 'subscription_regular_price' => $scheme[ 'scheme' ][ 'subscription_regular_price' ], |
|
| 299 | + 'subscription_sale_price' => $scheme[ 'scheme' ][ 'subscription_sale_price' ] |
|
| 300 | 300 | ); |
| 301 | 301 | |
| 302 | 302 | // Return the subscription price based on the pricing method. |
| 303 | - switch( $prices['method'] ) { |
|
| 303 | + switch ($prices[ 'method' ]) { |
|
| 304 | 304 | case 'override': |
| 305 | - $price = $prices['subscription_price']; |
|
| 306 | - $regular_price = $prices['subscription_regular_price']; |
|
| 307 | - $sale_price = $prices['subscription_sale_price']; |
|
| 305 | + $price = $prices[ 'subscription_price' ]; |
|
| 306 | + $regular_price = $prices[ 'subscription_regular_price' ]; |
|
| 307 | + $sale_price = $prices[ 'subscription_sale_price' ]; |
|
| 308 | 308 | break; |
| 309 | 309 | case 'inherit': |
| 310 | - $discount = $scheme['scheme']['subscription_discount']; |
|
| 311 | - $price = $prices['price']; |
|
| 312 | - $regular_price = $prices['regular_price']; |
|
| 313 | - $sale_price = $prices['sale_price']; |
|
| 310 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
| 311 | + $price = $prices[ 'price' ]; |
|
| 312 | + $regular_price = $prices[ 'regular_price' ]; |
|
| 313 | + $sale_price = $prices[ 'sale_price' ]; |
|
| 314 | 314 | |
| 315 | - if ( !empty( $discount ) && $discount > 0 ) { |
|
| 316 | - $sale_price = round( ( double ) $regular_price * ( 100 - $discount ) / 100, wc_get_price_decimals() ); |
|
| 315 | + if ( ! empty($discount) && $discount > 0) { |
|
| 316 | + $sale_price = round((double) $regular_price * (100 - $discount) / 100, wc_get_price_decimals()); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | break; |
@@ -321,42 +321,42 @@ discard block |
||
| 321 | 321 | |
| 322 | 322 | // Display both the regular price striked out and the sale price |
| 323 | 323 | // should the active price be less than the regular price. |
| 324 | - if ( $atts['meta'] != 'active' && !empty( $sale_price ) && $price < $regular_price ) { |
|
| 325 | - $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>'; |
|
| 324 | + if ($atts[ 'meta' ] != 'active' && ! empty($sale_price) && $price < $regular_price) { |
|
| 325 | + $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>'; |
|
| 326 | 326 | |
| 327 | 327 | // Trim the whitespace. |
| 328 | - $price = trim( $price ); |
|
| 328 | + $price = trim($price); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | // Override the value should only one value be returned. |
| 332 | - if ( $atts['meta'] != 'both' ) { |
|
| 333 | - if ( $atts['meta'] == 'active' ) { |
|
| 332 | + if ($atts[ 'meta' ] != 'both') { |
|
| 333 | + if ($atts[ 'meta' ] == 'active') { |
|
| 334 | 334 | $price = $price; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - if ( $atts['meta'] == 'regular' ) { |
|
| 337 | + if ($atts[ 'meta' ] == 'regular') { |
|
| 338 | 338 | $price = $regular_price; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - if ( $atts['meta'] == 'sale' ) { |
|
| 341 | + if ($atts[ 'meta' ] == 'sale') { |
|
| 342 | 342 | $price = $sale_price; |
| 343 | 343 | } |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - if ( is_numeric( $price ) ) { |
|
| 347 | - $price = wc_price( $price ); |
|
| 346 | + if (is_numeric($price)) { |
|
| 347 | + $price = wc_price($price); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | // Clean the price tag. |
| 351 | - $price = self::clean_wc_price( $price ); |
|
| 351 | + $price = self::clean_wc_price($price); |
|
| 352 | 352 | |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $price, $atts['after_price'] ); |
|
| 357 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $price, $atts[ 'after_price' ]); |
|
| 358 | 358 | |
| 359 | - echo html_entity_decode( $price_html ); |
|
| 359 | + echo html_entity_decode($price_html); |
|
| 360 | 360 | |
| 361 | 361 | return ob_get_clean(); |
| 362 | 362 | } // END get_subscription_price_meta() |
@@ -369,27 +369,27 @@ discard block |
||
| 369 | 369 | * @param array $atts |
| 370 | 370 | * @return string |
| 371 | 371 | */ |
| 372 | - public static function get_subscription_discount( $atts ) { |
|
| 372 | + public static function get_subscription_discount($atts) { |
|
| 373 | 373 | global $wpdb, $post; |
| 374 | 374 | |
| 375 | - $defaults = shortcode_atts( array( |
|
| 375 | + $defaults = shortcode_atts(array( |
|
| 376 | 376 | 'id' => '', |
| 377 | 377 | 'sku' => '', |
| 378 | - ), $atts ); |
|
| 378 | + ), $atts); |
|
| 379 | 379 | |
| 380 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 380 | + $atts = wp_parse_args($atts, $defaults); |
|
| 381 | 381 | |
| 382 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 383 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 384 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 385 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 386 | - $product_data = get_post( $product_id ); |
|
| 382 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 383 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 384 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 385 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 386 | + $product_data = get_post($product_id); |
|
| 387 | 387 | } else { |
| 388 | - $product_data = wc_get_product( $post->ID ); |
|
| 388 | + $product_data = wc_get_product($post->ID); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | // Check that the product type is supported. Return blank if not supported. |
| 392 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 392 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 393 | 393 | return ''; |
| 394 | 394 | } |
| 395 | 395 | |
@@ -399,18 +399,18 @@ discard block |
||
| 399 | 399 | $discount = ''; // Returns empty by default. |
| 400 | 400 | |
| 401 | 401 | // Get Subscription Discount - Only available with the WooCommerce extension "Subscribe to All the Things". |
| 402 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
| 402 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
| 403 | 403 | |
| 404 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 404 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 405 | 405 | // Override price? |
| 406 | - $override = $scheme['scheme']['subscription_pricing_method']; |
|
| 406 | + $override = $scheme[ 'scheme' ][ 'subscription_pricing_method' ]; |
|
| 407 | 407 | |
| 408 | 408 | // Discount ? |
| 409 | - $discount = $scheme['scheme']['subscription_discount']; |
|
| 409 | + $discount = $scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - if ( ! empty( $discount ) && is_numeric( $discount ) && $override == 'inherit' ) { |
|
| 413 | - $discount = sprintf( __( '%s%s %s', WCSS::TEXT_DOMAIN ), $discount, '%', apply_filters( 'wcs_shortcodes_sub_discount_string', __( 'discount', WCSS::TEXT_DOMAIN ) ) ); |
|
| 412 | + if ( ! empty($discount) && is_numeric($discount) && $override == 'inherit') { |
|
| 413 | + $discount = sprintf(__('%s%s %s', WCSS::TEXT_DOMAIN), $discount, '%', apply_filters('wcs_shortcodes_sub_discount_string', __('discount', WCSS::TEXT_DOMAIN))); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | echo $discount; |
@@ -424,47 +424,47 @@ discard block |
||
| 424 | 424 | * @param array $atts |
| 425 | 425 | * @return string |
| 426 | 426 | */ |
| 427 | - public static function get_subscription_period( $atts ) { |
|
| 427 | + public static function get_subscription_period($atts) { |
|
| 428 | 428 | global $wpdb, $post; |
| 429 | 429 | |
| 430 | - $defaults = shortcode_atts( array( |
|
| 430 | + $defaults = shortcode_atts(array( |
|
| 431 | 431 | 'id' => '', |
| 432 | 432 | 'sku' => '', |
| 433 | 433 | 'raw' => false |
| 434 | - ), $atts ); |
|
| 434 | + ), $atts); |
|
| 435 | 435 | |
| 436 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 436 | + $atts = wp_parse_args($atts, $defaults); |
|
| 437 | 437 | |
| 438 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 439 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 440 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 441 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 442 | - $product_data = get_post( $product_id ); |
|
| 438 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 439 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 440 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 441 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 442 | + $product_data = get_post($product_id); |
|
| 443 | 443 | } else { |
| 444 | - $product_data = wc_get_product( $post->ID ); |
|
| 444 | + $product_data = wc_get_product($post->ID); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | // Check that the product type is supported. Return blank if not supported. |
| 448 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 448 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 449 | 449 | return ''; |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | ob_start(); |
| 453 | 453 | |
| 454 | 454 | // Get Subscription Period |
| 455 | - $period = WC_Subscriptions_Product::get_period( $product_data ); |
|
| 455 | + $period = WC_Subscriptions_Product::get_period($product_data); |
|
| 456 | 456 | |
| 457 | 457 | // If the period is empty, look for alternative. |
| 458 | - if ( empty( $period ) ) { |
|
| 459 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
| 458 | + if (empty($period)) { |
|
| 459 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
| 460 | 460 | |
| 461 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 462 | - $period = $scheme['scheme']['subscription_period']; |
|
| 461 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 462 | + $period = $scheme[ 'scheme' ][ 'subscription_period' ]; |
|
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - if ( ! $atts['raw'] ) { |
|
| 467 | - $period = sprintf( __( 'Per %s', WCSS::TEXT_DOMAIN ), $period ); |
|
| 466 | + if ( ! $atts[ 'raw' ]) { |
|
| 467 | + $period = sprintf(__('Per %s', WCSS::TEXT_DOMAIN), $period); |
|
| 468 | 468 | $period = ucwords($period); |
| 469 | 469 | } |
| 470 | 470 | |
@@ -479,41 +479,41 @@ discard block |
||
| 479 | 479 | * @param array $atts |
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | - public static function get_subscription_period_interval( $atts ) { |
|
| 482 | + public static function get_subscription_period_interval($atts) { |
|
| 483 | 483 | global $wpdb, $post; |
| 484 | 484 | |
| 485 | - $defaults = shortcode_atts( array( |
|
| 485 | + $defaults = shortcode_atts(array( |
|
| 486 | 486 | 'id' => '', |
| 487 | 487 | 'sku' => '', |
| 488 | - ), $atts ); |
|
| 488 | + ), $atts); |
|
| 489 | 489 | |
| 490 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 490 | + $atts = wp_parse_args($atts, $defaults); |
|
| 491 | 491 | |
| 492 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 493 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 494 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 495 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 496 | - $product_data = get_post( $product_id ); |
|
| 492 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 493 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 494 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 495 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 496 | + $product_data = get_post($product_id); |
|
| 497 | 497 | } else { |
| 498 | - $product_data = wc_get_product( $post->ID ); |
|
| 498 | + $product_data = wc_get_product($post->ID); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // Check that the product type is supported. Return blank if not supported. |
| 502 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 502 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 503 | 503 | return ''; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | ob_start(); |
| 507 | 507 | |
| 508 | 508 | // Get Subscription Period Interval |
| 509 | - $period_interval = WC_Subscriptions_Product::get_interval( $product_data ); |
|
| 509 | + $period_interval = WC_Subscriptions_Product::get_interval($product_data); |
|
| 510 | 510 | |
| 511 | 511 | // If the period is empty, look for alternative. |
| 512 | - if ( empty( $period_interval ) ) { |
|
| 513 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
| 512 | + if (empty($period_interval)) { |
|
| 513 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
| 514 | 514 | |
| 515 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 516 | - $period_interval = $scheme['scheme']['subscription_period_interval']; |
|
| 515 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 516 | + $period_interval = $scheme[ 'scheme' ][ 'subscription_period_interval' ]; |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | |
@@ -528,52 +528,52 @@ discard block |
||
| 528 | 528 | * @param array $atts |
| 529 | 529 | * @return string |
| 530 | 530 | */ |
| 531 | - public static function get_subscription_length( $atts ) { |
|
| 531 | + public static function get_subscription_length($atts) { |
|
| 532 | 532 | global $wpdb, $post; |
| 533 | 533 | |
| 534 | - $defaults = shortcode_atts( array( |
|
| 534 | + $defaults = shortcode_atts(array( |
|
| 535 | 535 | 'id' => '', |
| 536 | 536 | 'sku' => '', |
| 537 | 537 | 'raw' => false, |
| 538 | - ), $atts ); |
|
| 538 | + ), $atts); |
|
| 539 | 539 | |
| 540 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 540 | + $atts = wp_parse_args($atts, $defaults); |
|
| 541 | 541 | |
| 542 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 543 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 544 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 545 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 546 | - $product_data = get_post( $product_id ); |
|
| 542 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 543 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 544 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 545 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 546 | + $product_data = get_post($product_id); |
|
| 547 | 547 | } else { |
| 548 | - $product_data = wc_get_product( $post->ID ); |
|
| 548 | + $product_data = wc_get_product($post->ID); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | // Check that the product type is supported. Return blank if not supported. |
| 552 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 552 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 553 | 553 | return ''; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | ob_start(); |
| 557 | 557 | |
| 558 | 558 | // Get Subscription Length |
| 559 | - $length = WC_Subscriptions_Product::get_length( $product_data ); |
|
| 559 | + $length = WC_Subscriptions_Product::get_length($product_data); |
|
| 560 | 560 | |
| 561 | 561 | // If the length is empty, look for alternative. |
| 562 | - if ( empty( $length ) ) { |
|
| 563 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
| 562 | + if (empty($length)) { |
|
| 563 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
| 564 | 564 | |
| 565 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 565 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 566 | 566 | |
| 567 | - $period = self::get_subscription_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
| 568 | - $length = $scheme['scheme']['subscription_length']; |
|
| 567 | + $period = self::get_subscription_period(array('id' => $product_data->id, 'raw' => true)); |
|
| 568 | + $length = $scheme[ 'scheme' ][ 'subscription_length' ]; |
|
| 569 | 569 | |
| 570 | 570 | // If we are not returning raw data then making it readable for humans. |
| 571 | - if ( ! $atts['raw'] ) { |
|
| 571 | + if ( ! $atts[ 'raw' ]) { |
|
| 572 | 572 | |
| 573 | - if ( $length > 0 ) { |
|
| 574 | - $length = sprintf( '%s %s', $length, $period ); |
|
| 573 | + if ($length > 0) { |
|
| 574 | + $length = sprintf('%s %s', $length, $period); |
|
| 575 | 575 | } else { |
| 576 | - $length = sprintf( __( 'Every %s', WCSS::TEXT_DOMAIN ), $period ); |
|
| 576 | + $length = sprintf(__('Every %s', WCSS::TEXT_DOMAIN), $period); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | $length = ucfirst($length); |
@@ -595,59 +595,59 @@ discard block |
||
| 595 | 595 | * @param array $atts |
| 596 | 596 | * @return string |
| 597 | 597 | */ |
| 598 | - public static function get_subscription_sign_up_fee( $atts ) { |
|
| 598 | + public static function get_subscription_sign_up_fee($atts) { |
|
| 599 | 599 | global $wpdb, $post; |
| 600 | 600 | |
| 601 | - $defaults = shortcode_atts( array( |
|
| 601 | + $defaults = shortcode_atts(array( |
|
| 602 | 602 | 'id' => '', |
| 603 | 603 | 'sku' => '', |
| 604 | 604 | 'raw' => false, |
| 605 | 605 | 'before_price' => '', |
| 606 | 606 | 'after_price' => '', |
| 607 | - ), $atts ); |
|
| 607 | + ), $atts); |
|
| 608 | 608 | |
| 609 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 609 | + $atts = wp_parse_args($atts, $defaults); |
|
| 610 | 610 | |
| 611 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 612 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 613 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 614 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 615 | - $product_data = get_post( $product_id ); |
|
| 611 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 612 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 613 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 614 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 615 | + $product_data = get_post($product_id); |
|
| 616 | 616 | } else { |
| 617 | - $product_data = wc_get_product( $post->ID ); |
|
| 617 | + $product_data = wc_get_product($post->ID); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | // Check that the product type is supported. Return blank if not supported. |
| 621 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 621 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 622 | 622 | return ''; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | ob_start(); |
| 626 | 626 | |
| 627 | 627 | // Get Subscription Sign Up Fee |
| 628 | - $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product_data ); |
|
| 628 | + $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product_data); |
|
| 629 | 629 | |
| 630 | 630 | // If the sign up fee is empty, look for alternative. |
| 631 | - if ( empty( $sign_up_fee ) ) { |
|
| 632 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
| 631 | + if (empty($sign_up_fee)) { |
|
| 632 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
| 633 | 633 | |
| 634 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 635 | - $sign_up_fee = $scheme['scheme']['subscription_sign_up_fee']; |
|
| 634 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 635 | + $sign_up_fee = $scheme[ 'scheme' ][ 'subscription_sign_up_fee' ]; |
|
| 636 | 636 | } |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - if ( ! $atts['raw'] ) { |
|
| 639 | + if ( ! $atts[ 'raw' ]) { |
|
| 640 | 640 | // Convert number into a price tag. |
| 641 | - if ( is_numeric( $sign_up_fee ) ) { |
|
| 642 | - $sign_up_fee = wc_price( $sign_up_fee ); |
|
| 641 | + if (is_numeric($sign_up_fee)) { |
|
| 642 | + $sign_up_fee = wc_price($sign_up_fee); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | // Clean the price tag. |
| 646 | - $sign_up_fee = self::clean_wc_price( $sign_up_fee ); |
|
| 646 | + $sign_up_fee = self::clean_wc_price($sign_up_fee); |
|
| 647 | 647 | |
| 648 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $sign_up_fee, $atts['after_price'] ); |
|
| 648 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $sign_up_fee, $atts[ 'after_price' ]); |
|
| 649 | 649 | |
| 650 | - $sign_up_fee = html_entity_decode( $price_html ); |
|
| 650 | + $sign_up_fee = html_entity_decode($price_html); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | echo $sign_up_fee; |
@@ -661,55 +661,55 @@ discard block |
||
| 661 | 661 | * @param array $atts |
| 662 | 662 | * @return string |
| 663 | 663 | */ |
| 664 | - public static function get_subscription_trial_string( $atts ) { |
|
| 664 | + public static function get_subscription_trial_string($atts) { |
|
| 665 | 665 | global $wpdb, $post; |
| 666 | 666 | |
| 667 | - $defaults = shortcode_atts( array( |
|
| 667 | + $defaults = shortcode_atts(array( |
|
| 668 | 668 | 'id' => '', |
| 669 | 669 | 'sku' => '', |
| 670 | - ), $atts ); |
|
| 670 | + ), $atts); |
|
| 671 | 671 | |
| 672 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 672 | + $atts = wp_parse_args($atts, $defaults); |
|
| 673 | 673 | |
| 674 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 675 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 676 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 677 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 678 | - $product_data = get_post( $product_id ); |
|
| 674 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 675 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 676 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 677 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 678 | + $product_data = get_post($product_id); |
|
| 679 | 679 | } else { |
| 680 | - $product_data = wc_get_product( $post->ID ); |
|
| 680 | + $product_data = wc_get_product($post->ID); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | // Check that the product type is supported. Return blank if not supported. |
| 684 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 684 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 685 | 685 | return ''; |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | ob_start(); |
| 689 | 689 | |
| 690 | 690 | // Get Subscription Trial Length |
| 691 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
| 691 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
| 692 | 692 | |
| 693 | 693 | // Get Subscription Trial Period |
| 694 | - $trial_period = self::get_subscription_trial_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
| 694 | + $trial_period = self::get_subscription_trial_period(array('id' => $product_data->id, 'raw' => true)); |
|
| 695 | 695 | |
| 696 | - if ( ! empty( $trial_length ) && $trial_length > 0 ) { |
|
| 696 | + if ( ! empty($trial_length) && $trial_length > 0) { |
|
| 697 | 697 | |
| 698 | - switch ( $trial_period ) { |
|
| 698 | + switch ($trial_period) { |
|
| 699 | 699 | case 'day': |
| 700 | - echo sprintf( _n( '%s day', '%s days', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
| 700 | + echo sprintf(_n('%s day', '%s days', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
| 701 | 701 | break; |
| 702 | 702 | |
| 703 | 703 | case 'week': |
| 704 | - echo sprintf( _n( '%s week', '%s weeks', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
| 704 | + echo sprintf(_n('%s week', '%s weeks', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
| 705 | 705 | break; |
| 706 | 706 | |
| 707 | 707 | case 'month': |
| 708 | - echo sprintf( _n( '%s month', '%s months', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
| 708 | + echo sprintf(_n('%s month', '%s months', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
| 709 | 709 | break; |
| 710 | 710 | |
| 711 | 711 | case 'year': |
| 712 | - echo sprintf( _n( '%s year', '%s years', $trial_length, WCSS::TEXT_DOMAIN ), $trial_length ); |
|
| 712 | + echo sprintf(_n('%s year', '%s years', $trial_length, WCSS::TEXT_DOMAIN), $trial_length); |
|
| 713 | 713 | break; |
| 714 | 714 | } |
| 715 | 715 | |
@@ -724,41 +724,41 @@ discard block |
||
| 724 | 724 | * @param array $atts |
| 725 | 725 | * @return string |
| 726 | 726 | */ |
| 727 | - public static function get_subscription_trial_length( $atts ) { |
|
| 727 | + public static function get_subscription_trial_length($atts) { |
|
| 728 | 728 | global $wpdb, $post; |
| 729 | 729 | |
| 730 | - $defaults = shortcode_atts( array( |
|
| 730 | + $defaults = shortcode_atts(array( |
|
| 731 | 731 | 'id' => '', |
| 732 | 732 | 'sku' => '', |
| 733 | - ), $atts ); |
|
| 733 | + ), $atts); |
|
| 734 | 734 | |
| 735 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 735 | + $atts = wp_parse_args($atts, $defaults); |
|
| 736 | 736 | |
| 737 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 738 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 739 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 740 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 741 | - $product_data = get_post( $product_id ); |
|
| 737 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 738 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 739 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 740 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 741 | + $product_data = get_post($product_id); |
|
| 742 | 742 | } else { |
| 743 | - $product_data = wc_get_product( $post->ID ); |
|
| 743 | + $product_data = wc_get_product($post->ID); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | // Check that the product type is supported. Return blank if not supported. |
| 747 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 747 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 748 | 748 | return ''; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | ob_start(); |
| 752 | 752 | |
| 753 | 753 | // Get Subscription Trial Length |
| 754 | - $trial_length = WC_Subscriptions_Product::get_trial_length( $product_data ); |
|
| 754 | + $trial_length = WC_Subscriptions_Product::get_trial_length($product_data); |
|
| 755 | 755 | |
| 756 | 756 | // If the trial length is empty, look for alternative. |
| 757 | - if ( empty( $trial_length ) ) { |
|
| 758 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
| 757 | + if (empty($trial_length)) { |
|
| 758 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
| 759 | 759 | |
| 760 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 761 | - $trial_length = $scheme['scheme']['subscription_trial_length']; |
|
| 760 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 761 | + $trial_length = $scheme[ 'scheme' ][ 'subscription_trial_length' ]; |
|
| 762 | 762 | } |
| 763 | 763 | } |
| 764 | 764 | |
@@ -773,52 +773,52 @@ discard block |
||
| 773 | 773 | * @param array $atts |
| 774 | 774 | * @return string |
| 775 | 775 | */ |
| 776 | - public static function get_subscription_trial_period( $atts ) { |
|
| 776 | + public static function get_subscription_trial_period($atts) { |
|
| 777 | 777 | global $wpdb, $post; |
| 778 | 778 | |
| 779 | - $defaults = shortcode_atts( array( |
|
| 779 | + $defaults = shortcode_atts(array( |
|
| 780 | 780 | 'id' => '', |
| 781 | 781 | 'sku' => '', |
| 782 | 782 | 'raw' => false, |
| 783 | - ), $atts ); |
|
| 783 | + ), $atts); |
|
| 784 | 784 | |
| 785 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 785 | + $atts = wp_parse_args($atts, $defaults); |
|
| 786 | 786 | |
| 787 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 788 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 789 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 790 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 791 | - $product_data = get_post( $product_id ); |
|
| 787 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 788 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 789 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 790 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 791 | + $product_data = get_post($product_id); |
|
| 792 | 792 | } else { |
| 793 | - $product_data = wc_get_product( $post->ID ); |
|
| 793 | + $product_data = wc_get_product($post->ID); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | // Check that the product type is supported. Return blank if not supported. |
| 797 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 797 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 798 | 798 | return ''; |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | ob_start(); |
| 802 | 802 | |
| 803 | 803 | // Get Subscription Trial Length |
| 804 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
| 804 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
| 805 | 805 | |
| 806 | 806 | // Get Subscription Trial Period |
| 807 | - $trial_period = WC_Subscriptions_Product::get_trial_period( $product_data ); |
|
| 807 | + $trial_period = WC_Subscriptions_Product::get_trial_period($product_data); |
|
| 808 | 808 | |
| 809 | 809 | // If the trial length is empty or is not zero, look for alternative. |
| 810 | - if ( empty( $trial_length ) || $trial_length != 0 ) { |
|
| 811 | - $scheme = self::get_satt_lowest_scheme_data( $product_data ); |
|
| 810 | + if (empty($trial_length) || $trial_length != 0) { |
|
| 811 | + $scheme = self::get_satt_lowest_scheme_data($product_data); |
|
| 812 | 812 | |
| 813 | - if ( !empty( $scheme ) && is_array( $scheme ) ) { |
|
| 814 | - $trial_length = $scheme['scheme']['subscription_trial_length']; |
|
| 815 | - $trial_period = $scheme['scheme']['subscription_trial_period']; |
|
| 813 | + if ( ! empty($scheme) && is_array($scheme)) { |
|
| 814 | + $trial_length = $scheme[ 'scheme' ][ 'subscription_trial_length' ]; |
|
| 815 | + $trial_period = $scheme[ 'scheme' ][ 'subscription_trial_period' ]; |
|
| 816 | 816 | } |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - if ( ! empty( $trial_length ) && $trial_length > 0 ) { |
|
| 819 | + if ( ! empty($trial_length) && $trial_length > 0) { |
|
| 820 | 820 | |
| 821 | - if ( ! $atts['raw'] ) { |
|
| 821 | + if ( ! $atts[ 'raw' ]) { |
|
| 822 | 822 | $trial_period = ucfirst($trial_period); |
| 823 | 823 | } |
| 824 | 824 | |
@@ -835,62 +835,62 @@ discard block |
||
| 835 | 835 | * @param array $atts |
| 836 | 836 | * @return string |
| 837 | 837 | */ |
| 838 | - public static function get_subscription_first_payment( $atts ) { |
|
| 838 | + public static function get_subscription_first_payment($atts) { |
|
| 839 | 839 | global $wpdb, $post; |
| 840 | 840 | |
| 841 | - $defaults = shortcode_atts( array( |
|
| 841 | + $defaults = shortcode_atts(array( |
|
| 842 | 842 | 'id' => '', |
| 843 | 843 | 'sku' => '', |
| 844 | 844 | 'show_time' => false, |
| 845 | 845 | 'from_date' => '', |
| 846 | 846 | 'timezone' => 'gmt', |
| 847 | 847 | 'format' => 'timestamp' |
| 848 | - ), $atts ); |
|
| 848 | + ), $atts); |
|
| 849 | 849 | |
| 850 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 850 | + $atts = wp_parse_args($atts, $defaults); |
|
| 851 | 851 | |
| 852 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 853 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 854 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 855 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 856 | - $product_data = get_post( $product_id ); |
|
| 852 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 853 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 854 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 855 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 856 | + $product_data = get_post($product_id); |
|
| 857 | 857 | } else { |
| 858 | - $product_data = wc_get_product( $post->ID ); |
|
| 858 | + $product_data = wc_get_product($post->ID); |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | // Check that the product type is supported. Return blank if not supported. |
| 862 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 862 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 863 | 863 | return ''; |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | ob_start(); |
| 867 | 867 | |
| 868 | - $billing_interval = self::get_subscription_period_interval( array( 'id' => $product_data->id ) ); |
|
| 869 | - $billing_length = self::get_subscription_length( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
| 870 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
| 868 | + $billing_interval = self::get_subscription_period_interval(array('id' => $product_data->id)); |
|
| 869 | + $billing_length = self::get_subscription_length(array('id' => $product_data->id, 'raw' => true)); |
|
| 870 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
| 871 | 871 | |
| 872 | - $from_date = $atts['from_date']; |
|
| 872 | + $from_date = $atts[ 'from_date' ]; |
|
| 873 | 873 | |
| 874 | - if ( $billing_interval !== $billing_length || $trial_length > 0 ) { |
|
| 875 | - if ( empty( $from_date ) ) { |
|
| 876 | - $from_date = gmdate( 'Y-m-d H:i:s' ); |
|
| 874 | + if ($billing_interval !== $billing_length || $trial_length > 0) { |
|
| 875 | + if (empty($from_date)) { |
|
| 876 | + $from_date = gmdate('Y-m-d H:i:s'); |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | // If the subscription has a free trial period, the first renewal is the same as the expiration of the free trial. |
| 880 | - if ( $trial_length > 0 ) { |
|
| 881 | - $first_renewal_timestamp = strtotime( self::get_trial_expiration_date( $product_data->id, $from_date ) ); |
|
| 880 | + if ($trial_length > 0) { |
|
| 881 | + $first_renewal_timestamp = strtotime(self::get_trial_expiration_date($product_data->id, $from_date)); |
|
| 882 | 882 | } else { |
| 883 | - $from_timestamp = strtotime( $from_date ); |
|
| 884 | - $billing_period = self::get_subscription_period( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
| 883 | + $from_timestamp = strtotime($from_date); |
|
| 884 | + $billing_period = self::get_subscription_period(array('id' => $product_data->id, 'raw' => true)); |
|
| 885 | 885 | |
| 886 | - if ( 'month' == $billing_period ) { |
|
| 887 | - $first_renewal_timestamp = wcs_add_months( $from_timestamp, $billing_interval ); |
|
| 886 | + if ('month' == $billing_period) { |
|
| 887 | + $first_renewal_timestamp = wcs_add_months($from_timestamp, $billing_interval); |
|
| 888 | 888 | } else { |
| 889 | - $first_renewal_timestamp = strtotime( "+ $billing_interval {$billing_period}s", $from_timestamp ); |
|
| 889 | + $first_renewal_timestamp = strtotime("+ $billing_interval {$billing_period}s", $from_timestamp); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | - if ( 'site' == $atts['timezone'] ) { |
|
| 893 | - $first_renewal_timestamp += ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
| 892 | + if ('site' == $atts[ 'timezone' ]) { |
|
| 893 | + $first_renewal_timestamp += (get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
| 894 | 894 | } |
| 895 | 895 | } |
| 896 | 896 | } else { |
@@ -899,22 +899,22 @@ discard block |
||
| 899 | 899 | |
| 900 | 900 | $date_format = ''; // Will be overridden later on. |
| 901 | 901 | |
| 902 | - if ( $first_renewal_timestamp > 0 ) { |
|
| 903 | - if ( $atts['show_time'] ) { |
|
| 904 | - if ( 'timestamp' == $atts['format'] ) { |
|
| 902 | + if ($first_renewal_timestamp > 0) { |
|
| 903 | + if ($atts[ 'show_time' ]) { |
|
| 904 | + if ('timestamp' == $atts[ 'format' ]) { |
|
| 905 | 905 | $date_format = 'Y-m-d H:i:s'; |
| 906 | - } else if ( 'string' == $atts['format'] ) { |
|
| 906 | + } else if ('string' == $atts[ 'format' ]) { |
|
| 907 | 907 | $date_format = 'D jS M Y H:i A'; |
| 908 | 908 | } |
| 909 | 909 | } else { |
| 910 | - if ( 'timestamp' == $atts['format'] ) { |
|
| 910 | + if ('timestamp' == $atts[ 'format' ]) { |
|
| 911 | 911 | $date_format = 'Y-m-d'; |
| 912 | - } else if ( 'string' == $atts['format'] ) { |
|
| 912 | + } else if ('string' == $atts[ 'format' ]) { |
|
| 913 | 913 | $date_format = 'D jS M Y'; |
| 914 | 914 | } |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | - $first_payment = date( $date_format, $first_renewal_timestamp ); |
|
| 917 | + $first_payment = date($date_format, $first_renewal_timestamp); |
|
| 918 | 918 | } else { |
| 919 | 919 | $first_payment = ''; |
| 920 | 920 | } |
@@ -930,65 +930,65 @@ discard block |
||
| 930 | 930 | * @param array $atts |
| 931 | 931 | * @return string |
| 932 | 932 | */ |
| 933 | - public static function get_subscription_initial( $atts ) { |
|
| 933 | + public static function get_subscription_initial($atts) { |
|
| 934 | 934 | global $wpdb, $post; |
| 935 | 935 | |
| 936 | - $defaults = shortcode_atts( array( |
|
| 936 | + $defaults = shortcode_atts(array( |
|
| 937 | 937 | 'id' => '', |
| 938 | 938 | 'sku' => '', |
| 939 | 939 | 'total' => false |
| 940 | - ), $atts ); |
|
| 940 | + ), $atts); |
|
| 941 | 941 | |
| 942 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 942 | + $atts = wp_parse_args($atts, $defaults); |
|
| 943 | 943 | |
| 944 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 945 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 946 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 947 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 948 | - $product_data = get_post( $product_id ); |
|
| 944 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 945 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 946 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 947 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 948 | + $product_data = get_post($product_id); |
|
| 949 | 949 | } else { |
| 950 | - $product_data = wc_get_product( $post->ID ); |
|
| 950 | + $product_data = wc_get_product($post->ID); |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | // Check that the product type is supported. Return blank if not supported. |
| 954 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 954 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 955 | 955 | return ''; |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | ob_start(); |
| 959 | 959 | |
| 960 | 960 | // Subscription Active Price |
| 961 | - $initial_payment = self::get_subscription_price_meta( array( 'id' => $product_data->id, 'meta' => 'active' ) ); |
|
| 961 | + $initial_payment = self::get_subscription_price_meta(array('id' => $product_data->id, 'meta' => 'active')); |
|
| 962 | 962 | |
| 963 | 963 | // Free Trial ? |
| 964 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
| 964 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
| 965 | 965 | |
| 966 | 966 | // If there is a free trial then the initial payment is Zero. |
| 967 | - if ( $trial_length > 0 ) { |
|
| 967 | + if ($trial_length > 0) { |
|
| 968 | 968 | $initial_payment = 0; |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | // Sign up fee ? |
| 972 | - $sign_up_fee = self::get_subscription_sign_up_fee( array( 'id' => $product_data->id, 'raw' => true ) ); |
|
| 972 | + $sign_up_fee = self::get_subscription_sign_up_fee(array('id' => $product_data->id, 'raw' => true)); |
|
| 973 | 973 | |
| 974 | 974 | // Apply the sign up fee if it exists. |
| 975 | - if ( !empty( $sign_up_fee ) && $sign_up_fee > 0 ) { |
|
| 975 | + if ( ! empty($sign_up_fee) && $sign_up_fee > 0) { |
|
| 976 | 976 | |
| 977 | - if ( ! $atts['total'] ) { |
|
| 978 | - $initial_payment = sprintf( __( '%s with a %s sign up fee.', WCSS::TEXT_DOMAIN ), wc_price( $initial_payment ), wc_price( $sign_up_fee ) ); |
|
| 977 | + if ( ! $atts[ 'total' ]) { |
|
| 978 | + $initial_payment = sprintf(__('%s with a %s sign up fee.', WCSS::TEXT_DOMAIN), wc_price($initial_payment), wc_price($sign_up_fee)); |
|
| 979 | 979 | } else { |
| 980 | - $initial_payment = round( ( double ) $initial_payment+$sign_up_fee, wc_get_price_decimals() ); |
|
| 980 | + $initial_payment = round((double) $initial_payment + $sign_up_fee, wc_get_price_decimals()); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | } |
| 984 | 984 | |
| 985 | 985 | // Convert number into a price tag. |
| 986 | - if ( is_numeric( $initial_payment ) ) { |
|
| 987 | - $initial_payment = wc_price( $initial_payment ); |
|
| 986 | + if (is_numeric($initial_payment)) { |
|
| 987 | + $initial_payment = wc_price($initial_payment); |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | // Clean the price tag. |
| 991 | - $initial_payment = self::clean_wc_price( $initial_payment ); |
|
| 991 | + $initial_payment = self::clean_wc_price($initial_payment); |
|
| 992 | 992 | |
| 993 | 993 | echo $initial_payment; |
| 994 | 994 | |
@@ -1001,11 +1001,11 @@ discard block |
||
| 1001 | 1001 | * @param $product_types |
| 1002 | 1002 | * @return array |
| 1003 | 1003 | */ |
| 1004 | - public static function support_product_types_for_wc_satt( $product_types ) { |
|
| 1004 | + public static function support_product_types_for_wc_satt($product_types) { |
|
| 1005 | 1005 | // Only add the product types from the WooCommerce extension "Subscribe to All the Things" if it is active. |
| 1006 | - if ( class_exists( 'WCS_ATT' ) ) { |
|
| 1006 | + if (class_exists('WCS_ATT')) { |
|
| 1007 | 1007 | $satt_product_types = WCS_ATT()->get_supported_product_types(); |
| 1008 | - $product_types = array_merge( $satt_product_types, $product_types ); |
|
| 1008 | + $product_types = array_merge($satt_product_types, $product_types); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | return $product_types; |
@@ -1019,10 +1019,10 @@ discard block |
||
| 1019 | 1019 | * @global $woocommerce |
| 1020 | 1020 | * @return string |
| 1021 | 1021 | */ |
| 1022 | - public static function clean_wc_price( $price ) { |
|
| 1022 | + public static function clean_wc_price($price) { |
|
| 1023 | 1023 | global $woocommerce; |
| 1024 | 1024 | |
| 1025 | - if ( version_compare( $woocommerce->version, '2.6.0' ) >= 0 ) { |
|
| 1025 | + if (version_compare($woocommerce->version, '2.6.0') >= 0) { |
|
| 1026 | 1026 | |
| 1027 | 1027 | $find = array( |
| 1028 | 1028 | '<span class="woocommerce-Price-amount amount">', |
@@ -1030,8 +1030,8 @@ discard block |
||
| 1030 | 1030 | '</span>' |
| 1031 | 1031 | ); |
| 1032 | 1032 | |
| 1033 | - foreach( $find as $remove ) { |
|
| 1034 | - $price = str_replace( $remove, '', $price ); |
|
| 1033 | + foreach ($find as $remove) { |
|
| 1034 | + $price = str_replace($remove, '', $price); |
|
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | } |
@@ -1047,25 +1047,25 @@ discard block |
||
| 1047 | 1047 | * @param int $product_id The product/post ID of the subscription |
| 1048 | 1048 | * @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). |
| 1049 | 1049 | */ |
| 1050 | - public static function get_trial_expiration_date( $product_id, $from_date = '' ) { |
|
| 1051 | - $trial_expiration_date = WC_Subscriptions_Product::get_trial_expiration_date( $product_id, $from_date ); |
|
| 1050 | + public static function get_trial_expiration_date($product_id, $from_date = '') { |
|
| 1051 | + $trial_expiration_date = WC_Subscriptions_Product::get_trial_expiration_date($product_id, $from_date); |
|
| 1052 | 1052 | |
| 1053 | 1053 | // If returned empty then try alternative. |
| 1054 | - if ( empty( $trial_expiration_date ) ) { |
|
| 1054 | + if (empty($trial_expiration_date)) { |
|
| 1055 | 1055 | |
| 1056 | - $trial_period = self::get_subscription_trial_period( array( 'id' => $product_id, 'raw' => true ) ); |
|
| 1057 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_id ) ); |
|
| 1056 | + $trial_period = self::get_subscription_trial_period(array('id' => $product_id, 'raw' => true)); |
|
| 1057 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_id)); |
|
| 1058 | 1058 | |
| 1059 | - if ( $trial_length > 0 ) { |
|
| 1059 | + if ($trial_length > 0) { |
|
| 1060 | 1060 | |
| 1061 | - if ( empty( $from_date ) ) { |
|
| 1062 | - $from_date = gmdate( 'Y-m-d H:i:s' ); |
|
| 1061 | + if (empty($from_date)) { |
|
| 1062 | + $from_date = gmdate('Y-m-d H:i:s'); |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | - if ( 'month' == $trial_period ) { |
|
| 1066 | - $trial_expiration_date = date( 'Y-m-d H:i:s', wcs_add_months( strtotime( $from_date ), $trial_length ) ); |
|
| 1065 | + if ('month' == $trial_period) { |
|
| 1066 | + $trial_expiration_date = date('Y-m-d H:i:s', wcs_add_months(strtotime($from_date), $trial_length)); |
|
| 1067 | 1067 | } else { // Safe to just add the billing periods |
| 1068 | - $trial_expiration_date = date( 'Y-m-d H:i:s', strtotime( "+ {$trial_length} {$trial_period}s", strtotime( $from_date ) ) ); |
|
| 1068 | + $trial_expiration_date = date('Y-m-d H:i:s', strtotime("+ {$trial_length} {$trial_period}s", strtotime($from_date))); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | } else { |