@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) { |
| 52 | 52 | $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id ); |
| 53 | - $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 53 | + $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 54 | 54 | return reset( $matching_group ); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | function getpaid_get_subscription( $subscription ) { |
| 65 | 65 | |
| 66 | - if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 67 | - $subscription = new WPInv_Subscription( $subscription ); |
|
| 68 | - } |
|
| 66 | + if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 67 | + $subscription = new WPInv_Subscription( $subscription ); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - return $subscription->exists() ? $subscription : false; |
|
| 70 | + return $subscription->exists() ? $subscription : false; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -81,28 +81,28 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
| 83 | 83 | |
| 84 | - // Do not retrieve all fields if we just want the count. |
|
| 85 | - if ( 'count' == $return ) { |
|
| 86 | - $args['fields'] = 'id'; |
|
| 87 | - $args['number'] = 1; |
|
| 88 | - } |
|
| 84 | + // Do not retrieve all fields if we just want the count. |
|
| 85 | + if ( 'count' == $return ) { |
|
| 86 | + $args['fields'] = 'id'; |
|
| 87 | + $args['number'] = 1; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - // Do not count all matches if we just want the results. |
|
| 91 | - if ( 'results' == $return ) { |
|
| 92 | - $args['count_total'] = false; |
|
| 93 | - } |
|
| 90 | + // Do not count all matches if we just want the results. |
|
| 91 | + if ( 'results' == $return ) { |
|
| 92 | + $args['count_total'] = false; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 95 | + $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 96 | 96 | |
| 97 | - if ( 'results' == $return ) { |
|
| 98 | - return $query->get_results(); |
|
| 99 | - } |
|
| 97 | + if ( 'results' == $return ) { |
|
| 98 | + return $query->get_results(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - if ( 'count' == $return ) { |
|
| 102 | - return $query->get_total(); |
|
| 103 | - } |
|
| 101 | + if ( 'count' == $return ) { |
|
| 102 | + return $query->get_total(); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $query; |
|
| 105 | + return $query; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -112,18 +112,18 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | function getpaid_get_subscription_statuses() { |
| 114 | 114 | |
| 115 | - return apply_filters( |
|
| 116 | - 'getpaid_get_subscription_statuses', |
|
| 117 | - array( |
|
| 118 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
| 119 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 120 | - 'active' => __( 'Active', 'invoicing' ), |
|
| 121 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
| 122 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 123 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
| 124 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 125 | - ) |
|
| 126 | - ); |
|
| 115 | + return apply_filters( |
|
| 116 | + 'getpaid_get_subscription_statuses', |
|
| 117 | + array( |
|
| 118 | + 'pending' => __( 'Pending', 'invoicing' ), |
|
| 119 | + 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 120 | + 'active' => __( 'Active', 'invoicing' ), |
|
| 121 | + 'failing' => __( 'Failing', 'invoicing' ), |
|
| 122 | + 'expired' => __( 'Expired', 'invoicing' ), |
|
| 123 | + 'completed' => __( 'Complete', 'invoicing' ), |
|
| 124 | + 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 125 | + ) |
|
| 126 | + ); |
|
| 127 | 127 | |
| 128 | 128 | } |
| 129 | 129 | |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | 135 | function getpaid_get_subscription_status_label( $status ) { |
| 136 | - $statuses = getpaid_get_subscription_statuses(); |
|
| 137 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 136 | + $statuses = getpaid_get_subscription_statuses(); |
|
| 137 | + return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -144,18 +144,18 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | function getpaid_get_subscription_status_classes() { |
| 146 | 146 | |
| 147 | - return apply_filters( |
|
| 148 | - 'getpaid_get_subscription_status_classes', |
|
| 149 | - array( |
|
| 150 | - 'pending' => 'badge-dark', |
|
| 151 | - 'trialling' => 'badge-info', |
|
| 152 | - 'active' => 'badge-success', |
|
| 153 | - 'failing' => 'badge-warning', |
|
| 154 | - 'expired' => 'badge-danger', |
|
| 155 | - 'completed' => 'badge-primary', |
|
| 156 | - 'cancelled' => 'badge-secondary', |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 147 | + return apply_filters( |
|
| 148 | + 'getpaid_get_subscription_status_classes', |
|
| 149 | + array( |
|
| 150 | + 'pending' => 'badge-dark', |
|
| 151 | + 'trialling' => 'badge-info', |
|
| 152 | + 'active' => 'badge-success', |
|
| 153 | + 'failing' => 'badge-warning', |
|
| 154 | + 'expired' => 'badge-danger', |
|
| 155 | + 'completed' => 'badge-primary', |
|
| 156 | + 'cancelled' => 'badge-secondary', |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | 159 | |
| 160 | 160 | } |
| 161 | 161 | |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | function getpaid_get_subscription_status_counts( $args = array() ) { |
| 168 | 168 | |
| 169 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 170 | - $counts = array(); |
|
| 169 | + $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 170 | + $counts = array(); |
|
| 171 | 171 | |
| 172 | - foreach ( $statuses as $status ) { |
|
| 173 | - $_args = wp_parse_args( "status=$status", $args ); |
|
| 174 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 175 | - } |
|
| 172 | + foreach ( $statuses as $status ) { |
|
| 173 | + $_args = wp_parse_args( "status=$status", $args ); |
|
| 174 | + $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - return $counts; |
|
| 177 | + return $counts; |
|
| 178 | 178 | |
| 179 | 179 | } |
| 180 | 180 | |
@@ -185,32 +185,32 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | function getpaid_get_subscription_periods() { |
| 187 | 187 | |
| 188 | - return apply_filters( |
|
| 189 | - 'getpaid_get_subscription_periods', |
|
| 190 | - array( |
|
| 188 | + return apply_filters( |
|
| 189 | + 'getpaid_get_subscription_periods', |
|
| 190 | + array( |
|
| 191 | 191 | |
| 192 | - 'day' => array( |
|
| 193 | - 'singular' => __( '%s day', 'invoicing' ), |
|
| 194 | - 'plural' => __( '%d days', 'invoicing' ), |
|
| 195 | - ), |
|
| 192 | + 'day' => array( |
|
| 193 | + 'singular' => __( '%s day', 'invoicing' ), |
|
| 194 | + 'plural' => __( '%d days', 'invoicing' ), |
|
| 195 | + ), |
|
| 196 | 196 | |
| 197 | - 'week' => array( |
|
| 198 | - 'singular' => __( '%s week', 'invoicing' ), |
|
| 199 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 200 | - ), |
|
| 197 | + 'week' => array( |
|
| 198 | + 'singular' => __( '%s week', 'invoicing' ), |
|
| 199 | + 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 200 | + ), |
|
| 201 | 201 | |
| 202 | - 'month' => array( |
|
| 203 | - 'singular' => __( '%s month', 'invoicing' ), |
|
| 204 | - 'plural' => __( '%d months', 'invoicing' ), |
|
| 205 | - ), |
|
| 202 | + 'month' => array( |
|
| 203 | + 'singular' => __( '%s month', 'invoicing' ), |
|
| 204 | + 'plural' => __( '%d months', 'invoicing' ), |
|
| 205 | + ), |
|
| 206 | 206 | |
| 207 | - 'year' => array( |
|
| 208 | - 'singular' => __( '%s year', 'invoicing' ), |
|
| 209 | - 'plural' => __( '%d years', 'invoicing' ), |
|
| 210 | - ), |
|
| 207 | + 'year' => array( |
|
| 208 | + 'singular' => __( '%s year', 'invoicing' ), |
|
| 209 | + 'plural' => __( '%d years', 'invoicing' ), |
|
| 210 | + ), |
|
| 211 | 211 | |
| 212 | - ) |
|
| 213 | - ); |
|
| 212 | + ) |
|
| 213 | + ); |
|
| 214 | 214 | |
| 215 | 215 | } |
| 216 | 216 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * @return int |
| 222 | 222 | */ |
| 223 | 223 | function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
| 224 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 224 | + return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * @return string |
| 232 | 232 | */ |
| 233 | 233 | function getpaid_get_subscription_trial_period_period( $trial_period ) { |
| 234 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 234 | + return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | 244 | function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
| 245 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 246 | - return strtolower( sanitize_text_field( $label ) ); |
|
| 245 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 246 | + return strtolower( sanitize_text_field( $label ) ); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -254,22 +254,22 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
| 256 | 256 | |
| 257 | - $periods = getpaid_get_subscription_periods(); |
|
| 258 | - $period = strtolower( $period ); |
|
| 257 | + $periods = getpaid_get_subscription_periods(); |
|
| 258 | + $period = strtolower( $period ); |
|
| 259 | 259 | |
| 260 | - if ( isset( $periods[ $period ] ) ) { |
|
| 261 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 262 | - } |
|
| 260 | + if ( isset( $periods[ $period ] ) ) { |
|
| 261 | + return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - // Backwards compatibility. |
|
| 265 | - foreach ( $periods as $key => $data ) { |
|
| 266 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 267 | - return sprintf( $data['singular'], $singular_prefix ); |
|
| 268 | - } |
|
| 269 | - } |
|
| 264 | + // Backwards compatibility. |
|
| 265 | + foreach ( $periods as $key => $data ) { |
|
| 266 | + if ( strpos( $key, $period ) === 0 ) { |
|
| 267 | + return sprintf( $data['singular'], $singular_prefix ); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - // Invalid string. |
|
| 272 | - return ''; |
|
| 271 | + // Invalid string. |
|
| 272 | + return ''; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -281,22 +281,22 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
| 283 | 283 | |
| 284 | - $periods = getpaid_get_subscription_periods(); |
|
| 285 | - $period = strtolower( $period ); |
|
| 284 | + $periods = getpaid_get_subscription_periods(); |
|
| 285 | + $period = strtolower( $period ); |
|
| 286 | 286 | |
| 287 | - if ( isset( $periods[ $period ] ) ) { |
|
| 288 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 289 | - } |
|
| 287 | + if ( isset( $periods[ $period ] ) ) { |
|
| 288 | + return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - // Backwards compatibility. |
|
| 292 | - foreach ( $periods as $key => $data ) { |
|
| 293 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 294 | - return sprintf( $data['plural'], $interval ); |
|
| 295 | - } |
|
| 296 | - } |
|
| 291 | + // Backwards compatibility. |
|
| 292 | + foreach ( $periods as $key => $data ) { |
|
| 293 | + if ( strpos( $key, $period ) === 0 ) { |
|
| 294 | + return sprintf( $data['plural'], $interval ); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - // Invalid string. |
|
| 299 | - return ''; |
|
| 298 | + // Invalid string. |
|
| 299 | + return ''; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -307,92 +307,92 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | function getpaid_get_formatted_subscription_amount( $subscription ) { |
| 309 | 309 | |
| 310 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 311 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 312 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 313 | - $bill_times = $subscription->get_bill_times(); |
|
| 314 | - $bill_times_less = $bill_times - 1; |
|
| 315 | - |
|
| 316 | - if ( ! empty( $bill_times ) ) { |
|
| 317 | - $bill_times = $subscription->get_frequency() * $bill_times; |
|
| 318 | - $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() ); |
|
| 319 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // Trial periods. |
|
| 323 | - if ( $subscription->has_trial_period() ) { |
|
| 324 | - |
|
| 325 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 326 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 327 | - |
|
| 328 | - if ( empty( $bill_times ) ) { |
|
| 329 | - |
|
| 330 | - return sprintf( |
|
| 331 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 332 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 333 | - $initial, |
|
| 334 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 335 | - $recurring, |
|
| 336 | - $period |
|
| 337 | - ); |
|
| 338 | - |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - return sprintf( |
|
| 342 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
| 343 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 344 | - $initial, |
|
| 345 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 346 | - $recurring, |
|
| 347 | - $period, |
|
| 348 | - $bill_times |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if ( $initial != $recurring ) { |
|
| 354 | - |
|
| 355 | - if ( empty( $bill_times ) ) { |
|
| 356 | - |
|
| 357 | - return sprintf( |
|
| 358 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
| 359 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 360 | - $initial, |
|
| 361 | - $recurring, |
|
| 362 | - $period |
|
| 363 | - ); |
|
| 364 | - |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return sprintf( |
|
| 368 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
| 369 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 370 | - $initial, |
|
| 371 | - $recurring, |
|
| 372 | - $period, |
|
| 373 | - $bill_times_less |
|
| 374 | - ); |
|
| 375 | - |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - if ( empty( $bill_times ) ) { |
|
| 379 | - |
|
| 380 | - return sprintf( |
|
| 381 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 382 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 383 | - $initial, |
|
| 384 | - $period |
|
| 385 | - ); |
|
| 386 | - |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - return sprintf( |
|
| 390 | - // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
| 391 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 392 | - $bill_times, |
|
| 393 | - $initial, |
|
| 394 | - $period |
|
| 395 | - ); |
|
| 310 | + $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 311 | + $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 312 | + $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 313 | + $bill_times = $subscription->get_bill_times(); |
|
| 314 | + $bill_times_less = $bill_times - 1; |
|
| 315 | + |
|
| 316 | + if ( ! empty( $bill_times ) ) { |
|
| 317 | + $bill_times = $subscription->get_frequency() * $bill_times; |
|
| 318 | + $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() ); |
|
| 319 | + $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // Trial periods. |
|
| 323 | + if ( $subscription->has_trial_period() ) { |
|
| 324 | + |
|
| 325 | + $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 326 | + $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 327 | + |
|
| 328 | + if ( empty( $bill_times ) ) { |
|
| 329 | + |
|
| 330 | + return sprintf( |
|
| 331 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 332 | + _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 333 | + $initial, |
|
| 334 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 335 | + $recurring, |
|
| 336 | + $period |
|
| 337 | + ); |
|
| 338 | + |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + return sprintf( |
|
| 342 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
| 343 | + _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 344 | + $initial, |
|
| 345 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 346 | + $recurring, |
|
| 347 | + $period, |
|
| 348 | + $bill_times |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if ( $initial != $recurring ) { |
|
| 354 | + |
|
| 355 | + if ( empty( $bill_times ) ) { |
|
| 356 | + |
|
| 357 | + return sprintf( |
|
| 358 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
| 359 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 360 | + $initial, |
|
| 361 | + $recurring, |
|
| 362 | + $period |
|
| 363 | + ); |
|
| 364 | + |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return sprintf( |
|
| 368 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
| 369 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 370 | + $initial, |
|
| 371 | + $recurring, |
|
| 372 | + $period, |
|
| 373 | + $bill_times_less |
|
| 374 | + ); |
|
| 375 | + |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + if ( empty( $bill_times ) ) { |
|
| 379 | + |
|
| 380 | + return sprintf( |
|
| 381 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 382 | + _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 383 | + $initial, |
|
| 384 | + $period |
|
| 385 | + ); |
|
| 386 | + |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + return sprintf( |
|
| 390 | + // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
| 391 | + _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 392 | + $bill_times, |
|
| 393 | + $initial, |
|
| 394 | + $period |
|
| 395 | + ); |
|
| 396 | 396 | |
| 397 | 397 | } |
| 398 | 398 | |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | * @return WPInv_Subscription|false |
| 404 | 404 | */ |
| 405 | 405 | function getpaid_get_invoice_subscription( $invoice ) { |
| 406 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 406 | + return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -412,10 +412,10 @@ discard block |
||
| 412 | 412 | * @param WPInv_Invoice $invoice |
| 413 | 413 | */ |
| 414 | 414 | function getpaid_activate_invoice_subscription( $invoice ) { |
| 415 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 416 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 417 | - $subscription->activate(); |
|
| 418 | - } |
|
| 415 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 416 | + if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 417 | + $subscription->activate(); |
|
| 418 | + } |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * @return WPInv_Subscriptions |
| 425 | 425 | */ |
| 426 | 426 | function getpaid_subscriptions() { |
| 427 | - return getpaid()->get( 'subscriptions' ); |
|
| 427 | + return getpaid()->get( 'subscriptions' ); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -443,15 +443,15 @@ discard block |
||
| 443 | 443 | return false; |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - // Fetch the invoice subscription. |
|
| 447 | - $subscription = getpaid_get_subscriptions( |
|
| 448 | - array( |
|
| 449 | - 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
| 450 | - 'number' => 1, |
|
| 451 | - ) |
|
| 452 | - ); |
|
| 446 | + // Fetch the invoice subscription. |
|
| 447 | + $subscription = getpaid_get_subscriptions( |
|
| 448 | + array( |
|
| 449 | + 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
| 450 | + 'number' => 1, |
|
| 451 | + ) |
|
| 452 | + ); |
|
| 453 | 453 | |
| 454 | - return empty( $subscription ) ? false : $subscription[0]; |
|
| 454 | + return empty( $subscription ) ? false : $subscription[0]; |
|
| 455 | 455 | |
| 456 | 456 | } |
| 457 | 457 | |
@@ -468,48 +468,48 @@ discard block |
||
| 468 | 468 | */ |
| 469 | 469 | function getpaid_get_recurring_item_key( $cart_item ) { |
| 470 | 470 | |
| 471 | - $cart_key = 'renews_'; |
|
| 472 | - $interval = $cart_item->get_recurring_interval(); |
|
| 473 | - $period = $cart_item->get_recurring_period( true ); |
|
| 474 | - $length = $cart_item->get_recurring_limit() * $interval; |
|
| 475 | - $trial_period = $cart_item->get_trial_period( true ); |
|
| 476 | - $trial_length = $cart_item->get_trial_interval(); |
|
| 477 | - |
|
| 478 | - // First start with the billing interval and period |
|
| 479 | - switch ( $interval ) { |
|
| 480 | - case 1: |
|
| 481 | - if ( 'day' == $period ) { |
|
| 482 | - $cart_key .= 'daily'; |
|
| 483 | - } else { |
|
| 484 | - $cart_key .= sprintf( '%sly', $period ); |
|
| 485 | - } |
|
| 486 | - break; |
|
| 487 | - case 2: |
|
| 488 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
| 489 | - break; |
|
| 490 | - case 3: |
|
| 491 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
| 492 | - break; |
|
| 493 | - default: |
|
| 494 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
| 495 | - break; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - // Maybe add the optional maximum billing periods... |
|
| 499 | - if ( $length > 0 ) { |
|
| 500 | - $cart_key .= '_for_'; |
|
| 501 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
| 502 | - if ( $length > 1 ) { |
|
| 503 | - $cart_key .= 's'; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - // And an optional free trial. |
|
| 508 | - if ( $cart_item->has_free_trial() ) { |
|
| 509 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
| 471 | + $cart_key = 'renews_'; |
|
| 472 | + $interval = $cart_item->get_recurring_interval(); |
|
| 473 | + $period = $cart_item->get_recurring_period( true ); |
|
| 474 | + $length = $cart_item->get_recurring_limit() * $interval; |
|
| 475 | + $trial_period = $cart_item->get_trial_period( true ); |
|
| 476 | + $trial_length = $cart_item->get_trial_interval(); |
|
| 477 | + |
|
| 478 | + // First start with the billing interval and period |
|
| 479 | + switch ( $interval ) { |
|
| 480 | + case 1: |
|
| 481 | + if ( 'day' == $period ) { |
|
| 482 | + $cart_key .= 'daily'; |
|
| 483 | + } else { |
|
| 484 | + $cart_key .= sprintf( '%sly', $period ); |
|
| 485 | + } |
|
| 486 | + break; |
|
| 487 | + case 2: |
|
| 488 | + $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
| 489 | + break; |
|
| 490 | + case 3: |
|
| 491 | + $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
| 492 | + break; |
|
| 493 | + default: |
|
| 494 | + $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
| 495 | + break; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + // Maybe add the optional maximum billing periods... |
|
| 499 | + if ( $length > 0 ) { |
|
| 500 | + $cart_key .= '_for_'; |
|
| 501 | + $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
| 502 | + if ( $length > 1 ) { |
|
| 503 | + $cart_key .= 's'; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + // And an optional free trial. |
|
| 508 | + if ( $cart_item->has_free_trial() ) { |
|
| 509 | + $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -520,16 +520,16 @@ discard block |
||
| 520 | 520 | */ |
| 521 | 521 | function getpaid_get_subscription_groups( $invoice ) { |
| 522 | 522 | |
| 523 | - // Generate subscription groups. |
|
| 524 | - $subscription_groups = array(); |
|
| 525 | - foreach ( $invoice->get_items() as $item ) { |
|
| 523 | + // Generate subscription groups. |
|
| 524 | + $subscription_groups = array(); |
|
| 525 | + foreach ( $invoice->get_items() as $item ) { |
|
| 526 | 526 | |
| 527 | - if ( $item->is_recurring() ) { |
|
| 528 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
| 529 | - } |
|
| 527 | + if ( $item->is_recurring() ) { |
|
| 528 | + $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
| 529 | + } |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - return $subscription_groups; |
|
| 532 | + return $subscription_groups; |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -543,56 +543,56 @@ discard block |
||
| 543 | 543 | */ |
| 544 | 544 | function getpaid_calculate_subscription_totals( $invoice ) { |
| 545 | 545 | |
| 546 | - // Generate subscription groups. |
|
| 547 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
| 546 | + // Generate subscription groups. |
|
| 547 | + $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
| 548 | 548 | |
| 549 | - // Now let's calculate the totals for each group of subscriptions |
|
| 550 | - $subscription_totals = array(); |
|
| 549 | + // Now let's calculate the totals for each group of subscriptions |
|
| 550 | + $subscription_totals = array(); |
|
| 551 | 551 | |
| 552 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
| 552 | + foreach ( $subscription_groups as $subscription_key => $items ) { |
|
| 553 | 553 | |
| 554 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
| 554 | + if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
| 555 | 555 | |
| 556 | - $subscription_totals[ $subscription_key ] = array( |
|
| 557 | - 'initial_total' => 0, |
|
| 558 | - 'recurring_total' => 0, |
|
| 559 | - 'items' => array(), |
|
| 560 | - 'trialling' => false, |
|
| 561 | - ); |
|
| 556 | + $subscription_totals[ $subscription_key ] = array( |
|
| 557 | + 'initial_total' => 0, |
|
| 558 | + 'recurring_total' => 0, |
|
| 559 | + 'items' => array(), |
|
| 560 | + 'trialling' => false, |
|
| 561 | + ); |
|
| 562 | 562 | |
| 563 | - } |
|
| 563 | + } |
|
| 564 | 564 | |
| 565 | - /** |
|
| 566 | - * Get the totals of the group. |
|
| 567 | - * @var GetPaid_Form_Item $item |
|
| 568 | - */ |
|
| 569 | - foreach ( $items as $item ) { |
|
| 565 | + /** |
|
| 566 | + * Get the totals of the group. |
|
| 567 | + * @var GetPaid_Form_Item $item |
|
| 568 | + */ |
|
| 569 | + foreach ( $items as $item ) { |
|
| 570 | 570 | |
| 571 | - $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ] = $item->prepare_data_for_saving(); |
|
| 572 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
| 573 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
| 574 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
| 575 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
| 576 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
| 577 | - $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 571 | + $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ] = $item->prepare_data_for_saving(); |
|
| 572 | + $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
| 573 | + $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
| 574 | + $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
| 575 | + $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
| 576 | + $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
| 577 | + $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 578 | 578 | |
| 579 | - // Calculate the next renewal date. |
|
| 580 | - $period = $item->get_recurring_period( true ); |
|
| 581 | - $interval = $item->get_recurring_interval(); |
|
| 579 | + // Calculate the next renewal date. |
|
| 580 | + $period = $item->get_recurring_period( true ); |
|
| 581 | + $interval = $item->get_recurring_interval(); |
|
| 582 | 582 | |
| 583 | - // If the subscription item has a trial period... |
|
| 584 | - if ( $item->has_free_trial() ) { |
|
| 585 | - $period = $item->get_trial_period( true ); |
|
| 586 | - $interval = $item->get_trial_interval(); |
|
| 587 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
| 588 | - } |
|
| 583 | + // If the subscription item has a trial period... |
|
| 584 | + if ( $item->has_free_trial() ) { |
|
| 585 | + $period = $item->get_trial_period( true ); |
|
| 586 | + $interval = $item->get_trial_interval(); |
|
| 587 | + $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
| 588 | + } |
|
| 589 | 589 | |
| 590 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
| 590 | + $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
| 591 | 591 | |
| 592 | - } |
|
| 592 | + } |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
| 595 | + return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | /** |
@@ -603,16 +603,16 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | function getpaid_should_group_subscriptions( $invoice ) { |
| 605 | 605 | |
| 606 | - $recurring_items = 0; |
|
| 606 | + $recurring_items = 0; |
|
| 607 | 607 | |
| 608 | - foreach ( $invoice->get_items() as $item ) { |
|
| 608 | + foreach ( $invoice->get_items() as $item ) { |
|
| 609 | 609 | |
| 610 | - if ( $item->is_recurring() ) { |
|
| 611 | - $recurring_items ++; |
|
| 612 | - } |
|
| 610 | + if ( $item->is_recurring() ) { |
|
| 611 | + $recurring_items ++; |
|
| 612 | + } |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
| 615 | + return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -623,39 +623,39 @@ discard block |
||
| 623 | 623 | * @return int |
| 624 | 624 | */ |
| 625 | 625 | function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) { |
| 626 | - global $wpdb; |
|
| 626 | + global $wpdb; |
|
| 627 | 627 | |
| 628 | - $parent_invoice_id = (int) $parent_invoice_id; |
|
| 628 | + $parent_invoice_id = (int) $parent_invoice_id; |
|
| 629 | 629 | |
| 630 | - if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) { |
|
| 630 | + if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) { |
|
| 631 | 631 | |
| 632 | - return (int) $wpdb->get_var( |
|
| 633 | - $wpdb->prepare( |
|
| 634 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 635 | - $parent_invoice_id, |
|
| 636 | - $parent_invoice_id |
|
| 637 | - ) |
|
| 638 | - ); |
|
| 632 | + return (int) $wpdb->get_var( |
|
| 633 | + $wpdb->prepare( |
|
| 634 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 635 | + $parent_invoice_id, |
|
| 636 | + $parent_invoice_id |
|
| 637 | + ) |
|
| 638 | + ); |
|
| 639 | 639 | |
| 640 | - } |
|
| 640 | + } |
|
| 641 | 641 | |
| 642 | - $invoice_ids = $wpdb->get_col( |
|
| 643 | - $wpdb->prepare( |
|
| 644 | - "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 645 | - $parent_invoice_id, |
|
| 646 | - $parent_invoice_id |
|
| 647 | - ) |
|
| 648 | - ); |
|
| 642 | + $invoice_ids = $wpdb->get_col( |
|
| 643 | + $wpdb->prepare( |
|
| 644 | + "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 645 | + $parent_invoice_id, |
|
| 646 | + $parent_invoice_id |
|
| 647 | + ) |
|
| 648 | + ); |
|
| 649 | 649 | |
| 650 | - $count = 0; |
|
| 650 | + $count = 0; |
|
| 651 | 651 | |
| 652 | - foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) { |
|
| 652 | + foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) { |
|
| 653 | 653 | |
| 654 | - if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) { |
|
| 655 | - $count ++; |
|
| 656 | - continue; |
|
| 657 | - } |
|
| 654 | + if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) { |
|
| 655 | + $count ++; |
|
| 656 | + continue; |
|
| 657 | + } |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - return $count; |
|
| 660 | + return $count; |
|
| 661 | 661 | } |
@@ -13,18 +13,18 @@ discard block |
||
| 13 | 13 | * @return WPInv_Subscription[]|WPInv_Subscription|false |
| 14 | 14 | * @since 2.3.0 |
| 15 | 15 | */ |
| 16 | -function getpaid_get_invoice_subscriptions( $invoice ) { |
|
| 16 | +function getpaid_get_invoice_subscriptions($invoice) { |
|
| 17 | 17 | |
| 18 | 18 | // Retrieve subscription groups. |
| 19 | - $subscription_ids = wp_list_pluck( getpaid_get_invoice_subscription_groups( $invoice->get_id() ), 'subscription_id' ); |
|
| 19 | + $subscription_ids = wp_list_pluck(getpaid_get_invoice_subscription_groups($invoice->get_id()), 'subscription_id'); |
|
| 20 | 20 | |
| 21 | 21 | // No subscription groups, normal subscription. |
| 22 | - if ( empty( $subscription_ids ) ) { |
|
| 23 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 22 | + if (empty($subscription_ids)) { |
|
| 23 | + return getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Subscription groups. |
| 27 | - return array_filter( array_map( 'getpaid_get_subscription', $subscription_ids ) ); |
|
| 27 | + return array_filter(array_map('getpaid_get_subscription', $subscription_ids)); |
|
| 28 | 28 | |
| 29 | 29 | } |
| 30 | 30 | |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * @return array |
| 36 | 36 | * @since 2.3.0 |
| 37 | 37 | */ |
| 38 | -function getpaid_get_invoice_subscription_groups( $invoice_id ) { |
|
| 39 | - $subscription_groups = get_post_meta( $invoice_id, 'getpaid_subscription_groups', true ); |
|
| 40 | - return empty( $subscription_groups ) ? array() : $subscription_groups; |
|
| 38 | +function getpaid_get_invoice_subscription_groups($invoice_id) { |
|
| 39 | + $subscription_groups = get_post_meta($invoice_id, 'getpaid_subscription_groups', true); |
|
| 40 | + return empty($subscription_groups) ? array() : $subscription_groups; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | * @return array|false |
| 49 | 49 | * @since 2.3.0 |
| 50 | 50 | */ |
| 51 | -function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) { |
|
| 52 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id ); |
|
| 53 | - $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 54 | - return reset( $matching_group ); |
|
| 51 | +function getpaid_get_invoice_subscription_group($invoice_id, $subscription_id) { |
|
| 52 | + $subscription_groups = getpaid_get_invoice_subscription_groups($invoice_id); |
|
| 53 | + $matching_group = wp_list_filter($subscription_groups, compact('subscription_id')); |
|
| 54 | + return reset($matching_group); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | * @since 2.3.0 |
| 62 | 62 | * @return WPInv_Subscription|false |
| 63 | 63 | */ |
| 64 | -function getpaid_get_subscription( $subscription ) { |
|
| 64 | +function getpaid_get_subscription($subscription) { |
|
| 65 | 65 | |
| 66 | - if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 67 | - $subscription = new WPInv_Subscription( $subscription ); |
|
| 66 | + if (!is_a($subscription, 'WPInv_Subscription')) { |
|
| 67 | + $subscription = new WPInv_Subscription($subscription); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | return $subscription->exists() ? $subscription : false; |
@@ -79,26 +79,26 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query |
| 81 | 81 | */ |
| 82 | -function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
|
| 82 | +function getpaid_get_subscriptions($args = array(), $return = 'results') { |
|
| 83 | 83 | |
| 84 | 84 | // Do not retrieve all fields if we just want the count. |
| 85 | - if ( 'count' == $return ) { |
|
| 85 | + if ('count' == $return) { |
|
| 86 | 86 | $args['fields'] = 'id'; |
| 87 | 87 | $args['number'] = 1; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // Do not count all matches if we just want the results. |
| 91 | - if ( 'results' == $return ) { |
|
| 91 | + if ('results' == $return) { |
|
| 92 | 92 | $args['count_total'] = false; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 95 | + $query = new GetPaid_Subscriptions_Query($args); |
|
| 96 | 96 | |
| 97 | - if ( 'results' == $return ) { |
|
| 97 | + if ('results' == $return) { |
|
| 98 | 98 | return $query->get_results(); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if ( 'count' == $return ) { |
|
| 101 | + if ('count' == $return) { |
|
| 102 | 102 | return $query->get_total(); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | return apply_filters( |
| 116 | 116 | 'getpaid_get_subscription_statuses', |
| 117 | 117 | array( |
| 118 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
| 119 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 120 | - 'active' => __( 'Active', 'invoicing' ), |
|
| 121 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
| 122 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 123 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
| 124 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 118 | + 'pending' => __('Pending', 'invoicing'), |
|
| 119 | + 'trialling' => __('Trialing', 'invoicing'), |
|
| 120 | + 'active' => __('Active', 'invoicing'), |
|
| 121 | + 'failing' => __('Failing', 'invoicing'), |
|
| 122 | + 'expired' => __('Expired', 'invoicing'), |
|
| 123 | + 'completed' => __('Complete', 'invoicing'), |
|
| 124 | + 'cancelled' => __('Cancelled', 'invoicing'), |
|
| 125 | 125 | ) |
| 126 | 126 | ); |
| 127 | 127 | |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | -function getpaid_get_subscription_status_label( $status ) { |
|
| 135 | +function getpaid_get_subscription_status_label($status) { |
|
| 136 | 136 | $statuses = getpaid_get_subscription_statuses(); |
| 137 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 137 | + return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status)); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -164,14 +164,14 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @return array |
| 166 | 166 | */ |
| 167 | -function getpaid_get_subscription_status_counts( $args = array() ) { |
|
| 167 | +function getpaid_get_subscription_status_counts($args = array()) { |
|
| 168 | 168 | |
| 169 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 169 | + $statuses = array_keys(getpaid_get_subscription_statuses()); |
|
| 170 | 170 | $counts = array(); |
| 171 | 171 | |
| 172 | - foreach ( $statuses as $status ) { |
|
| 173 | - $_args = wp_parse_args( "status=$status", $args ); |
|
| 174 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 172 | + foreach ($statuses as $status) { |
|
| 173 | + $_args = wp_parse_args("status=$status", $args); |
|
| 174 | + $counts[$status] = getpaid_get_subscriptions($_args, 'count'); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | return $counts; |
@@ -190,23 +190,23 @@ discard block |
||
| 190 | 190 | array( |
| 191 | 191 | |
| 192 | 192 | 'day' => array( |
| 193 | - 'singular' => __( '%s day', 'invoicing' ), |
|
| 194 | - 'plural' => __( '%d days', 'invoicing' ), |
|
| 193 | + 'singular' => __('%s day', 'invoicing'), |
|
| 194 | + 'plural' => __('%d days', 'invoicing'), |
|
| 195 | 195 | ), |
| 196 | 196 | |
| 197 | 197 | 'week' => array( |
| 198 | - 'singular' => __( '%s week', 'invoicing' ), |
|
| 199 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 198 | + 'singular' => __('%s week', 'invoicing'), |
|
| 199 | + 'plural' => __('%d weeks', 'invoicing'), |
|
| 200 | 200 | ), |
| 201 | 201 | |
| 202 | 202 | 'month' => array( |
| 203 | - 'singular' => __( '%s month', 'invoicing' ), |
|
| 204 | - 'plural' => __( '%d months', 'invoicing' ), |
|
| 203 | + 'singular' => __('%s month', 'invoicing'), |
|
| 204 | + 'plural' => __('%d months', 'invoicing'), |
|
| 205 | 205 | ), |
| 206 | 206 | |
| 207 | 207 | 'year' => array( |
| 208 | - 'singular' => __( '%s year', 'invoicing' ), |
|
| 209 | - 'plural' => __( '%d years', 'invoicing' ), |
|
| 208 | + 'singular' => __('%s year', 'invoicing'), |
|
| 209 | + 'plural' => __('%d years', 'invoicing'), |
|
| 210 | 210 | ), |
| 211 | 211 | |
| 212 | 212 | ) |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | * @param string $trial_period |
| 221 | 221 | * @return int |
| 222 | 222 | */ |
| 223 | -function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
|
| 224 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 223 | +function getpaid_get_subscription_trial_period_interval($trial_period) { |
|
| 224 | + return (int) preg_replace('/[^0-9]/', '', $trial_period); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | * @param string $trial_period |
| 231 | 231 | * @return string |
| 232 | 232 | */ |
| 233 | -function getpaid_get_subscription_trial_period_period( $trial_period ) { |
|
| 234 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 233 | +function getpaid_get_subscription_trial_period_period($trial_period) { |
|
| 234 | + return preg_replace('/[^a-z]/', '', strtolower($trial_period)); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -241,9 +241,9 @@ discard block |
||
| 241 | 241 | * @param int $interval |
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | -function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
|
| 245 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 246 | - return strtolower( sanitize_text_field( $label ) ); |
|
| 244 | +function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') { |
|
| 245 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix); |
|
| 246 | + return strtolower(sanitize_text_field($label)); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -252,19 +252,19 @@ discard block |
||
| 252 | 252 | * @param string $period |
| 253 | 253 | * @return string |
| 254 | 254 | */ |
| 255 | -function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
|
| 255 | +function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') { |
|
| 256 | 256 | |
| 257 | 257 | $periods = getpaid_get_subscription_periods(); |
| 258 | - $period = strtolower( $period ); |
|
| 258 | + $period = strtolower($period); |
|
| 259 | 259 | |
| 260 | - if ( isset( $periods[ $period ] ) ) { |
|
| 261 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 260 | + if (isset($periods[$period])) { |
|
| 261 | + return sprintf($periods[$period]['singular'], $singular_prefix); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // Backwards compatibility. |
| 265 | - foreach ( $periods as $key => $data ) { |
|
| 266 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 267 | - return sprintf( $data['singular'], $singular_prefix ); |
|
| 265 | + foreach ($periods as $key => $data) { |
|
| 266 | + if (strpos($key, $period) === 0) { |
|
| 267 | + return sprintf($data['singular'], $singular_prefix); |
|
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
@@ -279,19 +279,19 @@ discard block |
||
| 279 | 279 | * @param int $interval |
| 280 | 280 | * @return string |
| 281 | 281 | */ |
| 282 | -function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
|
| 282 | +function getpaid_get_plural_subscription_period_label($period, $interval) { |
|
| 283 | 283 | |
| 284 | 284 | $periods = getpaid_get_subscription_periods(); |
| 285 | - $period = strtolower( $period ); |
|
| 285 | + $period = strtolower($period); |
|
| 286 | 286 | |
| 287 | - if ( isset( $periods[ $period ] ) ) { |
|
| 288 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 287 | + if (isset($periods[$period])) { |
|
| 288 | + return sprintf($periods[$period]['plural'], $interval); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | // Backwards compatibility. |
| 292 | - foreach ( $periods as $key => $data ) { |
|
| 293 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 294 | - return sprintf( $data['plural'], $interval ); |
|
| 292 | + foreach ($periods as $key => $data) { |
|
| 293 | + if (strpos($key, $period) === 0) { |
|
| 294 | + return sprintf($data['plural'], $interval); |
|
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | |
@@ -305,33 +305,33 @@ discard block |
||
| 305 | 305 | * @param WPInv_Subscription $subscription |
| 306 | 306 | * @return string |
| 307 | 307 | */ |
| 308 | -function getpaid_get_formatted_subscription_amount( $subscription ) { |
|
| 308 | +function getpaid_get_formatted_subscription_amount($subscription) { |
|
| 309 | 309 | |
| 310 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 311 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 312 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 310 | + $initial = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
| 311 | + $recurring = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
| 312 | + $period = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
| 313 | 313 | $bill_times = $subscription->get_bill_times(); |
| 314 | 314 | $bill_times_less = $bill_times - 1; |
| 315 | 315 | |
| 316 | - if ( ! empty( $bill_times ) ) { |
|
| 316 | + if (!empty($bill_times)) { |
|
| 317 | 317 | $bill_times = $subscription->get_frequency() * $bill_times; |
| 318 | - $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() ); |
|
| 319 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 318 | + $bill_times_less = getpaid_get_subscription_period_label($subscription->get_frequency(), $bill_times - $subscription->get_frequency()); |
|
| 319 | + $bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Trial periods. |
| 323 | - if ( $subscription->has_trial_period() ) { |
|
| 323 | + if ($subscription->has_trial_period()) { |
|
| 324 | 324 | |
| 325 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 326 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 325 | + $trial_period = getpaid_get_subscription_trial_period_period($subscription->get_trial_period()); |
|
| 326 | + $trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period()); |
|
| 327 | 327 | |
| 328 | - if ( empty( $bill_times ) ) { |
|
| 328 | + if (empty($bill_times)) { |
|
| 329 | 329 | |
| 330 | 330 | return sprintf( |
| 331 | 331 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
| 332 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 332 | + _x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'), |
|
| 333 | 333 | $initial, |
| 334 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 334 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
| 335 | 335 | $recurring, |
| 336 | 336 | $period |
| 337 | 337 | ); |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | return sprintf( |
| 342 | 342 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
| 343 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 343 | + _x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
| 344 | 344 | $initial, |
| 345 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 345 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
| 346 | 346 | $recurring, |
| 347 | 347 | $period, |
| 348 | 348 | $bill_times |
@@ -350,13 +350,13 @@ discard block |
||
| 350 | 350 | |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - if ( $initial != $recurring ) { |
|
| 353 | + if ($initial != $recurring) { |
|
| 354 | 354 | |
| 355 | - if ( empty( $bill_times ) ) { |
|
| 355 | + if (empty($bill_times)) { |
|
| 356 | 356 | |
| 357 | 357 | return sprintf( |
| 358 | 358 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
| 359 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 359 | + _x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'), |
|
| 360 | 360 | $initial, |
| 361 | 361 | $recurring, |
| 362 | 362 | $period |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | return sprintf( |
| 368 | 368 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
| 369 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 369 | + _x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'), |
|
| 370 | 370 | $initial, |
| 371 | 371 | $recurring, |
| 372 | 372 | $period, |
@@ -375,11 +375,11 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - if ( empty( $bill_times ) ) { |
|
| 378 | + if (empty($bill_times)) { |
|
| 379 | 379 | |
| 380 | 380 | return sprintf( |
| 381 | 381 | // translators: $1: is the recurring amount, $2: is the recurring period |
| 382 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 382 | + _x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
| 383 | 383 | $initial, |
| 384 | 384 | $period |
| 385 | 385 | ); |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | return sprintf( |
| 390 | 390 | // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
| 391 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 391 | + _x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
| 392 | 392 | $bill_times, |
| 393 | 393 | $initial, |
| 394 | 394 | $period |
@@ -402,8 +402,8 @@ discard block |
||
| 402 | 402 | * @param WPInv_Invoice $invoice |
| 403 | 403 | * @return WPInv_Subscription|false |
| 404 | 404 | */ |
| 405 | -function getpaid_get_invoice_subscription( $invoice ) { |
|
| 406 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 405 | +function getpaid_get_invoice_subscription($invoice) { |
|
| 406 | + return getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -411,9 +411,9 @@ discard block |
||
| 411 | 411 | * |
| 412 | 412 | * @param WPInv_Invoice $invoice |
| 413 | 413 | */ |
| 414 | -function getpaid_activate_invoice_subscription( $invoice ) { |
|
| 415 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 416 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 414 | +function getpaid_activate_invoice_subscription($invoice) { |
|
| 415 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
| 416 | + if (is_a($subscription, 'WPInv_Subscription')) { |
|
| 417 | 417 | $subscription->activate(); |
| 418 | 418 | } |
| 419 | 419 | } |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * @return WPInv_Subscriptions |
| 425 | 425 | */ |
| 426 | 426 | function getpaid_subscriptions() { |
| 427 | - return getpaid()->get( 'subscriptions' ); |
|
| 427 | + return getpaid()->get('subscriptions'); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -433,13 +433,13 @@ discard block |
||
| 433 | 433 | * @since 2.3.0 |
| 434 | 434 | * @return WPInv_Subscription|bool |
| 435 | 435 | */ |
| 436 | -function wpinv_get_invoice_subscription( $invoice ) { |
|
| 436 | +function wpinv_get_invoice_subscription($invoice) { |
|
| 437 | 437 | |
| 438 | 438 | // Retrieve the invoice. |
| 439 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 439 | + $invoice = new WPInv_Invoice($invoice); |
|
| 440 | 440 | |
| 441 | 441 | // Ensure it is a recurring invoice. |
| 442 | - if ( ! $invoice->is_recurring() ) { |
|
| 442 | + if (!$invoice->is_recurring()) { |
|
| 443 | 443 | return false; |
| 444 | 444 | } |
| 445 | 445 | |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | ) |
| 452 | 452 | ); |
| 453 | 453 | |
| 454 | - return empty( $subscription ) ? false : $subscription[0]; |
|
| 454 | + return empty($subscription) ? false : $subscription[0]; |
|
| 455 | 455 | |
| 456 | 456 | } |
| 457 | 457 | |
@@ -466,50 +466,50 @@ discard block |
||
| 466 | 466 | * @param GetPaid_Form_Item|WPInv_Item $cart_item |
| 467 | 467 | * @return string |
| 468 | 468 | */ |
| 469 | -function getpaid_get_recurring_item_key( $cart_item ) { |
|
| 469 | +function getpaid_get_recurring_item_key($cart_item) { |
|
| 470 | 470 | |
| 471 | 471 | $cart_key = 'renews_'; |
| 472 | 472 | $interval = $cart_item->get_recurring_interval(); |
| 473 | - $period = $cart_item->get_recurring_period( true ); |
|
| 473 | + $period = $cart_item->get_recurring_period(true); |
|
| 474 | 474 | $length = $cart_item->get_recurring_limit() * $interval; |
| 475 | - $trial_period = $cart_item->get_trial_period( true ); |
|
| 475 | + $trial_period = $cart_item->get_trial_period(true); |
|
| 476 | 476 | $trial_length = $cart_item->get_trial_interval(); |
| 477 | 477 | |
| 478 | 478 | // First start with the billing interval and period |
| 479 | - switch ( $interval ) { |
|
| 479 | + switch ($interval) { |
|
| 480 | 480 | case 1: |
| 481 | - if ( 'day' == $period ) { |
|
| 481 | + if ('day' == $period) { |
|
| 482 | 482 | $cart_key .= 'daily'; |
| 483 | 483 | } else { |
| 484 | - $cart_key .= sprintf( '%sly', $period ); |
|
| 484 | + $cart_key .= sprintf('%sly', $period); |
|
| 485 | 485 | } |
| 486 | 486 | break; |
| 487 | 487 | case 2: |
| 488 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
| 488 | + $cart_key .= sprintf('every_2nd_%s', $period); |
|
| 489 | 489 | break; |
| 490 | 490 | case 3: |
| 491 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
| 491 | + $cart_key .= sprintf('every_3rd_%s', $period); |
|
| 492 | 492 | break; |
| 493 | 493 | default: |
| 494 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
| 494 | + $cart_key .= sprintf('every_%dth_%s', $interval, $period); |
|
| 495 | 495 | break; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | // Maybe add the optional maximum billing periods... |
| 499 | - if ( $length > 0 ) { |
|
| 499 | + if ($length > 0) { |
|
| 500 | 500 | $cart_key .= '_for_'; |
| 501 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
| 502 | - if ( $length > 1 ) { |
|
| 501 | + $cart_key .= sprintf('%d_%s', $length, $period); |
|
| 502 | + if ($length > 1) { |
|
| 503 | 503 | $cart_key .= 's'; |
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // And an optional free trial. |
| 508 | - if ( $cart_item->has_free_trial() ) { |
|
| 509 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
| 508 | + if ($cart_item->has_free_trial()) { |
|
| 509 | + $cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
| 512 | + return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -518,14 +518,14 @@ discard block |
||
| 518 | 518 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
| 519 | 519 | * @return array |
| 520 | 520 | */ |
| 521 | -function getpaid_get_subscription_groups( $invoice ) { |
|
| 521 | +function getpaid_get_subscription_groups($invoice) { |
|
| 522 | 522 | |
| 523 | 523 | // Generate subscription groups. |
| 524 | 524 | $subscription_groups = array(); |
| 525 | - foreach ( $invoice->get_items() as $item ) { |
|
| 525 | + foreach ($invoice->get_items() as $item) { |
|
| 526 | 526 | |
| 527 | - if ( $item->is_recurring() ) { |
|
| 528 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
| 527 | + if ($item->is_recurring()) { |
|
| 528 | + $subscription_groups[getpaid_get_recurring_item_key($item)][] = $item; |
|
| 529 | 529 | } |
| 530 | 530 | } |
| 531 | 531 | |
@@ -541,19 +541,19 @@ discard block |
||
| 541 | 541 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
| 542 | 542 | * @return array |
| 543 | 543 | */ |
| 544 | -function getpaid_calculate_subscription_totals( $invoice ) { |
|
| 544 | +function getpaid_calculate_subscription_totals($invoice) { |
|
| 545 | 545 | |
| 546 | 546 | // Generate subscription groups. |
| 547 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
| 547 | + $subscription_groups = getpaid_get_subscription_groups($invoice); |
|
| 548 | 548 | |
| 549 | 549 | // Now let's calculate the totals for each group of subscriptions |
| 550 | 550 | $subscription_totals = array(); |
| 551 | 551 | |
| 552 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
| 552 | + foreach ($subscription_groups as $subscription_key => $items) { |
|
| 553 | 553 | |
| 554 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
| 554 | + if (empty($subscription_totals[$subscription_key])) { |
|
| 555 | 555 | |
| 556 | - $subscription_totals[ $subscription_key ] = array( |
|
| 556 | + $subscription_totals[$subscription_key] = array( |
|
| 557 | 557 | 'initial_total' => 0, |
| 558 | 558 | 'recurring_total' => 0, |
| 559 | 559 | 'items' => array(), |
@@ -566,33 +566,33 @@ discard block |
||
| 566 | 566 | * Get the totals of the group. |
| 567 | 567 | * @var GetPaid_Form_Item $item |
| 568 | 568 | */ |
| 569 | - foreach ( $items as $item ) { |
|
| 569 | + foreach ($items as $item) { |
|
| 570 | 570 | |
| 571 | - $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ] = $item->prepare_data_for_saving(); |
|
| 572 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
| 573 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
| 574 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
| 575 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
| 576 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
| 577 | - $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 571 | + $subscription_totals[$subscription_key]['items'][$item->get_id()] = $item->prepare_data_for_saving(); |
|
| 572 | + $subscription_totals[$subscription_key]['item_id'] = $item->get_id(); |
|
| 573 | + $subscription_totals[$subscription_key]['period'] = $item->get_recurring_period(true); |
|
| 574 | + $subscription_totals[$subscription_key]['interval'] = $item->get_recurring_interval(); |
|
| 575 | + $subscription_totals[$subscription_key]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
| 576 | + $subscription_totals[$subscription_key]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
| 577 | + $subscription_totals[$subscription_key]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 578 | 578 | |
| 579 | 579 | // Calculate the next renewal date. |
| 580 | - $period = $item->get_recurring_period( true ); |
|
| 580 | + $period = $item->get_recurring_period(true); |
|
| 581 | 581 | $interval = $item->get_recurring_interval(); |
| 582 | 582 | |
| 583 | 583 | // If the subscription item has a trial period... |
| 584 | - if ( $item->has_free_trial() ) { |
|
| 585 | - $period = $item->get_trial_period( true ); |
|
| 584 | + if ($item->has_free_trial()) { |
|
| 585 | + $period = $item->get_trial_period(true); |
|
| 586 | 586 | $interval = $item->get_trial_interval(); |
| 587 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
| 587 | + $subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
| 590 | + $subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp'))); |
|
| 591 | 591 | |
| 592 | 592 | } |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
| 595 | + return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice); |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | /** |
@@ -601,18 +601,18 @@ discard block |
||
| 601 | 601 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
| 602 | 602 | * @return array |
| 603 | 603 | */ |
| 604 | -function getpaid_should_group_subscriptions( $invoice ) { |
|
| 604 | +function getpaid_should_group_subscriptions($invoice) { |
|
| 605 | 605 | |
| 606 | 606 | $recurring_items = 0; |
| 607 | 607 | |
| 608 | - foreach ( $invoice->get_items() as $item ) { |
|
| 608 | + foreach ($invoice->get_items() as $item) { |
|
| 609 | 609 | |
| 610 | - if ( $item->is_recurring() ) { |
|
| 611 | - $recurring_items ++; |
|
| 610 | + if ($item->is_recurring()) { |
|
| 611 | + $recurring_items++; |
|
| 612 | 612 | } |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
| 615 | + return apply_filters('getpaid_should_group_subscriptions', $recurring_items > 1, $invoice); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -622,12 +622,12 @@ discard block |
||
| 622 | 622 | * @param int|false $subscription_id |
| 623 | 623 | * @return int |
| 624 | 624 | */ |
| 625 | -function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) { |
|
| 625 | +function getpaid_count_subscription_invoices($parent_invoice_id, $subscription_id = false) { |
|
| 626 | 626 | global $wpdb; |
| 627 | 627 | |
| 628 | 628 | $parent_invoice_id = (int) $parent_invoice_id; |
| 629 | 629 | |
| 630 | - if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) { |
|
| 630 | + if (false === $subscription_id || !(bool) get_post_meta($parent_invoice_id, '_wpinv_subscription_id', true)) { |
|
| 631 | 631 | |
| 632 | 632 | return (int) $wpdb->get_var( |
| 633 | 633 | $wpdb->prepare( |
@@ -649,10 +649,10 @@ discard block |
||
| 649 | 649 | |
| 650 | 650 | $count = 0; |
| 651 | 651 | |
| 652 | - foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) { |
|
| 652 | + foreach (wp_parse_id_list($invoice_ids) as $invoice_id) { |
|
| 653 | 653 | |
| 654 | - if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) { |
|
| 655 | - $count ++; |
|
| 654 | + if ($invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta($invoice_id, '_wpinv_subscription_id', true)) { |
|
| 655 | + $count++; |
|
| 656 | 656 | continue; |
| 657 | 657 | } |
| 658 | 658 | } |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | $args = wp_parse_args( |
| 58 | 58 | $args, |
| 59 | 59 | array( |
| 60 | - 'status' => array( 'publish' ), |
|
| 61 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | - 'page' => 1, |
|
| 63 | - 'exclude' => array(), |
|
| 64 | - 'orderby' => 'date', |
|
| 65 | - 'order' => 'DESC', |
|
| 66 | - 'type' => wpinv_item_types(), |
|
| 67 | - 'meta_query' => array(), |
|
| 68 | - 'return' => 'objects', |
|
| 69 | - 'paginate' => false, |
|
| 60 | + 'status' => array( 'publish' ), |
|
| 61 | + 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | + 'page' => 1, |
|
| 63 | + 'exclude' => array(), |
|
| 64 | + 'orderby' => 'date', |
|
| 65 | + 'order' => 'DESC', |
|
| 66 | + 'type' => wpinv_item_types(), |
|
| 67 | + 'meta_query' => array(), |
|
| 68 | + 'return' => 'objects', |
|
| 69 | + 'paginate' => false, |
|
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | function wpinv_get_item_types() { |
| 208 | 208 | $item_types = array( |
| 209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 211 | - ); |
|
| 209 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
| 210 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
| 211 | + ); |
|
| 212 | 212 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
| 250 | 250 | if ( $post_ids ) { |
| 251 | 251 | $args = array( |
| 252 | - 'post_type' => 'wpi_item', |
|
| 253 | - 'orderby' => 'rand', |
|
| 254 | - 'post_count' => $num, |
|
| 255 | - 'fields' => 'ids', |
|
| 256 | - ); |
|
| 252 | + 'post_type' => 'wpi_item', |
|
| 253 | + 'orderby' => 'rand', |
|
| 254 | + 'post_count' => $num, |
|
| 255 | + 'fields' => 'ids', |
|
| 256 | + ); |
|
| 257 | 257 | } else { |
| 258 | 258 | $args = array( |
| 259 | - 'post_type' => 'wpi_item', |
|
| 260 | - 'orderby' => 'rand', |
|
| 261 | - 'post_count' => $num, |
|
| 262 | - ); |
|
| 259 | + 'post_type' => 'wpi_item', |
|
| 260 | + 'orderby' => 'rand', |
|
| 261 | + 'post_count' => $num, |
|
| 262 | + ); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $args = apply_filters( 'wpinv_get_random_items', $args ); |
@@ -427,10 +427,10 @@ discard block |
||
| 427 | 427 | $bill_times_less = $bill_times - 1; |
| 428 | 428 | |
| 429 | 429 | if ( ! empty( $bill_times ) ) { |
| 430 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 430 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 431 | 431 | $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
| 432 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 433 | - } |
|
| 432 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 433 | + } |
|
| 434 | 434 | |
| 435 | 435 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
| 436 | 436 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | * @param int the item ID to retrieve. |
| 15 | 15 | * @return WPInv_Item|false |
| 16 | 16 | */ |
| 17 | -function wpinv_get_item_by_id( $id ) { |
|
| 18 | - $item = wpinv_get_item( $id ); |
|
| 19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
| 17 | +function wpinv_get_item_by_id($id) { |
|
| 18 | + $item = wpinv_get_item($id); |
|
| 19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return WPInv_Item|false |
| 26 | 26 | */ |
| 27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
| 27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
| 28 | 28 | |
| 29 | - if ( 'id' == strtolower( $field ) ) { |
|
| 30 | - return wpinv_get_item_by_id( $field ); |
|
| 29 | + if ('id' == strtolower($field)) { |
|
| 30 | + return wpinv_get_item_by_id($field); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
| 34 | - return empty( $id ) ? false : wpinv_get_item( $id ); |
|
| 33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
| 34 | + return empty($id) ? false : wpinv_get_item($id); |
|
| 35 | 35 | |
| 36 | 36 | } |
| 37 | 37 | |
@@ -41,24 +41,24 @@ discard block |
||
| 41 | 41 | * @param int|WPInv_Item the item to retrieve. |
| 42 | 42 | * @return WPInv_Item|false |
| 43 | 43 | */ |
| 44 | -function wpinv_get_item( $item = 0 ) { |
|
| 44 | +function wpinv_get_item($item = 0) { |
|
| 45 | 45 | |
| 46 | - if ( empty( $item ) ) { |
|
| 46 | + if (empty($item)) { |
|
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $item = new WPInv_Item( $item ); |
|
| 50 | + $item = new WPInv_Item($item); |
|
| 51 | 51 | return $item->exists() ? $item : false; |
| 52 | 52 | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | -function wpinv_get_all_items( $args = array() ) { |
|
| 55 | +function wpinv_get_all_items($args = array()) { |
|
| 56 | 56 | |
| 57 | 57 | $args = wp_parse_args( |
| 58 | 58 | $args, |
| 59 | 59 | array( |
| 60 | - 'status' => array( 'publish' ), |
|
| 61 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 60 | + 'status' => array('publish'), |
|
| 61 | + 'limit' => get_option('posts_per_page'), |
|
| 62 | 62 | 'page' => 1, |
| 63 | 63 | 'exclude' => array(), |
| 64 | 64 | 'orderby' => 'date', |
@@ -78,44 +78,44 @@ discard block |
||
| 78 | 78 | 'fields' => 'ids', |
| 79 | 79 | 'orderby' => $args['orderby'], |
| 80 | 80 | 'order' => $args['order'], |
| 81 | - 'paged' => absint( $args['page'] ), |
|
| 81 | + 'paged' => absint($args['page']), |
|
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 85 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 84 | + if (!empty($args['exclude'])) { |
|
| 85 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( ! $args['paginate'] ) { |
|
| 88 | + if (!$args['paginate']) { |
|
| 89 | 89 | $wp_query_args['no_found_rows'] = true; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if ( ! empty( $args['search'] ) ) { |
|
| 92 | + if (!empty($args['search'])) { |
|
| 93 | 93 | $wp_query_args['s'] = $args['search']; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
| 97 | - $types = wpinv_parse_list( $args['type'] ); |
|
| 96 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
| 97 | + $types = wpinv_parse_list($args['type']); |
|
| 98 | 98 | $wp_query_args['meta_query'][] = array( |
| 99 | 99 | 'key' => '_wpinv_type', |
| 100 | - 'value' => implode( ',', $types ), |
|
| 100 | + 'value' => implode(',', $types), |
|
| 101 | 101 | 'compare' => 'IN', |
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args ); |
|
| 105 | + $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
|
| 106 | 106 | |
| 107 | 107 | // Get results. |
| 108 | - $items = new WP_Query( $wp_query_args ); |
|
| 108 | + $items = new WP_Query($wp_query_args); |
|
| 109 | 109 | |
| 110 | - if ( 'objects' === $args['return'] ) { |
|
| 111 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
| 112 | - } elseif ( 'self' === $args['return'] ) { |
|
| 110 | + if ('objects' === $args['return']) { |
|
| 111 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
| 112 | + } elseif ('self' === $args['return']) { |
|
| 113 | 113 | return $items; |
| 114 | 114 | } else { |
| 115 | 115 | $return = $items->posts; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if ( $args['paginate'] ) { |
|
| 118 | + if ($args['paginate']) { |
|
| 119 | 119 | return (object) array( |
| 120 | 120 | 'items' => $return, |
| 121 | 121 | 'total' => $items->found_posts, |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
| 131 | - if ( empty( $item_id ) ) { |
|
| 130 | +function wpinv_is_free_item($item_id = 0) { |
|
| 131 | + if (empty($item_id)) { |
|
| 132 | 132 | return false; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - $item = new WPInv_Item( $item_id ); |
|
| 135 | + $item = new WPInv_Item($item_id); |
|
| 136 | 136 | |
| 137 | 137 | return $item->is_free(); |
| 138 | 138 | } |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
| 144 | 144 | */ |
| 145 | -function wpinv_item_is_editable( $item = 0 ) { |
|
| 145 | +function wpinv_item_is_editable($item = 0) { |
|
| 146 | 146 | |
| 147 | 147 | // Fetch the item. |
| 148 | - $item = new WPInv_Item( $item ); |
|
| 148 | + $item = new WPInv_Item($item); |
|
| 149 | 149 | |
| 150 | 150 | // Check if it is editable. |
| 151 | 151 | return $item->is_editable(); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
| 155 | - if ( empty( $item_id ) ) { |
|
| 154 | +function wpinv_get_item_price($item_id = 0) { |
|
| 155 | + if (empty($item_id)) { |
|
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $item = new WPInv_Item( $item_id ); |
|
| 159 | + $item = new WPInv_Item($item_id); |
|
| 160 | 160 | |
| 161 | 161 | return $item->get_price(); |
| 162 | 162 | } |
@@ -166,88 +166,88 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @param WPInv_Item|int $item |
| 168 | 168 | */ |
| 169 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
| 170 | - $item = new WPInv_Item( $item ); |
|
| 169 | +function wpinv_is_recurring_item($item = 0) { |
|
| 170 | + $item = new WPInv_Item($item); |
|
| 171 | 171 | return $item->is_recurring(); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | -function wpinv_item_price( $item_id = 0 ) { |
|
| 175 | - if ( empty( $item_id ) ) { |
|
| 174 | +function wpinv_item_price($item_id = 0) { |
|
| 175 | + if (empty($item_id)) { |
|
| 176 | 176 | return false; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $price = wpinv_get_item_price( $item_id ); |
|
| 180 | - $price = wpinv_price( $price ); |
|
| 179 | + $price = wpinv_get_item_price($item_id); |
|
| 180 | + $price = wpinv_price($price); |
|
| 181 | 181 | |
| 182 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
| 182 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
| 186 | - if ( is_null( $amount_override ) ) { |
|
| 187 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
| 185 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
| 186 | + if (is_null($amount_override)) { |
|
| 187 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
| 188 | 188 | } else { |
| 189 | 189 | $original_price = $amount_override; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $price = $original_price; |
| 193 | 193 | |
| 194 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
| 194 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
| 198 | - if ( empty( $item_id ) ) { |
|
| 197 | +function wpinv_item_custom_singular_name($item_id) { |
|
| 198 | + if (empty($item_id)) { |
|
| 199 | 199 | return false; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - $item = new WPInv_Item( $item_id ); |
|
| 202 | + $item = new WPInv_Item($item_id); |
|
| 203 | 203 | |
| 204 | 204 | return $item->get_custom_singular_name(); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | function wpinv_get_item_types() { |
| 208 | 208 | $item_types = array( |
| 209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 209 | + 'custom' => __('Standard', 'invoicing'), |
|
| 210 | + 'fee' => __('Fee', 'invoicing'), |
|
| 211 | 211 | ); |
| 212 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
| 212 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | function wpinv_item_types() { |
| 216 | 216 | $item_types = wpinv_get_item_types(); |
| 217 | 217 | |
| 218 | - return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
| 218 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | -function wpinv_get_item_type( $item_id ) { |
|
| 222 | - if ( empty( $item_id ) ) { |
|
| 221 | +function wpinv_get_item_type($item_id) { |
|
| 222 | + if (empty($item_id)) { |
|
| 223 | 223 | return false; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - $item = new WPInv_Item( $item_id ); |
|
| 226 | + $item = new WPInv_Item($item_id); |
|
| 227 | 227 | |
| 228 | 228 | return $item->get_type(); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | -function wpinv_item_type( $item_id ) { |
|
| 231 | +function wpinv_item_type($item_id) { |
|
| 232 | 232 | $item_types = wpinv_get_item_types(); |
| 233 | 233 | |
| 234 | - $item_type = wpinv_get_item_type( $item_id ); |
|
| 234 | + $item_type = wpinv_get_item_type($item_id); |
|
| 235 | 235 | |
| 236 | - if ( empty( $item_type ) ) { |
|
| 236 | + if (empty($item_type)) { |
|
| 237 | 237 | $item_type = '-'; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' ); |
|
| 240 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
| 241 | 241 | |
| 242 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
| 242 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | -function wpinv_get_random_item( $post_ids = true ) { |
|
| 246 | - wpinv_get_random_items( 1, $post_ids ); |
|
| 245 | +function wpinv_get_random_item($post_ids = true) { |
|
| 246 | + wpinv_get_random_items(1, $post_ids); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
| 250 | - if ( $post_ids ) { |
|
| 249 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
| 250 | + if ($post_ids) { |
|
| 251 | 251 | $args = array( |
| 252 | 252 | 'post_type' => 'wpi_item', |
| 253 | 253 | 'orderby' => 'rand', |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | ); |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
| 265 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
| 266 | 266 | |
| 267 | - return get_posts( $args ); |
|
| 267 | + return get_posts($args); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | * @param WPInv_Item|int $item |
| 274 | 274 | * @param bool $html |
| 275 | 275 | */ |
| 276 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
| 276 | +function wpinv_get_item_suffix($item, $html = true) { |
|
| 277 | 277 | |
| 278 | - $item = new WPInv_Item( $item ); |
|
| 279 | - $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : ''; |
|
| 280 | - $suffix = $html ? $suffix : wp_strip_all_tags( $suffix ); |
|
| 278 | + $item = new WPInv_Item($item); |
|
| 279 | + $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : ''; |
|
| 280 | + $suffix = $html ? $suffix : wp_strip_all_tags($suffix); |
|
| 281 | 281 | |
| 282 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
| 282 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -288,9 +288,9 @@ discard block |
||
| 288 | 288 | * @param WPInv_Item|int $item |
| 289 | 289 | * @param bool $force_delete |
| 290 | 290 | */ |
| 291 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
| 292 | - $item = new WPInv_Item( $item ); |
|
| 293 | - $item->delete( $force_delete ); |
|
| 291 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
| 292 | + $item = new WPInv_Item($item); |
|
| 293 | + $item->delete($force_delete); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -329,44 +329,44 @@ discard block |
||
| 329 | 329 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
| 330 | 330 | * @return bool|WP_Error|WPInv_Item |
| 331 | 331 | */ |
| 332 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
| 332 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
| 333 | 333 | |
| 334 | 334 | // Prepare the item. |
| 335 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
| 336 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
| 337 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
| 335 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
| 336 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
| 337 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
| 338 | 338 | |
| 339 | - if ( ! empty( $item ) ) { |
|
| 339 | + if (!empty($item)) { |
|
| 340 | 340 | $args['ID'] = $item->get_id(); |
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // Do we have an item? |
| 345 | - if ( ! empty( $args['ID'] ) ) { |
|
| 346 | - $item = new WPInv_Item( $args['ID'] ); |
|
| 345 | + if (!empty($args['ID'])) { |
|
| 346 | + $item = new WPInv_Item($args['ID']); |
|
| 347 | 347 | } else { |
| 348 | 348 | $item = new WPInv_Item(); |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | // Do we have an error? |
| 352 | - if ( ! empty( $item->last_error ) ) { |
|
| 353 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
| 352 | + if (!empty($item->last_error)) { |
|
| 353 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Update item props. |
| 357 | - $item->set_props( $args ); |
|
| 357 | + $item->set_props($args); |
|
| 358 | 358 | |
| 359 | 359 | // Save the item. |
| 360 | 360 | $item->save(); |
| 361 | 361 | |
| 362 | 362 | // Do we have an error? |
| 363 | - if ( ! empty( $item->last_error ) ) { |
|
| 364 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
| 363 | + if (!empty($item->last_error)) { |
|
| 364 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | // Was the item saved? |
| 368 | - if ( ! $item->get_id() ) { |
|
| 369 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
| 368 | + if (!$item->get_id()) { |
|
| 369 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | return $item; |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | * |
| 379 | 379 | * @see wpinv_create_item() |
| 380 | 380 | */ |
| 381 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
| 382 | - return wpinv_create_item( $args, $wp_error ); |
|
| 381 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
| 382 | + return wpinv_create_item($args, $wp_error); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
| 386 | 386 | * Sanitizes a recurring period |
| 387 | 387 | */ |
| 388 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
| 388 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
| 389 | 389 | |
| 390 | 390 | $periods = array( |
| 391 | 391 | 'D' => 'day', |
@@ -394,16 +394,16 @@ discard block |
||
| 394 | 394 | 'Y' => 'year', |
| 395 | 395 | ); |
| 396 | 396 | |
| 397 | - if ( ! isset( $periods[ $period ] ) ) { |
|
| 397 | + if (!isset($periods[$period])) { |
|
| 398 | 398 | $period = 'D'; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - return $full ? $periods[ $period ] : $period; |
|
| 401 | + return $full ? $periods[$period] : $period; |
|
| 402 | 402 | |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | -function wpinv_item_max_buyable_quantity( $item_id ) { |
|
| 406 | - return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id ); |
|
| 405 | +function wpinv_item_max_buyable_quantity($item_id) { |
|
| 406 | + return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -411,47 +411,47 @@ discard block |
||
| 411 | 411 | * |
| 412 | 412 | * @param WPInv_Item|GetPaid_Form_Item $item |
| 413 | 413 | */ |
| 414 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
| 414 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
| 415 | 415 | |
| 416 | 416 | // Abort if it is not recurring. |
| 417 | - if ( ! $item->is_recurring() ) { |
|
| 417 | + if (!$item->is_recurring()) { |
|
| 418 | 418 | return ''; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
| 422 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
| 423 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
| 421 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
| 422 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
| 423 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
| 424 | 424 | $initial_class = 'getpaid-item-initial-price'; |
| 425 | 425 | $recurring_class = 'getpaid-item-recurring-price'; |
| 426 | 426 | $bill_times = $item->get_recurring_limit(); |
| 427 | 427 | $bill_times_less = $bill_times - 1; |
| 428 | 428 | |
| 429 | - if ( ! empty( $bill_times ) ) { |
|
| 429 | + if (!empty($bill_times)) { |
|
| 430 | 430 | $bill_times = $item->get_recurring_interval() * $bill_times; |
| 431 | - $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
|
| 432 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 431 | + $bill_times_less = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times - $item->get_recurring_interval()); |
|
| 432 | + $bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
| 436 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
| 437 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
| 435 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
| 436 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
| 437 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
| 441 | - return __( 'Free forever', 'invoicing' ); |
|
| 440 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
| 441 | + return __('Free forever', 'invoicing'); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | // For free trial items. |
| 445 | - if ( $item->has_free_trial() ) { |
|
| 446 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
| 445 | + if ($item->has_free_trial()) { |
|
| 446 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
| 447 | 447 | |
| 448 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
| 448 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
| 449 | 449 | |
| 450 | - if ( empty( $bill_times ) ) { |
|
| 450 | + if (empty($bill_times)) { |
|
| 451 | 451 | |
| 452 | 452 | return sprintf( |
| 453 | 453 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
| 454 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
| 454 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
| 455 | 455 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 456 | 456 | "<span class='$recurring_class'>$recurring_price</span>", |
| 457 | 457 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | |
| 462 | 462 | return sprintf( |
| 463 | 463 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times |
| 464 | - _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 464 | + _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
| 465 | 465 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 466 | 466 | "<span class='$recurring_class'>$recurring_price</span>", |
| 467 | 467 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -470,11 +470,11 @@ discard block |
||
| 470 | 470 | |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - if ( empty( $bill_times ) ) { |
|
| 473 | + if (empty($bill_times)) { |
|
| 474 | 474 | |
| 475 | 475 | return sprintf( |
| 476 | 476 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
| 477 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
| 477 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
| 478 | 478 | "<span class='$initial_class'>$initial_price</span>", |
| 479 | 479 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 480 | 480 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | |
| 486 | 486 | return sprintf( |
| 487 | 487 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times |
| 488 | - _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ), |
|
| 488 | + _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'), |
|
| 489 | 489 | "<span class='$initial_class'>$initial_price</span>", |
| 490 | 490 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 491 | 491 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -495,13 +495,13 @@ discard block |
||
| 495 | 495 | |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - if ( $initial_price == $recurring_price ) { |
|
| 498 | + if ($initial_price == $recurring_price) { |
|
| 499 | 499 | |
| 500 | - if ( empty( $bill_times ) ) { |
|
| 500 | + if (empty($bill_times)) { |
|
| 501 | 501 | |
| 502 | 502 | return sprintf( |
| 503 | 503 | // translators: $1: is the recurring price, $2: is the susbcription period |
| 504 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 504 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
| 505 | 505 | "<span class='$recurring_class'>$recurring_price</span>", |
| 506 | 506 | "<span class='getpaid-item-recurring-period'>$period</span>" |
| 507 | 507 | ); |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | |
| 511 | 511 | return sprintf( |
| 512 | 512 | // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times |
| 513 | - _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 513 | + _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
| 514 | 514 | "<span class='$recurring_class'>$recurring_price</span>", |
| 515 | 515 | "<span class='getpaid-item-recurring-period'>$period</span>", |
| 516 | 516 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -518,13 +518,13 @@ discard block |
||
| 518 | 518 | |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
| 521 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
| 522 | 522 | |
| 523 | - if ( empty( $bill_times ) ) { |
|
| 523 | + if (empty($bill_times)) { |
|
| 524 | 524 | |
| 525 | 525 | return sprintf( |
| 526 | 526 | // translators: $1: is the recurring period, $2: is the recurring price |
| 527 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
| 527 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
| 528 | 528 | "<span class='getpaid-item-recurring-period'>$period</span>", |
| 529 | 529 | "<span class='$recurring_class'>$recurring_price</span>" |
| 530 | 530 | ); |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | |
| 534 | 534 | return sprintf( |
| 535 | 535 | // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times |
| 536 | - _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ), |
|
| 536 | + _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'), |
|
| 537 | 537 | "<span class='getpaid-item-recurring-period'>$period</span>", |
| 538 | 538 | "<span class='$recurring_class'>$recurring_price</span>", |
| 539 | 539 | "<span class='getpaid-item-recurring-bill-times'>$bill_times_less</span>" |
@@ -541,11 +541,11 @@ discard block |
||
| 541 | 541 | |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - if ( empty( $bill_times ) ) { |
|
| 544 | + if (empty($bill_times)) { |
|
| 545 | 545 | |
| 546 | 546 | return sprintf( |
| 547 | 547 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
| 548 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
| 548 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
| 549 | 549 | "<span class='$initial_class'>$initial_price</span>", |
| 550 | 550 | "<span class='$recurring_class'>$recurring_price</span>", |
| 551 | 551 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | return sprintf( |
| 557 | 557 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times |
| 558 | - _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ), |
|
| 558 | + _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'), |
|
| 559 | 559 | "<span class='$initial_class'>$initial_price</span>", |
| 560 | 560 | "<span class='$recurring_class'>$recurring_price</span>", |
| 561 | 561 | "<span class='getpaid-item-recurring-period'>$period</span>", |