@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | 'subscription_initial_payment' => 'get_subscription_initial', |
| 26 | 26 | ); |
| 27 | 27 | |
| 28 | - foreach ( $shortcodes as $shortcode => $function ) { |
|
| 29 | - add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), array( __CLASS__, $function ) ); |
|
| 28 | + foreach ($shortcodes as $shortcode => $function) { |
|
| 29 | + add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), array(__CLASS__, $function)); |
|
| 30 | 30 | } // END foreach() |
| 31 | 31 | |
| 32 | 32 | // Adds support for product types that have subscription scheme options. |
| 33 | - add_filter( 'woocommerce_is_subscription', array( __CLASS__, 'force_is_subscription' ), 10, 3 ); |
|
| 33 | + add_filter('woocommerce_is_subscription', array(__CLASS__, 'force_is_subscription'), 10, 3); |
|
| 34 | 34 | |
| 35 | 35 | // Adds alternative subscription price from the WooCommerce extension "Subscribe to All the Things" and returns the lowest scheme price. |
| 36 | - add_action( 'woocommerce_subscriptions_shortcode_get_price', array( __CLASS__, 'get_satt_lowest_price' ), 10, 1 ); |
|
| 36 | + add_action('woocommerce_subscriptions_shortcode_get_price', array(__CLASS__, 'get_satt_lowest_price'), 10, 1); |
|
| 37 | 37 | } // END init() |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | * @return array |
| 45 | 45 | */ |
| 46 | 46 | public static function get_supported_product_types() { |
| 47 | - return apply_filters( 'wcss_product_types', array( |
|
| 47 | + return apply_filters('wcss_product_types', array( |
|
| 48 | 48 | 'subscription', |
| 49 | 49 | 'subscription-variation', |
| 50 | - ) ); |
|
| 50 | + )); |
|
| 51 | 51 | } // END get_supported_product_types() |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -58,15 +58,15 @@ discard block |
||
| 58 | 58 | * @param object $product |
| 59 | 59 | * @return bool |
| 60 | 60 | */ |
| 61 | - public static function force_is_subscription( $is_subscription, $product_id, $product ) { |
|
| 62 | - if ( is_object( $product ) ) { |
|
| 61 | + public static function force_is_subscription($is_subscription, $product_id, $product) { |
|
| 62 | + if (is_object($product)) { |
|
| 63 | 63 | $product = $product; |
| 64 | - } elseif ( is_numeric( $product_id ) ) { |
|
| 65 | - $product = wc_get_product( $product_id ); |
|
| 64 | + } elseif (is_numeric($product_id)) { |
|
| 65 | + $product = wc_get_product($product_id); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if ( in_array( $product->product_type, self::get_supported_product_types() ) ) { |
|
| 69 | - if ( class_exists( 'WCS_ATT_Schemes' ) && WCS_ATT_Schemes::get_product_subscription_schemes( $product ) ) { |
|
| 68 | + if (in_array($product->product_type, self::get_supported_product_types())) { |
|
| 69 | + if (class_exists('WCS_ATT_Schemes') && WCS_ATT_Schemes::get_product_subscription_schemes($product)) { |
|
| 70 | 70 | $is_subscription = true; |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -80,15 +80,15 @@ discard block |
||
| 80 | 80 | * @param WC_Product $product |
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | - public static function get_price( $product ) { |
|
| 84 | - if ( WC_Subscriptions_Product::get_price( $product->id ) > 0 ) { |
|
| 83 | + public static function get_price($product) { |
|
| 84 | + if (WC_Subscriptions_Product::get_price($product->id) > 0) { |
|
| 85 | 85 | |
| 86 | - return ecs_html( WC_Subscriptions_Product::get_price( $product->id, array( |
|
| 86 | + return ecs_html(WC_Subscriptions_Product::get_price($product->id, array( |
|
| 87 | 87 | 'subscription_period' => false, |
| 88 | 88 | 'subscription_length' => false, |
| 89 | 89 | 'sign_up_fee' => false, |
| 90 | 90 | 'trial_length' => false, |
| 91 | - ) ) ); |
|
| 91 | + ))); |
|
| 92 | 92 | |
| 93 | 93 | } else { |
| 94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * hooked: get_satt_lowest_price - 10 |
| 99 | 99 | */ |
| 100 | - do_action( 'woocommerce_subscriptions_shortcode_get_price', $product ); |
|
| 100 | + do_action('woocommerce_subscriptions_shortcode_get_price', $product); |
|
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | } // END get_price() |
@@ -108,37 +108,37 @@ discard block |
||
| 108 | 108 | * @param WC_Product $product |
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | - public static function get_satt_lowest_price( $product ) { |
|
| 112 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 113 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product ); |
|
| 111 | + public static function get_satt_lowest_price($product) { |
|
| 112 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 113 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product); |
|
| 114 | 114 | |
| 115 | - $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product, $product_level_schemes ); |
|
| 115 | + $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product, $product_level_schemes); |
|
| 116 | 116 | |
| 117 | 117 | // Override price? |
| 118 | - $override = $lowest_scheme['scheme']['subscription_pricing_method']; |
|
| 118 | + $override = $lowest_scheme[ 'scheme' ][ 'subscription_pricing_method' ]; |
|
| 119 | 119 | |
| 120 | 120 | // Discount? |
| 121 | - $discount = $lowest_scheme['scheme']['subscription_discount']; |
|
| 121 | + $discount = $lowest_scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
| 122 | 122 | |
| 123 | 123 | // Prices |
| 124 | 124 | $prices = array( |
| 125 | - 'price' => $lowest_scheme['price'], |
|
| 126 | - 'regular_price' => $lowest_scheme['regular_price'], |
|
| 127 | - 'sale_price' => $lowest_scheme['sale_price'], |
|
| 128 | - 'subscription_price' => $lowest_scheme['scheme']['subscription_price'], |
|
| 129 | - 'subscription_regular_price' => $lowest_scheme['scheme']['subscription_regular_price'], |
|
| 130 | - 'subscription_sale_price' => $lowest_scheme['scheme']['subscription_sale_price'] |
|
| 125 | + 'price' => $lowest_scheme[ 'price' ], |
|
| 126 | + 'regular_price' => $lowest_scheme[ 'regular_price' ], |
|
| 127 | + 'sale_price' => $lowest_scheme[ 'sale_price' ], |
|
| 128 | + 'subscription_price' => $lowest_scheme[ 'scheme' ][ 'subscription_price' ], |
|
| 129 | + 'subscription_regular_price' => $lowest_scheme[ 'scheme' ][ 'subscription_regular_price' ], |
|
| 130 | + 'subscription_sale_price' => $lowest_scheme[ 'scheme' ][ 'subscription_sale_price' ] |
|
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | 133 | // Prepare the price |
| 134 | 134 | $price = ''; |
| 135 | 135 | |
| 136 | - if ( $override === 'inherit' && ! empty( $discount ) && $prices[ 'price' ] > 0 ) { |
|
| 137 | - $price = empty( $discount ) ? $price : ( empty( $prices[ 'regular_price' ] ) ? $prices[ 'regular_price' ] : round( ( double ) $prices[ 'regular_price' ] * ( 100 - $discount ) / 100, wc_get_price_decimals() ) ); |
|
| 136 | + if ($override === 'inherit' && ! empty($discount) && $prices[ 'price' ] > 0) { |
|
| 137 | + $price = empty($discount) ? $price : (empty($prices[ 'regular_price' ]) ? $prices[ 'regular_price' ] : round((double) $prices[ 'regular_price' ] * (100 - $discount) / 100, wc_get_price_decimals())); |
|
| 138 | 138 | } else { |
| 139 | - $price = $prices['subscription_price']; |
|
| 139 | + $price = $prices[ 'subscription_price' ]; |
|
| 140 | 140 | |
| 141 | - if ( $prices[ 'subscription_price' ] < $prices[ 'subscription_regular_price' ] ) { |
|
| 141 | + if ($prices[ 'subscription_price' ] < $prices[ 'subscription_regular_price' ]) { |
|
| 142 | 142 | $price = $prices[ 'subscription_sale_price' ]; |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | * @param array $atts |
| 157 | 157 | * @return string |
| 158 | 158 | */ |
| 159 | - public static function get_subscription_price( $atts ) { |
|
| 159 | + public static function get_subscription_price($atts) { |
|
| 160 | 160 | global $wpdb, $post; |
| 161 | 161 | |
| 162 | - $defaults = shortcode_atts( array( |
|
| 162 | + $defaults = shortcode_atts(array( |
|
| 163 | 163 | 'id' => '', |
| 164 | 164 | 'sku' => '', |
| 165 | 165 | 'period' => false, |
@@ -168,47 +168,47 @@ discard block |
||
| 168 | 168 | 'trial_length' => false, |
| 169 | 169 | 'before_price' => '', |
| 170 | 170 | 'after_price' => '', |
| 171 | - ), $atts ); |
|
| 171 | + ), $atts); |
|
| 172 | 172 | |
| 173 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 173 | + $atts = wp_parse_args($atts, $defaults); |
|
| 174 | 174 | |
| 175 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 176 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 177 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 178 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 179 | - $product_data = get_post( $product_id ); |
|
| 175 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 176 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 177 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 178 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 179 | + $product_data = get_post($product_id); |
|
| 180 | 180 | } else { |
| 181 | - $product_data = wc_get_product( $post->ID ); |
|
| 181 | + $product_data = wc_get_product($post->ID); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // Check that the product type is supported. Return blank if not supported. |
| 185 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 185 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 186 | 186 | return ''; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | ob_start(); |
| 190 | 190 | |
| 191 | - $price_html = WC_Subscriptions_Product::get_price_string( $product_data->id, array( |
|
| 192 | - 'price' => self::get_price( $product_data ), |
|
| 193 | - 'subscription_period' => isset( $atts['period'] ) ? $atts['period'] : true, |
|
| 194 | - 'subscription_length' => isset( $atts['length'] ) ? $atts['length'] : true, |
|
| 195 | - 'sign_up_fee' => isset( $atts['sign_up_fee'] ) ? $atts['sign_up_fee'] : true, |
|
| 196 | - 'trial_length' => isset( $atts['trial_length'] ) ? $atts['trial_length'] : true, |
|
| 197 | - ) ); |
|
| 191 | + $price_html = WC_Subscriptions_Product::get_price_string($product_data->id, array( |
|
| 192 | + 'price' => self::get_price($product_data), |
|
| 193 | + 'subscription_period' => isset($atts[ 'period' ]) ? $atts[ 'period' ] : true, |
|
| 194 | + 'subscription_length' => isset($atts[ 'length' ]) ? $atts[ 'length' ] : true, |
|
| 195 | + 'sign_up_fee' => isset($atts[ 'sign_up_fee' ]) ? $atts[ 'sign_up_fee' ] : true, |
|
| 196 | + 'trial_length' => isset($atts[ 'trial_length' ]) ? $atts[ 'trial_length' ] : true, |
|
| 197 | + )); |
|
| 198 | 198 | |
| 199 | 199 | // Clean the subscription price wrapper. |
| 200 | 200 | $price_html = str_replace('<span class="subscription-details">', '', $price_html); |
| 201 | 201 | $price_html = str_replace('</span">', '', $price_html); |
| 202 | 202 | |
| 203 | 203 | // Trim the whitespace. |
| 204 | - $price_html = trim( $price_html ); |
|
| 204 | + $price_html = trim($price_html); |
|
| 205 | 205 | |
| 206 | 206 | // Convert to Price Tag. |
| 207 | - $price_html = wc_price( $price_html ); |
|
| 207 | + $price_html = wc_price($price_html); |
|
| 208 | 208 | |
| 209 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $price_html, $atts['after_price'] ); |
|
| 209 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $price_html, $atts[ 'after_price' ]); |
|
| 210 | 210 | |
| 211 | - echo html_entity_decode( $price_html ); |
|
| 211 | + echo html_entity_decode($price_html); |
|
| 212 | 212 | |
| 213 | 213 | return ob_get_clean(); |
| 214 | 214 | } // END get_subscription_price() |
@@ -221,27 +221,27 @@ discard block |
||
| 221 | 221 | * @param array $atts |
| 222 | 222 | * @return string |
| 223 | 223 | */ |
| 224 | - public static function get_subscription_discount( $atts ) { |
|
| 224 | + public static function get_subscription_discount($atts) { |
|
| 225 | 225 | global $wpdb, $post; |
| 226 | 226 | |
| 227 | - $defaults = shortcode_atts( array( |
|
| 227 | + $defaults = shortcode_atts(array( |
|
| 228 | 228 | 'id' => '', |
| 229 | 229 | 'sku' => '', |
| 230 | - ), $atts ); |
|
| 230 | + ), $atts); |
|
| 231 | 231 | |
| 232 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 232 | + $atts = wp_parse_args($atts, $defaults); |
|
| 233 | 233 | |
| 234 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 235 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 236 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 237 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 238 | - $product_data = get_post( $product_id ); |
|
| 234 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 235 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 236 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 237 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 238 | + $product_data = get_post($product_id); |
|
| 239 | 239 | } else { |
| 240 | - $product_data = wc_get_product( $post->ID ); |
|
| 240 | + $product_data = wc_get_product($post->ID); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Check that the product type is supported. Return blank if not supported. |
| 244 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 244 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 245 | 245 | return ''; |
| 246 | 246 | } |
| 247 | 247 | |
@@ -250,16 +250,16 @@ discard block |
||
| 250 | 250 | $discount = ''; // Returns empty by default. |
| 251 | 251 | |
| 252 | 252 | // Get Subscription Discount |
| 253 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 254 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product_data ); |
|
| 253 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 254 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product_data); |
|
| 255 | 255 | |
| 256 | - $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product_data, $product_level_schemes ); |
|
| 256 | + $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product_data, $product_level_schemes); |
|
| 257 | 257 | |
| 258 | - $discount = $lowest_scheme['scheme']['subscription_discount']; |
|
| 258 | + $discount = $lowest_scheme[ 'scheme' ][ 'subscription_discount' ]; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ( ! empty( $discount ) && is_numeric( $discount ) ) { |
|
| 262 | - echo sprintf( __( '%s%s %s', WCSS::TEXT_DOMAIN ), $discount, '%', apply_filters( 'wcs_shortcodes_sub_discount_string', __( 'discount', WCSS::TEXT_DOMAIN ) ) ); |
|
| 261 | + if ( ! empty($discount) && is_numeric($discount)) { |
|
| 262 | + echo sprintf(__('%s%s %s', WCSS::TEXT_DOMAIN), $discount, '%', apply_filters('wcs_shortcodes_sub_discount_string', __('discount', WCSS::TEXT_DOMAIN))); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | return ob_get_clean(); |
@@ -271,49 +271,49 @@ discard block |
||
| 271 | 271 | * @param array $atts |
| 272 | 272 | * @return string |
| 273 | 273 | */ |
| 274 | - public static function get_subscription_period( $atts ) { |
|
| 274 | + public static function get_subscription_period($atts) { |
|
| 275 | 275 | global $wpdb, $post; |
| 276 | 276 | |
| 277 | - $defaults = shortcode_atts( array( |
|
| 277 | + $defaults = shortcode_atts(array( |
|
| 278 | 278 | 'id' => '', |
| 279 | 279 | 'sku' => '', |
| 280 | 280 | 'just_period' => true |
| 281 | - ), $atts ); |
|
| 281 | + ), $atts); |
|
| 282 | 282 | |
| 283 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 283 | + $atts = wp_parse_args($atts, $defaults); |
|
| 284 | 284 | |
| 285 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 286 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 287 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 288 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 289 | - $product_data = get_post( $product_id ); |
|
| 285 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 286 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 287 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 288 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 289 | + $product_data = get_post($product_id); |
|
| 290 | 290 | } else { |
| 291 | - $product_data = wc_get_product( $post->ID ); |
|
| 291 | + $product_data = wc_get_product($post->ID); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | // Check that the product type is supported. Return blank if not supported. |
| 295 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 295 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 296 | 296 | return ''; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | ob_start(); |
| 300 | 300 | |
| 301 | 301 | // Get Subscription Period |
| 302 | - $period = WC_Subscriptions_Product::get_period( $product_data ); |
|
| 302 | + $period = WC_Subscriptions_Product::get_period($product_data); |
|
| 303 | 303 | |
| 304 | 304 | // If the period is empty, look for alternative. |
| 305 | - if ( empty( $period ) ) { |
|
| 306 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 307 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product_data ); |
|
| 305 | + if (empty($period)) { |
|
| 306 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 307 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product_data); |
|
| 308 | 308 | |
| 309 | - $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product_data, $product_level_schemes ); |
|
| 309 | + $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product_data, $product_level_schemes); |
|
| 310 | 310 | |
| 311 | - $period = $lowest_scheme['scheme']['subscription_period']; |
|
| 311 | + $period = $lowest_scheme[ 'scheme' ][ 'subscription_period' ]; |
|
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - if ( $atts['just_period'] ) { |
|
| 316 | - $period = sprintf( __( 'Per %s', WCSS::TEXT_DOMAIN ), $period ); |
|
| 315 | + if ($atts[ 'just_period' ]) { |
|
| 316 | + $period = sprintf(__('Per %s', WCSS::TEXT_DOMAIN), $period); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | echo ucwords($period); |
@@ -327,43 +327,43 @@ discard block |
||
| 327 | 327 | * @param array $atts |
| 328 | 328 | * @return string |
| 329 | 329 | */ |
| 330 | - public static function get_subscription_period_interval( $atts ) { |
|
| 330 | + public static function get_subscription_period_interval($atts) { |
|
| 331 | 331 | global $wpdb, $post; |
| 332 | 332 | |
| 333 | - $defaults = shortcode_atts( array( |
|
| 333 | + $defaults = shortcode_atts(array( |
|
| 334 | 334 | 'id' => '', |
| 335 | 335 | 'sku' => '', |
| 336 | - ), $atts ); |
|
| 336 | + ), $atts); |
|
| 337 | 337 | |
| 338 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 338 | + $atts = wp_parse_args($atts, $defaults); |
|
| 339 | 339 | |
| 340 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 341 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 342 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 343 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 344 | - $product_data = get_post( $product_id ); |
|
| 340 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 341 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 342 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 343 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 344 | + $product_data = get_post($product_id); |
|
| 345 | 345 | } else { |
| 346 | - $product_data = wc_get_product( $post->ID ); |
|
| 346 | + $product_data = wc_get_product($post->ID); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // Check that the product type is supported. Return blank if not supported. |
| 350 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 350 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 351 | 351 | return ''; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | ob_start(); |
| 355 | 355 | |
| 356 | 356 | // Get Subscription Period Interval |
| 357 | - $period_interval = WC_Subscriptions_Product::get_interval( $product_data ); |
|
| 357 | + $period_interval = WC_Subscriptions_Product::get_interval($product_data); |
|
| 358 | 358 | |
| 359 | 359 | // If the period is empty, look for alternative. |
| 360 | - if ( empty( $period_interval ) ) { |
|
| 361 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 362 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product_data ); |
|
| 360 | + if (empty($period_interval)) { |
|
| 361 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 362 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product_data); |
|
| 363 | 363 | |
| 364 | - $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product_data, $product_level_schemes ); |
|
| 364 | + $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product_data, $product_level_schemes); |
|
| 365 | 365 | |
| 366 | - $period_interval = $lowest_scheme['scheme']['subscription_period_interval']; |
|
| 366 | + $period_interval = $lowest_scheme[ 'scheme' ][ 'subscription_period_interval' ]; |
|
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | |
@@ -378,49 +378,49 @@ discard block |
||
| 378 | 378 | * @param array $atts |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | - public static function get_subscription_length( $atts ) { |
|
| 381 | + public static function get_subscription_length($atts) { |
|
| 382 | 382 | global $wpdb, $post; |
| 383 | 383 | |
| 384 | - $defaults = shortcode_atts( array( |
|
| 384 | + $defaults = shortcode_atts(array( |
|
| 385 | 385 | 'id' => '', |
| 386 | 386 | 'sku' => '', |
| 387 | - ), $atts ); |
|
| 387 | + ), $atts); |
|
| 388 | 388 | |
| 389 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 389 | + $atts = wp_parse_args($atts, $defaults); |
|
| 390 | 390 | |
| 391 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 392 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 393 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 394 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 395 | - $product_data = get_post( $product_id ); |
|
| 391 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 392 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 393 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 394 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 395 | + $product_data = get_post($product_id); |
|
| 396 | 396 | } else { |
| 397 | - $product_data = wc_get_product( $post->ID ); |
|
| 397 | + $product_data = wc_get_product($post->ID); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // Check that the product type is supported. Return blank if not supported. |
| 401 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 401 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 402 | 402 | return ''; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | ob_start(); |
| 406 | 406 | |
| 407 | 407 | // Get Subscription Length |
| 408 | - $length = WC_Subscriptions_Product::get_length( $product_data ); |
|
| 408 | + $length = WC_Subscriptions_Product::get_length($product_data); |
|
| 409 | 409 | |
| 410 | 410 | // If the length is empty, look for alternative. |
| 411 | - if ( empty( $length ) ) { |
|
| 412 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 413 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product_data ); |
|
| 411 | + if (empty($length)) { |
|
| 412 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 413 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product_data); |
|
| 414 | 414 | |
| 415 | - $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product_data, $product_level_schemes ); |
|
| 415 | + $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product_data, $product_level_schemes); |
|
| 416 | 416 | |
| 417 | - $period = self::get_subscription_period( array( 'id' => $product_data->id, 'just_period' => false ) ); |
|
| 418 | - $length = $lowest_scheme['scheme']['subscription_length']; |
|
| 417 | + $period = self::get_subscription_period(array('id' => $product_data->id, 'just_period' => false)); |
|
| 418 | + $length = $lowest_scheme[ 'scheme' ][ 'subscription_length' ]; |
|
| 419 | 419 | |
| 420 | - if ( $length > 0 ) { |
|
| 421 | - $length = sprintf( '%s %s', $length, $period ); |
|
| 420 | + if ($length > 0) { |
|
| 421 | + $length = sprintf('%s %s', $length, $period); |
|
| 422 | 422 | } else { |
| 423 | - $length = sprintf( __( 'Every %s', WCSS::TEXT_DOMAIN ), $period ); |
|
| 423 | + $length = sprintf(__('Every %s', WCSS::TEXT_DOMAIN), $period); |
|
| 424 | 424 | } |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -436,56 +436,56 @@ discard block |
||
| 436 | 436 | * @param array $atts |
| 437 | 437 | * @return string |
| 438 | 438 | */ |
| 439 | - public static function get_subscription_sign_up_fee( $atts ) { |
|
| 439 | + public static function get_subscription_sign_up_fee($atts) { |
|
| 440 | 440 | global $wpdb, $post; |
| 441 | 441 | |
| 442 | - $defaults = shortcode_atts( array( |
|
| 442 | + $defaults = shortcode_atts(array( |
|
| 443 | 443 | 'id' => '', |
| 444 | 444 | 'sku' => '', |
| 445 | 445 | 'before_price' => '', |
| 446 | 446 | 'after_price' => '', |
| 447 | - ), $atts ); |
|
| 447 | + ), $atts); |
|
| 448 | 448 | |
| 449 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 449 | + $atts = wp_parse_args($atts, $defaults); |
|
| 450 | 450 | |
| 451 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 452 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 453 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 454 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 455 | - $product_data = get_post( $product_id ); |
|
| 451 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 452 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 453 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 454 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 455 | + $product_data = get_post($product_id); |
|
| 456 | 456 | } else { |
| 457 | - $product_data = wc_get_product( $post->ID ); |
|
| 457 | + $product_data = wc_get_product($post->ID); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // Check that the product type is supported. Return blank if not supported. |
| 461 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 461 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 462 | 462 | return ''; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | ob_start(); |
| 466 | 466 | |
| 467 | 467 | // Get Subscription Sign Up Fee |
| 468 | - $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product_data ); |
|
| 468 | + $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product_data); |
|
| 469 | 469 | |
| 470 | 470 | // If the sign up fee is empty, look for alternative. |
| 471 | - if ( empty( $sign_up_fee ) ) { |
|
| 472 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 473 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product_data ); |
|
| 471 | + if (empty($sign_up_fee)) { |
|
| 472 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 473 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product_data); |
|
| 474 | 474 | |
| 475 | - $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product_data, $product_level_schemes ); |
|
| 475 | + $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product_data, $product_level_schemes); |
|
| 476 | 476 | |
| 477 | - $sign_up_fee = $lowest_scheme['scheme']['subscription_sign_up_fee']; |
|
| 477 | + $sign_up_fee = $lowest_scheme[ 'scheme' ][ 'subscription_sign_up_fee' ]; |
|
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | // Convert number into a price tag. |
| 482 | - if ( is_numeric( $sign_up_fee ) ) { |
|
| 483 | - $sign_up_fee = wc_price( $sign_up_fee ); |
|
| 482 | + if (is_numeric($sign_up_fee)) { |
|
| 483 | + $sign_up_fee = wc_price($sign_up_fee); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - $price_html = sprintf( __( '%s%s%s', WCSS::TEXT_DOMAIN ), $atts['before_price'], $sign_up_fee, $atts['after_price'] ); |
|
| 486 | + $price_html = sprintf(__('%s%s%s', WCSS::TEXT_DOMAIN), $atts[ 'before_price' ], $sign_up_fee, $atts[ 'after_price' ]); |
|
| 487 | 487 | |
| 488 | - echo html_entity_decode( $price_html ); |
|
| 488 | + echo html_entity_decode($price_html); |
|
| 489 | 489 | |
| 490 | 490 | return ob_get_clean(); |
| 491 | 491 | } // END get_subscription_sign_up_fee() |
@@ -496,43 +496,43 @@ discard block |
||
| 496 | 496 | * @param array $atts |
| 497 | 497 | * @return string |
| 498 | 498 | */ |
| 499 | - public static function get_subscription_trial_length( $atts ) { |
|
| 499 | + public static function get_subscription_trial_length($atts) { |
|
| 500 | 500 | global $wpdb, $post; |
| 501 | 501 | |
| 502 | - $defaults = shortcode_atts( array( |
|
| 502 | + $defaults = shortcode_atts(array( |
|
| 503 | 503 | 'id' => '', |
| 504 | 504 | 'sku' => '', |
| 505 | - ), $atts ); |
|
| 505 | + ), $atts); |
|
| 506 | 506 | |
| 507 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 507 | + $atts = wp_parse_args($atts, $defaults); |
|
| 508 | 508 | |
| 509 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 510 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 511 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 512 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 513 | - $product_data = get_post( $product_id ); |
|
| 509 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 510 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 511 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 512 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 513 | + $product_data = get_post($product_id); |
|
| 514 | 514 | } else { |
| 515 | - $product_data = wc_get_product( $post->ID ); |
|
| 515 | + $product_data = wc_get_product($post->ID); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // Check that the product type is supported. Return blank if not supported. |
| 519 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 519 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 520 | 520 | return ''; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | ob_start(); |
| 524 | 524 | |
| 525 | 525 | // Get Subscription Trial Length |
| 526 | - $trial_length = WC_Subscriptions_Product::get_trial_length( $product_data ); |
|
| 526 | + $trial_length = WC_Subscriptions_Product::get_trial_length($product_data); |
|
| 527 | 527 | |
| 528 | 528 | // If the trial length is empty, look for alternative. |
| 529 | - if ( empty( $trial_length ) ) { |
|
| 530 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 531 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product_data ); |
|
| 529 | + if (empty($trial_length)) { |
|
| 530 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 531 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product_data); |
|
| 532 | 532 | |
| 533 | - $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product_data, $product_level_schemes ); |
|
| 533 | + $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product_data, $product_level_schemes); |
|
| 534 | 534 | |
| 535 | - $trial_length = $lowest_scheme['scheme']['subscription_trial_length']; |
|
| 535 | + $trial_length = $lowest_scheme[ 'scheme' ][ 'subscription_trial_length' ]; |
|
| 536 | 536 | } |
| 537 | 537 | } |
| 538 | 538 | |
@@ -547,47 +547,47 @@ discard block |
||
| 547 | 547 | * @param array $atts |
| 548 | 548 | * @return string |
| 549 | 549 | */ |
| 550 | - public static function get_subscription_trial_period( $atts ) { |
|
| 550 | + public static function get_subscription_trial_period($atts) { |
|
| 551 | 551 | global $wpdb, $post; |
| 552 | 552 | |
| 553 | - $defaults = shortcode_atts( array( |
|
| 553 | + $defaults = shortcode_atts(array( |
|
| 554 | 554 | 'id' => '', |
| 555 | 555 | 'sku' => '', |
| 556 | - ), $atts ); |
|
| 556 | + ), $atts); |
|
| 557 | 557 | |
| 558 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 558 | + $atts = wp_parse_args($atts, $defaults); |
|
| 559 | 559 | |
| 560 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 561 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 562 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 563 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 564 | - $product_data = get_post( $product_id ); |
|
| 560 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 561 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 562 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 563 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 564 | + $product_data = get_post($product_id); |
|
| 565 | 565 | } else { |
| 566 | - $product_data = wc_get_product( $post->ID ); |
|
| 566 | + $product_data = wc_get_product($post->ID); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | // Check that the product type is supported. Return blank if not supported. |
| 570 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 570 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 571 | 571 | return ''; |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | ob_start(); |
| 575 | 575 | |
| 576 | 576 | // Get Subscription Trial Period |
| 577 | - $trial_period = WC_Subscriptions_Product::get_trial_period( $product_data ); |
|
| 577 | + $trial_period = WC_Subscriptions_Product::get_trial_period($product_data); |
|
| 578 | 578 | |
| 579 | 579 | // If the trial period is empty, look for alternative. |
| 580 | - if ( empty( $trial_period ) ) { |
|
| 581 | - if ( class_exists( 'WCS_ATT_Schemes' ) && class_exists( 'WCS_ATT_Scheme_Prices' ) ) { |
|
| 582 | - $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes( $product_data ); |
|
| 580 | + if (empty($trial_period)) { |
|
| 581 | + if (class_exists('WCS_ATT_Schemes') && class_exists('WCS_ATT_Scheme_Prices')) { |
|
| 582 | + $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product_data); |
|
| 583 | 583 | |
| 584 | - $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data( $product_data, $product_level_schemes ); |
|
| 584 | + $lowest_scheme = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product_data, $product_level_schemes); |
|
| 585 | 585 | |
| 586 | - $trial_length = $lowest_scheme['scheme']['subscription_trial_length']; |
|
| 587 | - $trial_period = $lowest_scheme['scheme']['subscription_trial_period']; |
|
| 586 | + $trial_length = $lowest_scheme[ 'scheme' ][ 'subscription_trial_length' ]; |
|
| 587 | + $trial_period = $lowest_scheme[ 'scheme' ][ 'subscription_trial_period' ]; |
|
| 588 | 588 | |
| 589 | - if ( ! empty( $trial_length ) && $trial_length > 0 ) { |
|
| 590 | - $trial_period = sprintf( __( '%s%s', WCSS::TEXT_DOMAIN ), $trial_period, __( 's', WCSS::TEXT_DOMAIN ) ); |
|
| 589 | + if ( ! empty($trial_length) && $trial_length > 0) { |
|
| 590 | + $trial_period = sprintf(__('%s%s', WCSS::TEXT_DOMAIN), $trial_period, __('s', WCSS::TEXT_DOMAIN)); |
|
| 591 | 591 | } |
| 592 | 592 | } |
| 593 | 593 | } |
@@ -603,84 +603,84 @@ discard block |
||
| 603 | 603 | * @param array $atts |
| 604 | 604 | * @return string |
| 605 | 605 | */ |
| 606 | - public static function get_subscription_first_payment( $atts ) { |
|
| 606 | + public static function get_subscription_first_payment($atts) { |
|
| 607 | 607 | global $wpdb, $post; |
| 608 | 608 | |
| 609 | - $defaults = shortcode_atts( array( |
|
| 609 | + $defaults = shortcode_atts(array( |
|
| 610 | 610 | 'id' => '', |
| 611 | 611 | 'sku' => '', |
| 612 | 612 | 'show_time' => false, |
| 613 | 613 | 'from_date' => '', |
| 614 | 614 | 'timezone' => 'gmt', |
| 615 | 615 | 'format' => 'timestamp' |
| 616 | - ), $atts ); |
|
| 616 | + ), $atts); |
|
| 617 | 617 | |
| 618 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 618 | + $atts = wp_parse_args($atts, $defaults); |
|
| 619 | 619 | |
| 620 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 621 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 622 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 623 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 624 | - $product_data = get_post( $product_id ); |
|
| 620 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 621 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 622 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 623 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 624 | + $product_data = get_post($product_id); |
|
| 625 | 625 | } else { |
| 626 | - $product_data = wc_get_product( $post->ID ); |
|
| 626 | + $product_data = wc_get_product($post->ID); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | // Check that the product type is supported. Return blank if not supported. |
| 630 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 630 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 631 | 631 | return ''; |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | ob_start(); |
| 635 | 635 | |
| 636 | - $billing_interval = self::get_subscription_period_interval( array( 'id' => $product_data->id ) ); |
|
| 637 | - $billing_length = self::get_subscription_length( array( 'id' => $product_data->id ) ); |
|
| 638 | - $trial_length = self::get_subscription_trial_length( array( 'id' => $product_data->id ) ); |
|
| 636 | + $billing_interval = self::get_subscription_period_interval(array('id' => $product_data->id)); |
|
| 637 | + $billing_length = self::get_subscription_length(array('id' => $product_data->id)); |
|
| 638 | + $trial_length = self::get_subscription_trial_length(array('id' => $product_data->id)); |
|
| 639 | 639 | |
| 640 | - $from_date = $atts['from_date']; |
|
| 640 | + $from_date = $atts[ 'from_date' ]; |
|
| 641 | 641 | |
| 642 | - if ( $billing_interval != $billing_length || $trial_length > 0 ) { |
|
| 643 | - if ( empty( $from_date ) ) { |
|
| 644 | - $from_date = gmdate( 'Y-m-d H:i:s' ); |
|
| 642 | + if ($billing_interval != $billing_length || $trial_length > 0) { |
|
| 643 | + if (empty($from_date)) { |
|
| 644 | + $from_date = gmdate('Y-m-d H:i:s'); |
|
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | // If the subscription has a free trial period, the first renewal is the same as the expiration of the free trial |
| 648 | - if ( $trial_length > 0 ) { |
|
| 649 | - $first_renewal_timestamp = strtotime( WC_Subscriptions_Product::get_trial_expiration_date( $product_data->id, $from_date ) ); |
|
| 648 | + if ($trial_length > 0) { |
|
| 649 | + $first_renewal_timestamp = strtotime(WC_Subscriptions_Product::get_trial_expiration_date($product_data->id, $from_date)); |
|
| 650 | 650 | } else { |
| 651 | - $from_timestamp = strtotime( $from_date ); |
|
| 652 | - $billing_period = self::get_subscription_period( array( 'id' => $product_data->id ) ); |
|
| 651 | + $from_timestamp = strtotime($from_date); |
|
| 652 | + $billing_period = self::get_subscription_period(array('id' => $product_data->id)); |
|
| 653 | 653 | |
| 654 | - if ( 'month' == $billing_period ) { |
|
| 655 | - $first_renewal_timestamp = wcs_add_months( $from_timestamp, $billing_interval ); |
|
| 654 | + if ('month' == $billing_period) { |
|
| 655 | + $first_renewal_timestamp = wcs_add_months($from_timestamp, $billing_interval); |
|
| 656 | 656 | } else { |
| 657 | - $first_renewal_timestamp = strtotime( "+ $billing_interval {$billing_period}s", $from_timestamp ); |
|
| 657 | + $first_renewal_timestamp = strtotime("+ $billing_interval {$billing_period}s", $from_timestamp); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - if ( 'site' == $atts['timezone'] ) { |
|
| 661 | - $first_renewal_timestamp += ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
| 660 | + if ('site' == $atts[ 'timezone' ]) { |
|
| 661 | + $first_renewal_timestamp += (get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | 664 | } else { |
| 665 | 665 | $first_renewal_timestamp = 0; |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - if ( $first_renewal_timestamp > 0 ) { |
|
| 669 | - if ( $atts['show_time'] ) { |
|
| 670 | - if ( 'timestamp' == $atts['format'] ) { |
|
| 668 | + if ($first_renewal_timestamp > 0) { |
|
| 669 | + if ($atts[ 'show_time' ]) { |
|
| 670 | + if ('timestamp' == $atts[ 'format' ]) { |
|
| 671 | 671 | $date_format = 'Y-m-d H:i:s'; |
| 672 | 672 | } else { |
| 673 | 673 | $date_format = 'D jS M Y H:i A'; |
| 674 | 674 | } |
| 675 | 675 | } else { |
| 676 | - if ( 'timestamp' == $atts['format'] ) { |
|
| 676 | + if ('timestamp' == $atts[ 'format' ]) { |
|
| 677 | 677 | $date_format = 'Y-m-d'; |
| 678 | 678 | } else { |
| 679 | 679 | $date_format = 'D jS M Y'; |
| 680 | 680 | } |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | - $first_payment = date( $date_format, $first_renewal_timestamp ); |
|
| 683 | + $first_payment = date($date_format, $first_renewal_timestamp); |
|
| 684 | 684 | } else { |
| 685 | 685 | $first_payment = ''; |
| 686 | 686 | } |
@@ -696,27 +696,27 @@ discard block |
||
| 696 | 696 | * @param array $atts |
| 697 | 697 | * @return string |
| 698 | 698 | */ |
| 699 | - public static function get_subscription_initial( $atts ) { |
|
| 699 | + public static function get_subscription_initial($atts) { |
|
| 700 | 700 | global $wpdb, $post; |
| 701 | 701 | |
| 702 | - $defaults = shortcode_atts( array( |
|
| 702 | + $defaults = shortcode_atts(array( |
|
| 703 | 703 | 'id' => '', |
| 704 | 704 | 'sku' => '', |
| 705 | - ), $atts ); |
|
| 705 | + ), $atts); |
|
| 706 | 706 | |
| 707 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 707 | + $atts = wp_parse_args($atts, $defaults); |
|
| 708 | 708 | |
| 709 | - if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
|
| 710 | - $product_data = wc_get_product( $atts['id'] ); |
|
| 711 | - } elseif ( ! empty( $atts['sku'] ) ) { |
|
| 712 | - $product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
|
| 713 | - $product_data = get_post( $product_id ); |
|
| 709 | + if ( ! empty($atts[ 'id' ]) && $atts[ 'id' ] > 0) { |
|
| 710 | + $product_data = wc_get_product($atts[ 'id' ]); |
|
| 711 | + } elseif ( ! empty($atts[ 'sku' ])) { |
|
| 712 | + $product_id = wc_get_product_id_by_sku($atts[ 'sku' ]); |
|
| 713 | + $product_data = get_post($product_id); |
|
| 714 | 714 | } else { |
| 715 | - $product_data = wc_get_product( $post->ID ); |
|
| 715 | + $product_data = wc_get_product($post->ID); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | // Check that the product type is supported. Return blank if not supported. |
| 719 | - if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
|
| 719 | + if ( ! is_object($product_data) || ! in_array($product_data->product_type, self::get_supported_product_types())) { |
|
| 720 | 720 | return ''; |
| 721 | 721 | } |
| 722 | 722 | |