@@ -24,64 +24,64 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | <?php |
| 26 | 26 | |
| 27 | - // Fires before printing a line item column. |
|
| 28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
| 27 | + // Fires before printing a line item column. |
|
| 28 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
| 29 | 29 | |
| 30 | - // Item name. |
|
| 31 | - if ( 'name' == $key ) { |
|
| 30 | + // Item name. |
|
| 31 | + if ( 'name' == $key ) { |
|
| 32 | 32 | |
| 33 | - // Display the name. |
|
| 34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
| 33 | + // Display the name. |
|
| 34 | + echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
| 35 | 35 | |
| 36 | - // And an optional description. |
|
| 36 | + // And an optional description. |
|
| 37 | 37 | $description = $item->get_description(); |
| 38 | 38 | |
| 39 | 39 | if ( ! empty( $description ) ) { |
| 40 | 40 | $description = wp_kses_post( $description ); |
| 41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // Price help text. |
|
| 44 | + // Price help text. |
|
| 45 | 45 | $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
| 46 | 46 | if ( $description ) { |
| 47 | 47 | echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>"; |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // Item price. |
|
| 53 | - if ( 'price' == $key ) { |
|
| 52 | + // Item price. |
|
| 53 | + if ( 'price' == $key ) { |
|
| 54 | 54 | |
| 55 | - // Set the currency position. |
|
| 56 | - $position = wpinv_currency_position(); |
|
| 55 | + // Set the currency position. |
|
| 56 | + $position = wpinv_currency_position(); |
|
| 57 | 57 | |
| 58 | - if ( $position == 'left_space' ) { |
|
| 59 | - $position = 'left'; |
|
| 60 | - } |
|
| 58 | + if ( $position == 'left_space' ) { |
|
| 59 | + $position = 'left'; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if ( $position == 'right_space' ) { |
|
| 63 | - $position = 'right'; |
|
| 64 | - } |
|
| 62 | + if ( $position == 'right_space' ) { |
|
| 63 | + $position = 'right'; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if ( $item->user_can_set_their_price() ) { |
|
| 67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
| 68 | - $minimum = (float) $item->get_minimum_price(); |
|
| 69 | - $validate_minimum = ''; |
|
| 70 | - $class = ''; |
|
| 71 | - $data_minimum = ''; |
|
| 66 | + if ( $item->user_can_set_their_price() ) { |
|
| 67 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
| 68 | + $minimum = (float) $item->get_minimum_price(); |
|
| 69 | + $validate_minimum = ''; |
|
| 70 | + $class = ''; |
|
| 71 | + $data_minimum = ''; |
|
| 72 | 72 | |
| 73 | - if ( $minimum > 0 ) { |
|
| 74 | - $validate_minimum = sprintf( |
|
| 75 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
| 76 | - sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
| 77 | - ); |
|
| 73 | + if ( $minimum > 0 ) { |
|
| 74 | + $validate_minimum = sprintf( |
|
| 75 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
| 76 | + sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - $class = 'getpaid-validate-minimum-amount'; |
|
| 79 | + $class = 'getpaid-validate-minimum-amount'; |
|
| 80 | 80 | |
| 81 | - $data_minimum = "data-minimum-amount='$minimum'"; |
|
| 82 | - } |
|
| 81 | + $data_minimum = "data-minimum-amount='$minimum'"; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - ?> |
|
| 84 | + ?> |
|
| 85 | 85 | <div class="input-group input-group-sm"> |
| 86 | 86 | <?php if( 'left' == $position ) : ?> |
| 87 | 87 | <div class="input-group-prepend"> |
@@ -105,37 +105,37 @@ discard block |
||
| 105 | 105 | </div> |
| 106 | 106 | |
| 107 | 107 | <?php |
| 108 | - } else { |
|
| 109 | - echo wpinv_price( $item->get_price(), $currency ); |
|
| 110 | - ?> |
|
| 108 | + } else { |
|
| 109 | + echo wpinv_price( $item->get_price(), $currency ); |
|
| 110 | + ?> |
|
| 111 | 111 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
| 112 | 112 | <?php |
| 113 | - } |
|
| 114 | - } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - // Item quantity. |
|
| 117 | - if ( 'quantity' == $key ) { |
|
| 116 | + // Item quantity. |
|
| 117 | + if ( 'quantity' == $key ) { |
|
| 118 | 118 | |
| 119 | - if ( $item->allows_quantities() ) { |
|
| 120 | - ?> |
|
| 119 | + if ( $item->allows_quantities() ) { |
|
| 120 | + ?> |
|
| 121 | 121 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required> |
| 122 | 122 | <?php |
| 123 | - } else { |
|
| 124 | - echo (float) $item->get_quantity(); |
|
| 125 | - echo ' '; |
|
| 126 | - ?> |
|
| 123 | + } else { |
|
| 124 | + echo (float) $item->get_quantity(); |
|
| 125 | + echo ' '; |
|
| 126 | + ?> |
|
| 127 | 127 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
| 128 | 128 | <?php |
| 129 | - } |
|
| 130 | - } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // Item sub total. |
|
| 133 | - if ( 'subtotal' == $key ) { |
|
| 134 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
| 135 | - } |
|
| 132 | + // Item sub total. |
|
| 133 | + if ( 'subtotal' == $key ) { |
|
| 134 | + echo wpinv_price( $item->get_sub_total(), $currency ); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
| 138 | - ?> |
|
| 137 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
| 138 | + ?> |
|
| 139 | 139 | |
| 140 | 140 | </div> |
| 141 | 141 | |
@@ -7,116 +7,116 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | -do_action( 'getpaid_before_payment_form_cart_item', $form, $item ); |
|
| 12 | +do_action('getpaid_before_payment_form_cart_item', $form, $item); |
|
| 13 | 13 | |
| 14 | 14 | $currency = $form->get_currency(); |
| 15 | 15 | |
| 16 | 16 | ?> |
| 17 | -<div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo $item->get_id(); ?> border-bottom py-2 px-3'> |
|
| 17 | +<div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo $item->get_id(); ?> border-bottom py-2 px-3'> |
|
| 18 | 18 | |
| 19 | 19 | <div class="form-row needs-validation"> |
| 20 | 20 | |
| 21 | - <?php foreach ( array_keys( $columns ) as $key ) : ?> |
|
| 21 | + <?php foreach (array_keys($columns) as $key) : ?> |
|
| 22 | 22 | |
| 23 | - <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> position-relative getpaid-form-cart-item-<?php echo sanitize_html_class( $key ); ?> getpaid-form-cart-item-<?php echo sanitize_html_class( $key ); ?>-<?php echo $item->get_id(); ?>"> |
|
| 23 | + <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> position-relative getpaid-form-cart-item-<?php echo sanitize_html_class($key); ?> getpaid-form-cart-item-<?php echo sanitize_html_class($key); ?>-<?php echo $item->get_id(); ?>"> |
|
| 24 | 24 | |
| 25 | 25 | <?php |
| 26 | 26 | |
| 27 | 27 | // Fires before printing a line item column. |
| 28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
| 28 | + do_action("getpaid_form_cart_item_before_$key", $item, $form); |
|
| 29 | 29 | |
| 30 | 30 | // Item name. |
| 31 | - if ( 'name' == $key ) { |
|
| 31 | + if ('name' == $key) { |
|
| 32 | 32 | |
| 33 | 33 | // Display the name. |
| 34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
| 34 | + echo '<div class="mb-1">' . sanitize_text_field($item->get_name()) . '</div>'; |
|
| 35 | 35 | |
| 36 | 36 | // And an optional description. |
| 37 | 37 | $description = $item->get_description(); |
| 38 | 38 | |
| 39 | - if ( ! empty( $description ) ) { |
|
| 40 | - $description = wp_kses_post( $description ); |
|
| 39 | + if (!empty($description)) { |
|
| 40 | + $description = wp_kses_post($description); |
|
| 41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | // Price help text. |
| 45 | - $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
| 46 | - if ( $description ) { |
|
| 45 | + $description = getpaid_item_recurring_price_help_text($item, $currency); |
|
| 46 | + if ($description) { |
|
| 47 | 47 | echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>"; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Item price. |
| 53 | - if ( 'price' == $key ) { |
|
| 53 | + if ('price' == $key) { |
|
| 54 | 54 | |
| 55 | 55 | // Set the currency position. |
| 56 | 56 | $position = wpinv_currency_position(); |
| 57 | 57 | |
| 58 | - if ( $position == 'left_space' ) { |
|
| 58 | + if ($position == 'left_space') { |
|
| 59 | 59 | $position = 'left'; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ( $position == 'right_space' ) { |
|
| 62 | + if ($position == 'right_space') { |
|
| 63 | 63 | $position = 'right'; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ( $item->user_can_set_their_price() ) { |
|
| 67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
| 66 | + if ($item->user_can_set_their_price()) { |
|
| 67 | + $price = max((float) $item->get_price(), (float) $item->get_minimum_price()); |
|
| 68 | 68 | $minimum = (float) $item->get_minimum_price(); |
| 69 | 69 | $validate_minimum = ''; |
| 70 | 70 | $class = ''; |
| 71 | 71 | $data_minimum = ''; |
| 72 | 72 | |
| 73 | - if ( $minimum > 0 ) { |
|
| 73 | + if ($minimum > 0) { |
|
| 74 | 74 | $validate_minimum = sprintf( |
| 75 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
| 76 | - sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
| 75 | + esc_attr__('The minimum allowed amount is %s', 'invoicing'), |
|
| 76 | + sanitize_text_field(wpinv_price($minimum, $currency)) |
|
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | 79 | $class = 'getpaid-validate-minimum-amount'; |
| 80 | 80 | |
| 81 | - $data_minimum = "data-minimum-amount='$minimum'"; |
|
| 81 | + $data_minimum = "data-minimum-amount='$minimum'"; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | ?> |
| 85 | 85 | <div class="input-group input-group-sm"> |
| 86 | - <?php if( 'left' == $position ) : ?> |
|
| 86 | + <?php if ('left' == $position) : ?> |
|
| 87 | 87 | <div class="input-group-prepend"> |
| 88 | - <span class="input-group-text"><?php echo wpinv_currency_symbol( $currency ); ?></span> |
|
| 88 | + <span class="input-group-text"><?php echo wpinv_currency_symbol($currency); ?></span> |
|
| 89 | 89 | </div> |
| 90 | 90 | <?php endif; ?> |
| 91 | 91 | |
| 92 | - <input type="text" <?php echo $data_minimum; ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo $price; ?>" placeholder="<?php echo esc_attr( $item->get_minimum_price() ); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo $class; ?>" style="width: 64px; line-height: 1; min-height: 35px;"> |
|
| 92 | + <input type="text" <?php echo $data_minimum; ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo $price; ?>" placeholder="<?php echo esc_attr($item->get_minimum_price()); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo $class; ?>" style="width: 64px; line-height: 1; min-height: 35px;"> |
|
| 93 | 93 | |
| 94 | - <?php if ( ! empty( $validate_minimum ) ) : ?> |
|
| 94 | + <?php if (!empty($validate_minimum)) : ?> |
|
| 95 | 95 | <div class="invalid-tooltip"> |
| 96 | 96 | <?php echo $validate_minimum; ?> |
| 97 | 97 | </div> |
| 98 | 98 | <?php endif; ?> |
| 99 | 99 | |
| 100 | - <?php if( 'left' != $position ) : ?> |
|
| 100 | + <?php if ('left' != $position) : ?> |
|
| 101 | 101 | <div class="input-group-append"> |
| 102 | - <span class="input-group-text"><?php echo wpinv_currency_symbol( $currency ); ?></span> |
|
| 102 | + <span class="input-group-text"><?php echo wpinv_currency_symbol($currency); ?></span> |
|
| 103 | 103 | </div> |
| 104 | 104 | <?php endif; ?> |
| 105 | 105 | </div> |
| 106 | 106 | |
| 107 | 107 | <?php |
| 108 | 108 | } else { |
| 109 | - echo wpinv_price( $item->get_price(), $currency ); |
|
| 109 | + echo wpinv_price($item->get_price(), $currency); |
|
| 110 | 110 | ?> |
| 111 | - <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
|
| 111 | + <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr($item->get_price()); ?>'> |
|
| 112 | 112 | <?php |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Item quantity. |
| 117 | - if ( 'quantity' == $key ) { |
|
| 117 | + if ('quantity' == $key) { |
|
| 118 | 118 | |
| 119 | - if ( $item->allows_quantities() ) { |
|
| 119 | + if ($item->allows_quantities()) { |
|
| 120 | 120 | ?> |
| 121 | 121 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required> |
| 122 | 122 | <?php |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Item sub total. |
| 133 | - if ( 'subtotal' == $key ) { |
|
| 134 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
| 133 | + if ('subtotal' == $key) { |
|
| 134 | + echo wpinv_price($item->get_sub_total(), $currency); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
| 137 | + do_action("getpaid_payment_form_cart_item_$key", $item, $form); |
|
| 138 | 138 | ?> |
| 139 | 139 | |
| 140 | 140 | </div> |
@@ -145,4 +145,4 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | </div> |
| 147 | 147 | <?php |
| 148 | -do_action( 'getpaid_payment_form_cart_item', $form, $item ); |
|
| 148 | +do_action('getpaid_payment_form_cart_item', $form, $item); |
|
@@ -12,255 +12,255 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Contains the response for refreshing prices. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $response = array(); |
|
| 15 | + /** |
|
| 16 | + * Contains the response for refreshing prices. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $response = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $this->response = array( |
|
| 29 | - 'submission_id' => $submission->id, |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $this->response = array( |
|
| 29 | + 'submission_id' => $submission->id, |
|
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | 31 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 32 | - ); |
|
| 33 | - |
|
| 34 | - $this->add_totals( $submission ); |
|
| 35 | - $this->add_texts( $submission ); |
|
| 36 | - $this->add_items( $submission ); |
|
| 37 | - $this->add_fees( $submission ); |
|
| 38 | - $this->add_discounts( $submission ); |
|
| 39 | - $this->add_taxes( $submission ); |
|
| 40 | - $this->add_gateways( $submission ); |
|
| 41 | - |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Adds totals to a response for submission refresh prices. |
|
| 46 | - * |
|
| 47 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 48 | - */ |
|
| 49 | - public function add_totals( $submission ) { |
|
| 50 | - |
|
| 51 | - $this->response = array_merge( |
|
| 52 | - $this->response, |
|
| 53 | - array( |
|
| 54 | - |
|
| 55 | - 'totals' => array( |
|
| 56 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 57 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 58 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 59 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 60 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 61 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 62 | - ), |
|
| 63 | - |
|
| 64 | - 'recurring' => array( |
|
| 65 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 66 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 67 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 68 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 69 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 70 | - ), |
|
| 71 | - |
|
| 72 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 73 | - 'currency' => $submission->get_currency(), |
|
| 74 | - |
|
| 75 | - ) |
|
| 76 | - ); |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Adds texts to a response for submission refresh prices. |
|
| 82 | - * |
|
| 83 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 84 | - */ |
|
| 85 | - public function add_texts( $submission ) { |
|
| 86 | - |
|
| 87 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 88 | - |
|
| 89 | - if ( $submission->has_recurring != 0 ) { |
|
| 90 | - |
|
| 91 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 92 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 93 | - |
|
| 94 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 95 | - $payable = "$payable / $period"; |
|
| 96 | - } else { |
|
| 97 | - $payable = sprintf( |
|
| 98 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 99 | - $submission->format_amount( $submission->get_total() ), |
|
| 100 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 101 | - $period |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $texts = array( |
|
| 108 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 109 | - ); |
|
| 110 | - |
|
| 111 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
| 112 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 113 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 114 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 118 | - |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Adds items to a response for submission refresh prices. |
|
| 123 | - * |
|
| 124 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 125 | - */ |
|
| 126 | - public function add_items( $submission ) { |
|
| 127 | - |
|
| 128 | - // Add items. |
|
| 129 | - $items = array(); |
|
| 32 | + ); |
|
| 33 | + |
|
| 34 | + $this->add_totals( $submission ); |
|
| 35 | + $this->add_texts( $submission ); |
|
| 36 | + $this->add_items( $submission ); |
|
| 37 | + $this->add_fees( $submission ); |
|
| 38 | + $this->add_discounts( $submission ); |
|
| 39 | + $this->add_taxes( $submission ); |
|
| 40 | + $this->add_gateways( $submission ); |
|
| 41 | + |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Adds totals to a response for submission refresh prices. |
|
| 46 | + * |
|
| 47 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 48 | + */ |
|
| 49 | + public function add_totals( $submission ) { |
|
| 50 | + |
|
| 51 | + $this->response = array_merge( |
|
| 52 | + $this->response, |
|
| 53 | + array( |
|
| 54 | + |
|
| 55 | + 'totals' => array( |
|
| 56 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 57 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 58 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 59 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 60 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 61 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 62 | + ), |
|
| 63 | + |
|
| 64 | + 'recurring' => array( |
|
| 65 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 66 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 67 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 68 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 69 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 70 | + ), |
|
| 71 | + |
|
| 72 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 73 | + 'currency' => $submission->get_currency(), |
|
| 74 | + |
|
| 75 | + ) |
|
| 76 | + ); |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Adds texts to a response for submission refresh prices. |
|
| 82 | + * |
|
| 83 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 84 | + */ |
|
| 85 | + public function add_texts( $submission ) { |
|
| 86 | + |
|
| 87 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 88 | + |
|
| 89 | + if ( $submission->has_recurring != 0 ) { |
|
| 90 | + |
|
| 91 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 92 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 93 | + |
|
| 94 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 95 | + $payable = "$payable / $period"; |
|
| 96 | + } else { |
|
| 97 | + $payable = sprintf( |
|
| 98 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 99 | + $submission->format_amount( $submission->get_total() ), |
|
| 100 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 101 | + $period |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $texts = array( |
|
| 108 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 109 | + ); |
|
| 130 | 110 | |
| 131 | 111 | foreach ( $submission->get_items() as $item_id => $item ) { |
| 132 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 133 | - } |
|
| 112 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 113 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 114 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 115 | + } |
|
| 134 | 116 | |
| 135 | - $this->response = array_merge( |
|
| 136 | - $this->response, |
|
| 137 | - array( 'items' => $items ) |
|
| 138 | - ); |
|
| 117 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 139 | 118 | |
| 140 | - } |
|
| 119 | + } |
|
| 141 | 120 | |
| 142 | - /** |
|
| 143 | - * Adds fees to a response for submission refresh prices. |
|
| 144 | - * |
|
| 145 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 146 | - */ |
|
| 147 | - public function add_fees( $submission ) { |
|
| 121 | + /** |
|
| 122 | + * Adds items to a response for submission refresh prices. |
|
| 123 | + * |
|
| 124 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 125 | + */ |
|
| 126 | + public function add_items( $submission ) { |
|
| 127 | + |
|
| 128 | + // Add items. |
|
| 129 | + $items = array(); |
|
| 130 | + |
|
| 131 | + foreach ( $submission->get_items() as $item_id => $item ) { |
|
| 132 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 133 | + } |
|
| 148 | 134 | |
| 149 | - $fees = array(); |
|
| 135 | + $this->response = array_merge( |
|
| 136 | + $this->response, |
|
| 137 | + array( 'items' => $items ) |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Adds fees to a response for submission refresh prices. |
|
| 144 | + * |
|
| 145 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 146 | + */ |
|
| 147 | + public function add_fees( $submission ) { |
|
| 148 | + |
|
| 149 | + $fees = array(); |
|
| 150 | 150 | |
| 151 | 151 | foreach ( $submission->get_fees() as $name => $data ) { |
| 152 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 153 | - } |
|
| 152 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $this->response = array_merge( |
|
| 156 | - $this->response, |
|
| 157 | - array( 'fees' => $fees ) |
|
| 158 | - ); |
|
| 155 | + $this->response = array_merge( |
|
| 156 | + $this->response, |
|
| 157 | + array( 'fees' => $fees ) |
|
| 158 | + ); |
|
| 159 | 159 | |
| 160 | - } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Adds discounts to a response for submission refresh prices. |
|
| 164 | - * |
|
| 165 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 166 | - */ |
|
| 167 | - public function add_discounts( $submission ) { |
|
| 162 | + /** |
|
| 163 | + * Adds discounts to a response for submission refresh prices. |
|
| 164 | + * |
|
| 165 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 166 | + */ |
|
| 167 | + public function add_discounts( $submission ) { |
|
| 168 | 168 | |
| 169 | - $discounts = array(); |
|
| 169 | + $discounts = array(); |
|
| 170 | 170 | |
| 171 | 171 | foreach ( $submission->get_discounts() as $name => $data ) { |
| 172 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $this->response = array_merge( |
|
| 176 | - $this->response, |
|
| 177 | - array( 'discounts' => $discounts ) |
|
| 178 | - ); |
|
| 172 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 173 | + } |
|
| 179 | 174 | |
| 180 | - } |
|
| 175 | + $this->response = array_merge( |
|
| 176 | + $this->response, |
|
| 177 | + array( 'discounts' => $discounts ) |
|
| 178 | + ); |
|
| 181 | 179 | |
| 182 | - /** |
|
| 183 | - * Adds taxes to a response for submission refresh prices. |
|
| 184 | - * |
|
| 185 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 186 | - */ |
|
| 187 | - public function add_taxes( $submission ) { |
|
| 180 | + } |
|
| 188 | 181 | |
| 189 | - $taxes = array(); |
|
| 190 | - $markup = ''; |
|
| 182 | + /** |
|
| 183 | + * Adds taxes to a response for submission refresh prices. |
|
| 184 | + * |
|
| 185 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 186 | + */ |
|
| 187 | + public function add_taxes( $submission ) { |
|
| 188 | + |
|
| 189 | + $taxes = array(); |
|
| 190 | + $markup = ''; |
|
| 191 | 191 | foreach ( $submission->get_taxes() as $name => $data ) { |
| 192 | - $name = sanitize_text_field( $name ); |
|
| 193 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 194 | - $taxes[$name] = $amount; |
|
| 195 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 196 | - } |
|
| 192 | + $name = sanitize_text_field( $name ); |
|
| 193 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 194 | + $taxes[$name] = $amount; |
|
| 195 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - if ( wpinv_display_individual_tax_rates() ) { |
|
| 199 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 200 | - } |
|
| 198 | + if ( wpinv_display_individual_tax_rates() ) { |
|
| 199 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - $this->response = array_merge( |
|
| 203 | - $this->response, |
|
| 204 | - array( 'taxes' => $taxes ) |
|
| 205 | - ); |
|
| 202 | + $this->response = array_merge( |
|
| 203 | + $this->response, |
|
| 204 | + array( 'taxes' => $taxes ) |
|
| 205 | + ); |
|
| 206 | 206 | |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Adds gateways to a response for submission refresh prices. |
|
| 211 | - * |
|
| 212 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 213 | - */ |
|
| 214 | - public function add_gateways( $submission ) { |
|
| 209 | + /** |
|
| 210 | + * Adds gateways to a response for submission refresh prices. |
|
| 211 | + * |
|
| 212 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 213 | + */ |
|
| 214 | + public function add_gateways( $submission ) { |
|
| 215 | 215 | |
| 216 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 216 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 217 | 217 | |
| 218 | - if ( $this->response['has_recurring'] ) { |
|
| 218 | + if ( $this->response['has_recurring'] ) { |
|
| 219 | 219 | |
| 220 | - foreach ( $gateways as $i => $gateway ) { |
|
| 220 | + foreach ( $gateways as $i => $gateway ) { |
|
| 221 | 221 | |
| 222 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 223 | - unset( $gateways[ $i ] ); |
|
| 224 | - } |
|
| 222 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 223 | + unset( $gateways[ $i ] ); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | 230 | |
| 231 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 232 | - $this->response = array_merge( |
|
| 233 | - $this->response, |
|
| 234 | - array( 'gateways' => $gateways ) |
|
| 235 | - ); |
|
| 231 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 232 | + $this->response = array_merge( |
|
| 233 | + $this->response, |
|
| 234 | + array( 'gateways' => $gateways ) |
|
| 235 | + ); |
|
| 236 | 236 | |
| 237 | - } |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Standardizes prices. |
|
| 241 | - * |
|
| 242 | - * @param int $item_id |
|
| 243 | - * @param float $item_total |
|
| 244 | - * @param string $discount_code |
|
| 245 | - * @param bool $recurring |
|
| 246 | - */ |
|
| 247 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 239 | + /** |
|
| 240 | + * Standardizes prices. |
|
| 241 | + * |
|
| 242 | + * @param int $item_id |
|
| 243 | + * @param float $item_total |
|
| 244 | + * @param string $discount_code |
|
| 245 | + * @param bool $recurring |
|
| 246 | + */ |
|
| 247 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 248 | 248 | |
| 249 | - $standardadized_price = $item_total; |
|
| 249 | + $standardadized_price = $item_total; |
|
| 250 | 250 | |
| 251 | - // Do we have a $discount_code? |
|
| 252 | - if ( ! empty( $discount_code ) ) { |
|
| 251 | + // Do we have a $discount_code? |
|
| 252 | + if ( ! empty( $discount_code ) ) { |
|
| 253 | 253 | |
| 254 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 254 | + $discount = new WPInv_Discount( $discount_code ); |
|
| 255 | 255 | |
| 256 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 257 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 258 | - } |
|
| 256 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 257 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return max( 0, $standardadized_price ); |
|
| 262 | + return max( 0, $standardadized_price ); |
|
| 263 | 263 | |
| 264 | - } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission refresh prices class |
@@ -23,21 +23,21 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
| 25 | 25 | */ |
| 26 | - public function __construct( $submission ) { |
|
| 26 | + public function __construct($submission) { |
|
| 27 | 27 | |
| 28 | 28 | $this->response = array( |
| 29 | 29 | 'submission_id' => $submission->id, |
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
| 31 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | - $this->add_totals( $submission ); |
|
| 35 | - $this->add_texts( $submission ); |
|
| 36 | - $this->add_items( $submission ); |
|
| 37 | - $this->add_fees( $submission ); |
|
| 38 | - $this->add_discounts( $submission ); |
|
| 39 | - $this->add_taxes( $submission ); |
|
| 40 | - $this->add_gateways( $submission ); |
|
| 34 | + $this->add_totals($submission); |
|
| 35 | + $this->add_texts($submission); |
|
| 36 | + $this->add_items($submission); |
|
| 37 | + $this->add_fees($submission); |
|
| 38 | + $this->add_discounts($submission); |
|
| 39 | + $this->add_taxes($submission); |
|
| 40 | + $this->add_gateways($submission); |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | |
@@ -46,30 +46,30 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @param GetPaid_Payment_Form_Submission $submission |
| 48 | 48 | */ |
| 49 | - public function add_totals( $submission ) { |
|
| 49 | + public function add_totals($submission) { |
|
| 50 | 50 | |
| 51 | 51 | $this->response = array_merge( |
| 52 | 52 | $this->response, |
| 53 | 53 | array( |
| 54 | 54 | |
| 55 | 55 | 'totals' => array( |
| 56 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 57 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 58 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 59 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 60 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 61 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 56 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
| 57 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
| 58 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
| 59 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
| 60 | + 'total' => $submission->format_amount($submission->get_total()), |
|
| 61 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
| 62 | 62 | ), |
| 63 | 63 | |
| 64 | 64 | 'recurring' => array( |
| 65 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 66 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 67 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 68 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 69 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 65 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
| 66 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
| 67 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
| 68 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
| 69 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
| 70 | 70 | ), |
| 71 | 71 | |
| 72 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 72 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
| 73 | 73 | 'currency' => $submission->get_currency(), |
| 74 | 74 | |
| 75 | 75 | ) |
@@ -82,22 +82,22 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @param GetPaid_Payment_Form_Submission $submission |
| 84 | 84 | */ |
| 85 | - public function add_texts( $submission ) { |
|
| 85 | + public function add_texts($submission) { |
|
| 86 | 86 | |
| 87 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 87 | + $payable = $submission->format_amount($submission->get_total()); |
|
| 88 | 88 | |
| 89 | - if ( $submission->has_recurring != 0 ) { |
|
| 89 | + if ($submission->has_recurring != 0) { |
|
| 90 | 90 | |
| 91 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 92 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 91 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
| 92 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
| 93 | 93 | |
| 94 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 94 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
| 95 | 95 | $payable = "$payable / $period"; |
| 96 | 96 | } else { |
| 97 | 97 | $payable = sprintf( |
| 98 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 99 | - $submission->format_amount( $submission->get_total() ), |
|
| 100 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 98 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
| 99 | + $submission->format_amount($submission->get_total()), |
|
| 100 | + $submission->format_amount($submission->get_recurring_total()), |
|
| 101 | 101 | $period |
| 102 | 102 | ); |
| 103 | 103 | } |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | '.getpaid-checkout-total-payable' => $payable, |
| 109 | 109 | ); |
| 110 | 110 | |
| 111 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
| 112 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 113 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 114 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 111 | + foreach ($submission->get_items() as $item_id => $item) { |
|
| 112 | + $initial_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false)); |
|
| 113 | + $recurring_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true)); |
|
| 114 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 117 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
| 118 | 118 | |
| 119 | 119 | } |
| 120 | 120 | |
@@ -123,18 +123,18 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @param GetPaid_Payment_Form_Submission $submission |
| 125 | 125 | */ |
| 126 | - public function add_items( $submission ) { |
|
| 126 | + public function add_items($submission) { |
|
| 127 | 127 | |
| 128 | 128 | // Add items. |
| 129 | 129 | $items = array(); |
| 130 | 130 | |
| 131 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
| 132 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 131 | + foreach ($submission->get_items() as $item_id => $item) { |
|
| 132 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $this->response = array_merge( |
| 136 | 136 | $this->response, |
| 137 | - array( 'items' => $items ) |
|
| 137 | + array('items' => $items) |
|
| 138 | 138 | ); |
| 139 | 139 | |
| 140 | 140 | } |
@@ -144,17 +144,17 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @param GetPaid_Payment_Form_Submission $submission |
| 146 | 146 | */ |
| 147 | - public function add_fees( $submission ) { |
|
| 147 | + public function add_fees($submission) { |
|
| 148 | 148 | |
| 149 | 149 | $fees = array(); |
| 150 | 150 | |
| 151 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
| 152 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 151 | + foreach ($submission->get_fees() as $name => $data) { |
|
| 152 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | $this->response = array_merge( |
| 156 | 156 | $this->response, |
| 157 | - array( 'fees' => $fees ) |
|
| 157 | + array('fees' => $fees) |
|
| 158 | 158 | ); |
| 159 | 159 | |
| 160 | 160 | } |
@@ -164,17 +164,17 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @param GetPaid_Payment_Form_Submission $submission |
| 166 | 166 | */ |
| 167 | - public function add_discounts( $submission ) { |
|
| 167 | + public function add_discounts($submission) { |
|
| 168 | 168 | |
| 169 | 169 | $discounts = array(); |
| 170 | 170 | |
| 171 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 172 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 171 | + foreach ($submission->get_discounts() as $name => $data) { |
|
| 172 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $this->response = array_merge( |
| 176 | 176 | $this->response, |
| 177 | - array( 'discounts' => $discounts ) |
|
| 177 | + array('discounts' => $discounts) |
|
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | 180 | } |
@@ -184,24 +184,24 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @param GetPaid_Payment_Form_Submission $submission |
| 186 | 186 | */ |
| 187 | - public function add_taxes( $submission ) { |
|
| 187 | + public function add_taxes($submission) { |
|
| 188 | 188 | |
| 189 | 189 | $taxes = array(); |
| 190 | 190 | $markup = ''; |
| 191 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 192 | - $name = sanitize_text_field( $name ); |
|
| 193 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 191 | + foreach ($submission->get_taxes() as $name => $data) { |
|
| 192 | + $name = sanitize_text_field($name); |
|
| 193 | + $amount = $submission->format_amount($data['initial_tax']); |
|
| 194 | 194 | $taxes[$name] = $amount; |
| 195 | 195 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - if ( wpinv_display_individual_tax_rates() ) { |
|
| 198 | + if (wpinv_display_individual_tax_rates()) { |
|
| 199 | 199 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $this->response = array_merge( |
| 203 | 203 | $this->response, |
| 204 | - array( 'taxes' => $taxes ) |
|
| 204 | + array('taxes' => $taxes) |
|
| 205 | 205 | ); |
| 206 | 206 | |
| 207 | 207 | } |
@@ -211,16 +211,16 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @param GetPaid_Payment_Form_Submission $submission |
| 213 | 213 | */ |
| 214 | - public function add_gateways( $submission ) { |
|
| 214 | + public function add_gateways($submission) { |
|
| 215 | 215 | |
| 216 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 216 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 217 | 217 | |
| 218 | - if ( $this->response['has_recurring'] ) { |
|
| 218 | + if ($this->response['has_recurring']) { |
|
| 219 | 219 | |
| 220 | - foreach ( $gateways as $i => $gateway ) { |
|
| 220 | + foreach ($gateways as $i => $gateway) { |
|
| 221 | 221 | |
| 222 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 223 | - unset( $gateways[ $i ] ); |
|
| 222 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
| 223 | + unset($gateways[$i]); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | } |
@@ -228,10 +228,10 @@ discard block |
||
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
| 231 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 231 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
| 232 | 232 | $this->response = array_merge( |
| 233 | 233 | $this->response, |
| 234 | - array( 'gateways' => $gateways ) |
|
| 234 | + array('gateways' => $gateways) |
|
| 235 | 235 | ); |
| 236 | 236 | |
| 237 | 237 | } |
@@ -244,22 +244,22 @@ discard block |
||
| 244 | 244 | * @param string $discount_code |
| 245 | 245 | * @param bool $recurring |
| 246 | 246 | */ |
| 247 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 247 | + public function standardize_price($item_id, $item_total, $discount_code, $recurring = false) { |
|
| 248 | 248 | |
| 249 | 249 | $standardadized_price = $item_total; |
| 250 | 250 | |
| 251 | 251 | // Do we have a $discount_code? |
| 252 | - if ( ! empty( $discount_code ) ) { |
|
| 252 | + if (!empty($discount_code)) { |
|
| 253 | 253 | |
| 254 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 254 | + $discount = new WPInv_Discount($discount_code); |
|
| 255 | 255 | |
| 256 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 257 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 256 | + if ($discount->exists() && $discount->is_valid_for_items($item_id) && (!$recurring || $discount->is_recurring())) { |
|
| 257 | + $standardadized_price = $item_total - $discount->get_discounted_amount($item_total); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - return max( 0, $standardadized_price ); |
|
| 262 | + return max(0, $standardadized_price); |
|
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
@@ -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,22 +41,22 @@ 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 | - $args = wp_parse_args( $args, array( |
|
| 58 | - 'status' => array( 'publish' ), |
|
| 59 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 57 | + $args = wp_parse_args($args, array( |
|
| 58 | + 'status' => array('publish'), |
|
| 59 | + 'limit' => get_option('posts_per_page'), |
|
| 60 | 60 | 'page' => 1, |
| 61 | 61 | 'exclude' => array(), |
| 62 | 62 | 'orderby' => 'date', |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | 'meta_query' => array(), |
| 66 | 66 | 'return' => 'objects', |
| 67 | 67 | 'paginate' => false, |
| 68 | - ) ); |
|
| 68 | + )); |
|
| 69 | 69 | |
| 70 | 70 | $wp_query_args = array( |
| 71 | 71 | 'post_type' => 'wpi_item', |
@@ -75,26 +75,26 @@ discard block |
||
| 75 | 75 | 'fields' => 'ids', |
| 76 | 76 | 'orderby' => $args['orderby'], |
| 77 | 77 | 'order' => $args['order'], |
| 78 | - 'paged' => absint( $args['page'] ), |
|
| 78 | + 'paged' => absint($args['page']), |
|
| 79 | 79 | ); |
| 80 | 80 | |
| 81 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 82 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 81 | + if (!empty($args['exclude'])) { |
|
| 82 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ( ! $args['paginate' ] ) { |
|
| 85 | + if (!$args['paginate']) { |
|
| 86 | 86 | $wp_query_args['no_found_rows'] = true; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ( ! empty( $args['search'] ) ) { |
|
| 89 | + if (!empty($args['search'])) { |
|
| 90 | 90 | $wp_query_args['s'] = $args['search']; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
| 94 | - $types = wpinv_parse_list( $args['type'] ); |
|
| 93 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
| 94 | + $types = wpinv_parse_list($args['type']); |
|
| 95 | 95 | $wp_query_args['meta_query'][] = array( |
| 96 | 96 | 'key' => '_wpinv_type', |
| 97 | - 'value' => implode( ',', $types ), |
|
| 97 | + 'value' => implode(',', $types), |
|
| 98 | 98 | 'compare' => 'IN', |
| 99 | 99 | ); |
| 100 | 100 | } |
@@ -102,17 +102,17 @@ discard block |
||
| 102 | 102 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
| 103 | 103 | |
| 104 | 104 | // Get results. |
| 105 | - $items = new WP_Query( $wp_query_args ); |
|
| 105 | + $items = new WP_Query($wp_query_args); |
|
| 106 | 106 | |
| 107 | - if ( 'objects' === $args['return'] ) { |
|
| 108 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
| 109 | - } elseif ( 'self' === $args['return'] ) { |
|
| 107 | + if ('objects' === $args['return']) { |
|
| 108 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
| 109 | + } elseif ('self' === $args['return']) { |
|
| 110 | 110 | return $items; |
| 111 | 111 | } else { |
| 112 | 112 | $return = $items->posts; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( $args['paginate' ] ) { |
|
| 115 | + if ($args['paginate']) { |
|
| 116 | 116 | return (object) array( |
| 117 | 117 | 'items' => $return, |
| 118 | 118 | 'total' => $items->found_posts, |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
| 128 | - if( empty( $item_id ) ) { |
|
| 127 | +function wpinv_is_free_item($item_id = 0) { |
|
| 128 | + if (empty($item_id)) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $item = new WPInv_Item( $item_id ); |
|
| 132 | + $item = new WPInv_Item($item_id); |
|
| 133 | 133 | |
| 134 | 134 | return $item->is_free(); |
| 135 | 135 | } |
@@ -139,21 +139,21 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
| 141 | 141 | */ |
| 142 | -function wpinv_item_is_editable( $item = 0 ) { |
|
| 142 | +function wpinv_item_is_editable($item = 0) { |
|
| 143 | 143 | |
| 144 | 144 | // Fetch the item. |
| 145 | - $item = new WPInv_Item( $item ); |
|
| 145 | + $item = new WPInv_Item($item); |
|
| 146 | 146 | |
| 147 | 147 | // Check if it is editable. |
| 148 | 148 | return $item->is_editable(); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
| 152 | - if( empty( $item_id ) ) { |
|
| 151 | +function wpinv_get_item_price($item_id = 0) { |
|
| 152 | + if (empty($item_id)) { |
|
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $item = new WPInv_Item( $item_id ); |
|
| 156 | + $item = new WPInv_Item($item_id); |
|
| 157 | 157 | |
| 158 | 158 | return $item->get_price(); |
| 159 | 159 | } |
@@ -163,96 +163,96 @@ discard block |
||
| 163 | 163 | * |
| 164 | 164 | * @param WPInv_Item|int $item |
| 165 | 165 | */ |
| 166 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
| 167 | - $item = new WPInv_Item( $item ); |
|
| 166 | +function wpinv_is_recurring_item($item = 0) { |
|
| 167 | + $item = new WPInv_Item($item); |
|
| 168 | 168 | return $item->is_recurring(); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | -function wpinv_item_price( $item_id = 0 ) { |
|
| 172 | - if( empty( $item_id ) ) { |
|
| 171 | +function wpinv_item_price($item_id = 0) { |
|
| 172 | + if (empty($item_id)) { |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $price = wpinv_get_item_price( $item_id ); |
|
| 177 | - $price = wpinv_price( $price ); |
|
| 176 | + $price = wpinv_get_item_price($item_id); |
|
| 177 | + $price = wpinv_price($price); |
|
| 178 | 178 | |
| 179 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
| 179 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
| 183 | - if ( is_null( $amount_override ) ) { |
|
| 184 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
| 182 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
| 183 | + if (is_null($amount_override)) { |
|
| 184 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
| 185 | 185 | } else { |
| 186 | 186 | $original_price = $amount_override; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $price = $original_price; |
| 190 | 190 | |
| 191 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
| 191 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
| 195 | - if( empty( $item_id ) ) { |
|
| 194 | +function wpinv_item_custom_singular_name($item_id) { |
|
| 195 | + if (empty($item_id)) { |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - $item = new WPInv_Item( $item_id ); |
|
| 199 | + $item = new WPInv_Item($item_id); |
|
| 200 | 200 | |
| 201 | 201 | return $item->get_custom_singular_name(); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | function wpinv_get_item_types() { |
| 205 | 205 | $item_types = array( |
| 206 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 207 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 206 | + 'custom' => __('Standard', 'invoicing'), |
|
| 207 | + 'fee' => __('Fee', 'invoicing'), |
|
| 208 | 208 | ); |
| 209 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
| 209 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function wpinv_item_types() { |
| 213 | 213 | $item_types = wpinv_get_item_types(); |
| 214 | 214 | |
| 215 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
| 215 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | -function wpinv_get_item_type( $item_id ) { |
|
| 219 | - if( empty( $item_id ) ) { |
|
| 218 | +function wpinv_get_item_type($item_id) { |
|
| 219 | + if (empty($item_id)) { |
|
| 220 | 220 | return false; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - $item = new WPInv_Item( $item_id ); |
|
| 223 | + $item = new WPInv_Item($item_id); |
|
| 224 | 224 | |
| 225 | 225 | return $item->get_type(); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | -function wpinv_item_type( $item_id ) { |
|
| 228 | +function wpinv_item_type($item_id) { |
|
| 229 | 229 | $item_types = wpinv_get_item_types(); |
| 230 | 230 | |
| 231 | - $item_type = wpinv_get_item_type( $item_id ); |
|
| 231 | + $item_type = wpinv_get_item_type($item_id); |
|
| 232 | 232 | |
| 233 | - if ( empty( $item_type ) ) { |
|
| 233 | + if (empty($item_type)) { |
|
| 234 | 234 | $item_type = '-'; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
| 237 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
| 238 | 238 | |
| 239 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
| 239 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | -function wpinv_get_random_item( $post_ids = true ) { |
|
| 243 | - wpinv_get_random_items( 1, $post_ids ); |
|
| 242 | +function wpinv_get_random_item($post_ids = true) { |
|
| 243 | + wpinv_get_random_items(1, $post_ids); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
| 247 | - if ( $post_ids ) { |
|
| 248 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
| 246 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
| 247 | + if ($post_ids) { |
|
| 248 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
| 249 | 249 | } else { |
| 250 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
| 250 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
| 253 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
| 254 | 254 | |
| 255 | - return get_posts( $args ); |
|
| 255 | + return get_posts($args); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -261,13 +261,13 @@ discard block |
||
| 261 | 261 | * @param WPInv_Item|int $item |
| 262 | 262 | * @param bool $html |
| 263 | 263 | */ |
| 264 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
| 264 | +function wpinv_get_item_suffix($item, $html = true) { |
|
| 265 | 265 | |
| 266 | - $item = new WPInv_Item( $item ); |
|
| 267 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
| 268 | - $suffix = $html ? $suffix : strip_tags( $suffix ); |
|
| 266 | + $item = new WPInv_Item($item); |
|
| 267 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
| 268 | + $suffix = $html ? $suffix : strip_tags($suffix); |
|
| 269 | 269 | |
| 270 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
| 270 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * @param WPInv_Item|int $item |
| 277 | 277 | * @param bool $force_delete |
| 278 | 278 | */ |
| 279 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
| 280 | - $item = new WPInv_Item( $item ); |
|
| 281 | - $item->delete( $force_delete ); |
|
| 279 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
| 280 | + $item = new WPInv_Item($item); |
|
| 281 | + $item->delete($force_delete); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -317,45 +317,45 @@ discard block |
||
| 317 | 317 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
| 318 | 318 | * @return bool|WP_Error|WPInv_Item |
| 319 | 319 | */ |
| 320 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
| 320 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
| 321 | 321 | |
| 322 | 322 | // Prepare the item. |
| 323 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
| 324 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
| 325 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
| 323 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
| 324 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
| 325 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
| 326 | 326 | |
| 327 | - if ( ! empty( $item ) ) { |
|
| 327 | + if (!empty($item)) { |
|
| 328 | 328 | $args['ID'] = $item->get_id(); |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // Do we have an item? |
| 334 | - if ( ! empty( $args['ID'] ) ) { |
|
| 335 | - $item = new WPInv_Item( $args['ID'] ); |
|
| 334 | + if (!empty($args['ID'])) { |
|
| 335 | + $item = new WPInv_Item($args['ID']); |
|
| 336 | 336 | } else { |
| 337 | 337 | $item = new WPInv_Item(); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | // Do we have an error? |
| 341 | - if ( ! empty( $item->last_error ) ) { |
|
| 342 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
| 341 | + if (!empty($item->last_error)) { |
|
| 342 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | // Update item props. |
| 346 | - $item->set_props( $args ); |
|
| 346 | + $item->set_props($args); |
|
| 347 | 347 | |
| 348 | 348 | // Save the item. |
| 349 | 349 | $item->save(); |
| 350 | 350 | |
| 351 | 351 | // Do we have an error? |
| 352 | - if ( ! empty( $item->last_error ) ) { |
|
| 353 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
| 352 | + if (!empty($item->last_error)) { |
|
| 353 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Was the item saved? |
| 357 | - if ( ! $item->get_id() ) { |
|
| 358 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
| 357 | + if (!$item->get_id()) { |
|
| 358 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | return $item; |
@@ -367,14 +367,14 @@ discard block |
||
| 367 | 367 | * |
| 368 | 368 | * @see wpinv_create_item() |
| 369 | 369 | */ |
| 370 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
| 371 | - return wpinv_create_item( $args, $wp_error ); |
|
| 370 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
| 371 | + return wpinv_create_item($args, $wp_error); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
| 375 | 375 | * Sanitizes a recurring period |
| 376 | 376 | */ |
| 377 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
| 377 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
| 378 | 378 | |
| 379 | 379 | $periods = array( |
| 380 | 380 | 'D' => 'day', |
@@ -383,11 +383,11 @@ discard block |
||
| 383 | 383 | 'Y' => 'year', |
| 384 | 384 | ); |
| 385 | 385 | |
| 386 | - if ( ! isset( $periods[ $period ] ) ) { |
|
| 386 | + if (!isset($periods[$period])) { |
|
| 387 | 387 | $period = 'D'; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - return $full ? $periods[ $period ] : $period; |
|
| 390 | + return $full ? $periods[$period] : $period; |
|
| 391 | 391 | |
| 392 | 392 | } |
| 393 | 393 | |
@@ -396,38 +396,38 @@ discard block |
||
| 396 | 396 | * |
| 397 | 397 | * @param WPInv_Item|GetPaid_Form_Item $item |
| 398 | 398 | */ |
| 399 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
| 399 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
| 400 | 400 | |
| 401 | 401 | // Abort if it is not recurring. |
| 402 | - if ( ! $item->is_recurring() ) { |
|
| 402 | + if (!$item->is_recurring()) { |
|
| 403 | 403 | return ''; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
| 407 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
| 408 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
| 406 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
| 407 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
| 408 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
| 409 | 409 | $initial_class = 'getpaid-item-initial-price'; |
| 410 | 410 | $recurring_class = 'getpaid-item-recurring-price'; |
| 411 | 411 | |
| 412 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
| 413 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
| 414 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
| 412 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
| 413 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
| 414 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
| 418 | - return __( 'Free forever', 'invoicing' ); |
|
| 417 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
| 418 | + return __('Free forever', 'invoicing'); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | // For free trial items. |
| 422 | - if ( $item->has_free_trial() ) { |
|
| 423 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
| 422 | + if ($item->has_free_trial()) { |
|
| 423 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
| 424 | 424 | |
| 425 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
| 425 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
| 426 | 426 | |
| 427 | 427 | return sprintf( |
| 428 | 428 | |
| 429 | 429 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
| 430 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
| 430 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
| 431 | 431 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 432 | 432 | "<span class='$recurring_class'>$recurring_price</span>", |
| 433 | 433 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | return sprintf( |
| 440 | 440 | |
| 441 | 441 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
| 442 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
| 442 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
| 443 | 443 | "<span class='$initial_class'>$initial_price</span>", |
| 444 | 444 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 445 | 445 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -449,12 +449,12 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - if ( $initial_price == $recurring_price ) { |
|
| 452 | + if ($initial_price == $recurring_price) { |
|
| 453 | 453 | |
| 454 | 454 | return sprintf( |
| 455 | 455 | |
| 456 | 456 | // translators: $1: is the recurring price, $2: is the susbcription period |
| 457 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 457 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
| 458 | 458 | "<span class='$recurring_class'>$recurring_price</span>", |
| 459 | 459 | "<span class='getpaid-item-recurring-period'>$period</span>" |
| 460 | 460 | |
@@ -462,12 +462,12 @@ discard block |
||
| 462 | 462 | |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
| 465 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
| 466 | 466 | |
| 467 | 467 | return sprintf( |
| 468 | 468 | |
| 469 | 469 | // translators: $1: is the recurring period, $2: is the recurring price |
| 470 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
| 470 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
| 471 | 471 | "<span class='getpaid-item-recurring-period'>$period</span>", |
| 472 | 472 | "<span class='$recurring_class'>$recurring_price</span>" |
| 473 | 473 | |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | return sprintf( |
| 479 | 479 | |
| 480 | 480 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
| 481 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
| 481 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
| 482 | 482 | "<span class='$initial_class'>$initial_price</span>", |
| 483 | 483 | "<span class='$recurring_class'>$recurring_price</span>", |
| 484 | 484 | "<span class='getpaid-item-recurring-period'>$period</span>" |