| Total Complexity | 46 |
| Total Lines | 738 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like GetPaid_Meta_Box_Item_Details often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GetPaid_Meta_Box_Item_Details, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class GetPaid_Meta_Box_Item_Details { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Output the metabox. |
||
| 21 | * |
||
| 22 | * @param WP_Post $post |
||
| 23 | */ |
||
| 24 | public static function output( $post ) { |
||
| 25 | // Prepare the item. |
||
| 26 | $item = new WPInv_Item( $post ); |
||
| 27 | |||
| 28 | // Nonce field. |
||
| 29 | wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
||
| 30 | |||
| 31 | // Variable prices. |
||
| 32 | $variable_prices = $item->get_variable_prices(); |
||
| 33 | |||
| 34 | // Set the currency position. |
||
| 35 | $position = wpinv_currency_position(); |
||
| 36 | |||
| 37 | if ( $position == 'left_space' ) { |
||
| 38 | $position = 'left'; |
||
| 39 | } |
||
| 40 | |||
| 41 | if ( $position == 'right_space' ) { |
||
| 42 | $position = 'right'; |
||
| 43 | } |
||
| 44 | |||
| 45 | ?> |
||
| 46 | <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr( $item->get_type( 'edit' ) ); ?>" /> |
||
| 47 | <style> |
||
| 48 | #poststuff .input-group-text, |
||
| 49 | #poststuff .form-control { |
||
| 50 | border-color: #7e8993; |
||
| 51 | } |
||
| 52 | |||
| 53 | .bsui label.col-sm-3.col-form-label { |
||
| 54 | font-weight: 600; |
||
| 55 | } |
||
| 56 | </style> |
||
| 57 | <div class="bsui" style="max-width: 600px;padding-top: 10px;"> |
||
| 58 | |||
| 59 | <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?> |
||
| 60 | |||
| 61 | <div class="form-group mb-3 row"> |
||
| 62 | <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php esc_html_e( 'Item Price', 'invoicing' ); ?></span></label> |
||
| 63 | <div class="col-sm-8"> |
||
| 64 | <div class="row wpinv_hide_if_variable_pricing"> |
||
| 65 | <div class="col-sm-4 getpaid-price-input mb-3"> |
||
| 66 | <div class="input-group input-group-sm"> |
||
| 67 | |||
| 68 | <?php if ( 'left' == $position ) : ?> |
||
| 69 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
| 70 | <div class="input-group-prepend"> |
||
| 71 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span> |
||
|
|
|||
| 72 | </div> |
||
| 73 | <?php else : ?> |
||
| 74 | <span class="input-group-text"> |
||
| 75 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?> |
||
| 76 | </span> |
||
| 77 | <?php endif; ?> |
||
| 78 | <?php endif; ?> |
||
| 79 | |||
| 80 | <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control wpinv-force-integer" autocomplete="off"> |
||
| 81 | |||
| 82 | <?php if ( 'left' != $position ) : ?> |
||
| 83 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
| 84 | <div class="input-group-append"> |
||
| 85 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span> |
||
| 86 | </div> |
||
| 87 | <?php else : ?> |
||
| 88 | <span class="input-group-text"> |
||
| 89 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?> |
||
| 90 | </span> |
||
| 91 | <?php endif; ?> |
||
| 92 | <?php endif; ?> |
||
| 93 | </div> |
||
| 94 | </div> |
||
| 95 | <div class="col-sm-4 wpinv_show_if_recurring"> |
||
| 96 | <?php |
||
| 97 | esc_html_e( 'Every' ); |
||
| 98 | echo ' '; |
||
| 99 | ?> |
||
| 100 | <input type="number" style="max-width: 60px;" value="<?php echo esc_attr( $item->get_recurring_interval( 'edit' ) ); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" /> |
||
| 101 | </div> |
||
| 102 | <div class="col-sm-4 wpinv_show_if_recurring"> |
||
| 103 | <?php |
||
| 104 | aui()->select( |
||
| 105 | array( |
||
| 106 | 'id' => 'wpinv_recurring_period', |
||
| 107 | 'name' => 'wpinv_recurring_period', |
||
| 108 | 'label' => __( 'Period', 'invoicing' ), |
||
| 109 | 'placeholder' => __( 'Select Period', 'invoicing' ), |
||
| 110 | 'value' => $item->get_recurring_period( 'edit' ), |
||
| 111 | 'select2' => true, |
||
| 112 | 'data-allow-clear' => 'false', |
||
| 113 | 'options' => array( |
||
| 114 | 'D' => __( 'day(s)', 'invoicing' ), |
||
| 115 | 'W' => __( 'week(s)', 'invoicing' ), |
||
| 116 | 'M' => __( 'month(s)', 'invoicing' ), |
||
| 117 | 'Y' => __( 'year(s)', 'invoicing' ), |
||
| 118 | ), |
||
| 119 | ), |
||
| 120 | true |
||
| 121 | ); |
||
| 122 | ?> |
||
| 123 | </div> |
||
| 124 | </div> |
||
| 125 | |||
| 126 | <div class="row"> |
||
| 127 | <div class="col-sm-12"> |
||
| 128 | <?php |
||
| 129 | // Variable pricing. |
||
| 130 | do_action( 'wpinv_item_details_metabox_before_variable_pricing_checkbox', $item ); |
||
| 131 | |||
| 132 | aui()->input( |
||
| 133 | array( |
||
| 134 | 'id' => 'wpinv_variable_pricing', |
||
| 135 | 'name' => 'wpinv_variable_pricing', |
||
| 136 | 'type' => 'checkbox', |
||
| 137 | 'label' => apply_filters( 'wpinv_variable_pricing_toggle_text', __( 'Enable variable pricing', 'invoicing' ) ), |
||
| 138 | 'value' => '1', |
||
| 139 | 'checked' => $item->has_variable_pricing(), |
||
| 140 | 'no_wrap' => true, |
||
| 141 | ), |
||
| 142 | true |
||
| 143 | ); |
||
| 144 | |||
| 145 | do_action( 'wpinv_item_details_metabox_variable_pricing_checkbox', $item ); |
||
| 146 | ?> |
||
| 147 | </div> |
||
| 148 | </div> |
||
| 149 | |||
| 150 | <div class="row wpinv_hide_if_variable_pricing"> |
||
| 151 | <div class="col-sm-12"> |
||
| 152 | <?php |
||
| 153 | |||
| 154 | // Dynamic pricing. |
||
| 155 | if ( $item->supports_dynamic_pricing() ) { |
||
| 156 | |||
| 157 | do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item ); |
||
| 158 | |||
| 159 | // NYP toggle. |
||
| 160 | aui()->input( |
||
| 161 | array( |
||
| 162 | 'id' => 'wpinv_name_your_price', |
||
| 163 | 'name' => 'wpinv_name_your_price', |
||
| 164 | 'type' => 'checkbox', |
||
| 165 | 'label' => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ), |
||
| 166 | 'value' => '1', |
||
| 167 | 'checked' => $item->user_can_set_their_price(), |
||
| 168 | 'no_wrap' => true, |
||
| 169 | ), |
||
| 170 | true |
||
| 171 | ); |
||
| 172 | |||
| 173 | do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item ); |
||
| 174 | } |
||
| 175 | |||
| 176 | // Subscriptions. |
||
| 177 | do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item ); |
||
| 178 | |||
| 179 | aui()->input( |
||
| 180 | array( |
||
| 181 | 'id' => 'wpinv_is_recurring', |
||
| 182 | 'name' => 'wpinv_is_recurring', |
||
| 183 | 'type' => 'checkbox', |
||
| 184 | 'label' => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ), |
||
| 185 | 'value' => '1', |
||
| 186 | 'checked' => $item->is_recurring(), |
||
| 187 | 'no_wrap' => true, |
||
| 188 | ), |
||
| 189 | true |
||
| 190 | ); |
||
| 191 | do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item ); |
||
| 192 | |||
| 193 | ?> |
||
| 194 | <div class="wpinv_show_if_recurring"> |
||
| 195 | <em><?php echo wp_kses_post( wpinv_get_recurring_gateways_text() ); ?></em> |
||
| 196 | </div> |
||
| 197 | </div> |
||
| 198 | </div> |
||
| 199 | </div> |
||
| 200 | <div class="col-sm-1 pt-2 pl-0 wpinv_hide_if_variable_pricing"> |
||
| 201 | <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e( 'Set the subscription price, billing interval and period.', 'invoicing' ); ?>"></span> |
||
| 202 | </div> |
||
| 203 | </div> |
||
| 204 | |||
| 205 | <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?> |
||
| 206 | |||
| 207 | <?php if ( $item->supports_dynamic_pricing() ) : ?> |
||
| 208 | <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?> |
||
| 209 | <div class="wpinv_show_if_dynamic wpinv_minimum_price wpinv_hide_if_variable_pricing"> |
||
| 210 | |||
| 211 | <div class="form-group mb-3 row"> |
||
| 212 | <label for="wpinv_minimum_price" class="col-sm-3 col-form-label"> |
||
| 213 | <?php esc_html_e( 'Minimum Price', 'invoicing' ); ?> |
||
| 214 | </label> |
||
| 215 | <div class="col-sm-8"> |
||
| 216 | <div class="input-group input-group-sm"> |
||
| 217 | <?php if ( 'left' == $position ) : ?> |
||
| 218 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
| 219 | <div class="input-group-prepend"> |
||
| 220 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span> |
||
| 221 | </div> |
||
| 222 | <?php else : ?> |
||
| 223 | <span class="input-group-text"> |
||
| 224 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?> |
||
| 225 | </span> |
||
| 226 | <?php endif; ?> |
||
| 227 | <?php endif; ?> |
||
| 228 | |||
| 229 | <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control wpinv-force-integer"> |
||
| 230 | |||
| 231 | <?php if ( 'left' != $position ) : ?> |
||
| 232 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
| 233 | <div class="input-group-append"> |
||
| 234 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span> |
||
| 235 | </div> |
||
| 236 | <?php else : ?> |
||
| 237 | <span class="input-group-text"> |
||
| 238 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?> |
||
| 239 | </span> |
||
| 240 | <?php endif; ?> |
||
| 241 | <?php endif; ?> |
||
| 242 | </div> |
||
| 243 | </div> |
||
| 244 | |||
| 245 | <div class="col-sm-1 pt-2 pl-0"> |
||
| 246 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the minimum amount that users are allowed to set', 'invoicing' ); ?>"></span> |
||
| 247 | </div> |
||
| 248 | </div> |
||
| 249 | |||
| 250 | </div> |
||
| 251 | <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?> |
||
| 252 | <?php endif; ?> |
||
| 253 | |||
| 254 | <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?> |
||
| 255 | <div class="wpinv_show_if_recurring wpinv_hide_if_variable_pricing wpinv_maximum_renewals"> |
||
| 256 | |||
| 257 | <div class="form-group mb-3 row"> |
||
| 258 | <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label"> |
||
| 259 | <?php esc_html_e( 'Maximum Renewals', 'invoicing' ); ?> |
||
| 260 | </label> |
||
| 261 | <div class="col-sm-8"> |
||
| 262 | <input type="number" value="<?php echo esc_attr( $item->get_recurring_limit( 'edit' ) ); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" /> |
||
| 263 | </div> |
||
| 264 | <div class="col-sm-1 pt-2 pl-0"> |
||
| 265 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing' ); ?>"></span> |
||
| 266 | </div> |
||
| 267 | </div> |
||
| 268 | |||
| 269 | </div> |
||
| 270 | <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?> |
||
| 271 | |||
| 272 | <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?> |
||
| 273 | <div class="wpinv_show_if_recurring wpinv_hide_if_variable_pricing wpinv_free_trial"> |
||
| 274 | |||
| 275 | <div class="form-group mb-3 row"> |
||
| 276 | <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php defined( 'GETPAID_PAID_TRIALS_VERSION' ) ? esc_html_e( 'Free/Paid Trial', 'invoicing' ) : esc_html_e( 'Free Trial', 'invoicing' ); ?></label> |
||
| 277 | |||
| 278 | <div class="col-sm-8"> |
||
| 279 | <div class="row"> |
||
| 280 | <div class="col-sm-6"> |
||
| 281 | <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0; ?> |
||
| 282 | |||
| 283 | <div> |
||
| 284 | <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>"> |
||
| 285 | </div> |
||
| 286 | </div> |
||
| 287 | <div class="col-sm-6"> |
||
| 288 | <?php |
||
| 289 | aui()->select( |
||
| 290 | array( |
||
| 291 | 'id' => 'wpinv_trial_period', |
||
| 292 | 'name' => 'wpinv_trial_period', |
||
| 293 | 'label' => __( 'Trial Period', 'invoicing' ), |
||
| 294 | 'placeholder' => __( 'Trial Period', 'invoicing' ), |
||
| 295 | 'value' => $item->get_trial_period( 'edit' ), |
||
| 296 | 'select2' => true, |
||
| 297 | 'data-allow-clear' => 'false', |
||
| 298 | 'no_wrap' => true, |
||
| 299 | 'options' => array( |
||
| 300 | 'D' => __( 'day(s)', 'invoicing' ), |
||
| 301 | 'W' => __( 'week(s)', 'invoicing' ), |
||
| 302 | 'M' => __( 'month(s)', 'invoicing' ), |
||
| 303 | 'Y' => __( 'year(s)', 'invoicing' ), |
||
| 304 | ), |
||
| 305 | ), |
||
| 306 | true |
||
| 307 | ); |
||
| 308 | ?> |
||
| 309 | |||
| 310 | </div> |
||
| 311 | </div> |
||
| 312 | </div> |
||
| 313 | |||
| 314 | <div class="col-sm-1 pt-2 pl-0"> |
||
| 315 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'An optional period of time to wait before charging the first recurring payment.', 'invoicing' ); ?>"></span> |
||
| 316 | </div> |
||
| 317 | |||
| 318 | </div> |
||
| 319 | |||
| 320 | </div> |
||
| 321 | <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?> |
||
| 322 | </div> |
||
| 323 | |||
| 324 | <div class="bsui"> |
||
| 325 | <?php do_action( 'wpinv_item_details_metabox_before_variable_pricing', $item ); ?> |
||
| 326 | |||
| 327 | <div class="wpinv_show_if_variable_pricing wpinv_variable_pricing"> |
||
| 328 | |||
| 329 | <div id="wpinv_price_fields" class="wpinv_meta_table_wrap mb-3"> |
||
| 330 | <div class="widefat getpaid_repeatable_table"> |
||
| 331 | |||
| 332 | <div class="wpinv-price-option-fields getpaid-repeatables-wrap"> |
||
| 333 | <?php |
||
| 334 | if ( ! empty( $variable_prices ) ) : |
||
| 335 | |||
| 336 | foreach ( $variable_prices as $key => $value ) : |
||
| 337 | $name = (isset( $value['name'] ) && ! empty( $value['name'] )) ? $value['name'] : ''; |
||
| 338 | $index = (isset( $value['index'] ) && $value['index'] !== '') ? $value['index'] : $key; |
||
| 339 | $amount = isset( $value['amount'] ) ? $value['amount'] : ''; |
||
| 340 | |||
| 341 | $args = apply_filters( 'wpinv_price_row_args', compact( 'name', 'amount' ), $value ); |
||
| 342 | $args = wp_parse_args( $args, $value ); |
||
| 343 | ?> |
||
| 344 | <div class="wpinv_variable_prices_wrapper getpaid_repeatable_row" data-key="<?php echo esc_attr( $key ); ?>"> |
||
| 345 | <?php self::render_price_row( $key, $args, $item, $index ); ?> |
||
| 346 | </div> |
||
| 347 | <?php |
||
| 348 | endforeach; |
||
| 349 | else : |
||
| 350 | ?> |
||
| 351 | <div class="wpinv_variable_prices_wrapper getpaid_repeatable_row" data-key="1"> |
||
| 352 | <?php self::render_price_row( 1, array(), $item, 1 ); ?> |
||
| 353 | </div> |
||
| 354 | <?php endif; ?> |
||
| 355 | |||
| 356 | <div class="wpinv-add-repeatable-row"> |
||
| 357 | <div class="float-none pt-2 clear"> |
||
| 358 | <button type="button" class="button-secondary getpaid-add-variable-price-row"><?php _e( 'Add New Price', 'invoicing' ); ?></button> |
||
| 359 | </div> |
||
| 360 | </div> |
||
| 361 | </div> |
||
| 362 | </div> |
||
| 363 | </div> |
||
| 364 | </div> |
||
| 365 | <?php do_action( 'wpinv_item_details_metabox_variable_pricing', $item ); ?> |
||
| 366 | </div> |
||
| 367 | |||
| 368 | <div class="bsui" style="max-width: 600px;"> |
||
| 369 | <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?> |
||
| 370 | </div> |
||
| 371 | |||
| 372 | <script type="text/html" id="tmpl-getpaid-variable-price-row"> |
||
| 373 | <div class="wpinv_variable_prices_wrapper getpaid_repeatable_row" data-key="1"> |
||
| 374 | <?php self::render_price_row( 1, array(), $item, 1 ); ?> |
||
| 375 | </div> |
||
| 376 | </script> |
||
| 377 | |||
| 378 | <script type="text/javascript"> |
||
| 379 | jQuery(function($) { |
||
| 380 | |||
| 381 | // Inserts a new row |
||
| 382 | $('.getpaid-add-variable-price-row').on('click', function(e) { |
||
| 383 | e.preventDefault(); |
||
| 384 | const html = $('#tmpl-getpaid-variable-price-row').html(); |
||
| 385 | const price_row = $(html); |
||
| 386 | const last_price_row = $(this).parents('.wpinv-price-option-fields').find('.wpinv_variable_prices_wrapper').last(); |
||
| 387 | |||
| 388 | // Retrieve the highest current key |
||
| 389 | var key = highest = 1; |
||
| 390 | $(this).parents('.wpinv-price-option-fields').find('.getpaid_repeatable_row').each(function() { |
||
| 391 | var current = $(this).data('key'); |
||
| 392 | if (parseInt(current) > highest) { |
||
| 393 | highest = current; |
||
| 394 | } |
||
| 395 | }); |
||
| 396 | key = highest += 1; |
||
| 397 | |||
| 398 | price_row.attr('data-key', key); |
||
| 399 | |||
| 400 | price_row.find('input, select, textarea').each(function() { |
||
| 401 | var name = $(this).attr('name'); |
||
| 402 | var id = $(this).attr('id'); |
||
| 403 | if (name) { |
||
| 404 | name = name.replace(/\[(\d+)\]/, '[' + parseInt(key) + ']'); |
||
| 405 | $(this).attr('name', name); |
||
| 406 | } |
||
| 407 | |||
| 408 | $(this).attr('data-key', key); |
||
| 409 | if (typeof id != 'undefined') { |
||
| 410 | id = id.replace(/(\d+)/, parseInt(key)); |
||
| 411 | $(this).attr('id', id); |
||
| 412 | } |
||
| 413 | }); |
||
| 414 | |||
| 415 | price_row.find('span.getpaid_price_id').each(function() { |
||
| 416 | $(this).text(parseInt(key)); |
||
| 417 | }); |
||
| 418 | |||
| 419 | price_row.find('.getpaid_repeatable_default_input').each(function() { |
||
| 420 | $(this).val(parseInt(key)).removeAttr('checked'); |
||
| 421 | }); |
||
| 422 | |||
| 423 | $(price_row).insertAfter(last_price_row) |
||
| 424 | }); |
||
| 425 | |||
| 426 | // Remove a row. |
||
| 427 | $(document).on('click', '.getpaid-remove-price-option-row', function(e) { |
||
| 428 | e.preventDefault(); |
||
| 429 | |||
| 430 | var row = $(this).parents('.getpaid_repeatable_row'), |
||
| 431 | count = row.parent().find('.getpaid_repeatable_row').length, |
||
| 432 | price_id = parseInt(row.data("key")); |
||
| 433 | |||
| 434 | $('.getpaid_repeatable_condition_field option[value="' + price_id + '"]').remove() |
||
| 435 | |||
| 436 | if (count > 1) { |
||
| 437 | $('input, select', row).val(''); |
||
| 438 | row.fadeOut('fast').remove(); |
||
| 439 | } |
||
| 440 | }); |
||
| 441 | |||
| 442 | $(".getpaid_repeatable_table .getpaid-repeatables-wrap").sortable({ |
||
| 443 | handle: '.getpaid-draghandle-cursor', |
||
| 444 | items: '.getpaid_repeatable_row', |
||
| 445 | opacity: 0.6, |
||
| 446 | cursor: 'move', |
||
| 447 | axis: 'y', |
||
| 448 | update: function() { |
||
| 449 | var count = 0; |
||
| 450 | $(this).find('.getpaid_repeatable_row').each(function() { |
||
| 451 | $(this).find('input.getpaid_repeatable_index').each(function() { |
||
| 452 | $(this).val(count); |
||
| 453 | }); |
||
| 454 | count++; |
||
| 455 | }); |
||
| 456 | } |
||
| 457 | }); |
||
| 458 | }); |
||
| 459 | </script> |
||
| 460 | <?php |
||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Render a price row with advanced settings for a WPINV Item. |
||
| 465 | * |
||
| 466 | * This function generates HTML markup for displaying a price row with advanced settings, |
||
| 467 | * including recurring payment options. |
||
| 468 | * |
||
| 469 | * @since 2.8.9 |
||
| 470 | * |
||
| 471 | * @param string $key The unique identifier for the price row. |
||
| 472 | * @param array $args Optional. Array of arguments for customizing the price row. Default empty array. |
||
| 473 | * @param WP_Post $item WPINV Itemm object. |
||
| 474 | * @param int $index The index of the price row. |
||
| 475 | */ |
||
| 476 | public static function render_price_row( $key, $args = array(), $item, $index ) { |
||
| 477 | $defaults = array( |
||
| 478 | 'name' => null, |
||
| 479 | 'amount' => null, |
||
| 480 | 'is-recurring' => 'no', |
||
| 481 | 'trial-interval' => 0, |
||
| 482 | 'trial-period' => null, |
||
| 483 | 'recurring-interval' => 1, |
||
| 484 | 'recurring-period' => null, |
||
| 485 | 'recurring-limit' => 0, |
||
| 486 | ); |
||
| 487 | |||
| 488 | $args = wp_parse_args( $args, $defaults ); |
||
| 489 | |||
| 490 | $default_price_id = $item->get_default_price_id(); |
||
| 491 | $is_recurring = ('yes' === $args['is-recurring']) ? true : false; |
||
| 492 | $position = wpinv_currency_position(); |
||
| 493 | |||
| 494 | $extra_attributes = array( |
||
| 495 | 'min' => 0, |
||
| 496 | 'step' => 1, |
||
| 497 | 'size' => 1, |
||
| 498 | 'style' => 'width: 70px', |
||
| 499 | ); |
||
| 500 | |||
| 501 | if ( ! $is_recurring ) { |
||
| 502 | $extra_attributes['disabled'] = true; |
||
| 503 | } |
||
| 504 | ?> |
||
| 505 | <div class="getpaid-repeatable-row-header getpaid-draghandle-cursor"> |
||
| 506 | |||
| 507 | <span class="getpaid-repeatable-row-title" title="<?php _e( 'Click and drag to re-order price options', 'invoicing' ); ?>"> |
||
| 508 | <?php printf( __( 'Price ID: %s', 'invoicing' ), '<span class="getpaid_price_id">' . $key . '</span>' ); ?> |
||
| 509 | <input type="hidden" name="wpinv_variable_prices[<?php echo $key; ?>][index]" class="getpaid_repeatable_index" value="<?php echo $index; ?>"/> |
||
| 510 | </span> |
||
| 511 | |||
| 512 | <span class="getpaid-repeatable-row-actions"> |
||
| 513 | <a href="#" class="wpinv-toggle-custom-price-option-settings" data-show="<?php _e( 'Show advanced settings', 'invoicing' ); ?>" data-hide="<?php _e( 'Hide advanced settings', 'invoicing' ); ?>"><?php _e( 'Show advanced settings', 'invoicing' ); ?></a> |
||
| 514 | | |
||
| 515 | <a class="getpaid-remove-price-option-row text-danger"> |
||
| 516 | <?php _e( 'Remove', 'invoicing' ); ?> <span class="screen-reader-text"><?php printf( __( 'Remove price option %s', 'invoicing' ), esc_attr( $key ) ); ?></span> |
||
| 517 | </a> |
||
| 518 | </span> |
||
| 519 | </div> |
||
| 520 | |||
| 521 | <div class="getpaid-repeatable-row-standard-fields"> |
||
| 522 | |||
| 523 | <div class="getpaid-option-name"> |
||
| 524 | <label class="form-label"><?php _e( 'Option Name', 'invoicing' ); ?></label> |
||
| 525 | <?php |
||
| 526 | aui()->input( |
||
| 527 | array( |
||
| 528 | 'name' => 'wpinv_variable_prices[' . $key . '][name]', |
||
| 529 | 'placeholder' => __( 'Option Name', 'invoicing' ), |
||
| 530 | 'value' => esc_attr( $args['name'] ), |
||
| 531 | 'class' => 'wpinv_variable_price_name form-control-sm', |
||
| 532 | 'no_wrap' => true, |
||
| 533 | ), |
||
| 534 | true |
||
| 535 | ); |
||
| 536 | ?> |
||
| 537 | </div> |
||
| 538 | |||
| 539 | <div class="getpaid-option-price"> |
||
| 540 | <label class="form-label"><?php _e( 'Price', 'invoicing' ); ?></label> |
||
| 541 | <div class="input-group input-group-sm"> |
||
| 542 | <?php if ( 'left' == $position ) : ?> |
||
| 543 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
| 544 | <div class="input-group-prepend"> |
||
| 545 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span> |
||
| 546 | </div> |
||
| 547 | <?php else : ?> |
||
| 548 | <span class="input-group-text"> |
||
| 549 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?> |
||
| 550 | </span> |
||
| 551 | <?php endif; ?> |
||
| 552 | <?php endif; ?> |
||
| 553 | |||
| 554 | <input type="text" name="wpinv_variable_prices[<?php echo $key; ?>][amount]" id="wpinv_variable_prices[<?php echo $key; ?>][amount]" value="<?php echo esc_attr( getpaid_unstandardize_amount( $args['amount'] ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 9.99 ) ); ?>" class="form-control form-control-sm wpinv-force-integer getpaid-price-field" autocomplete="off"> |
||
| 555 | |||
| 556 | <?php if ( 'left' != $position ) : ?> |
||
| 557 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
| 558 | <div class="input-group-append"> |
||
| 559 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span> |
||
| 560 | </div> |
||
| 561 | <?php else : ?> |
||
| 562 | <span class="input-group-text"> |
||
| 563 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?> |
||
| 564 | </span> |
||
| 565 | <?php endif; ?> |
||
| 566 | <?php endif; ?> |
||
| 567 | </div> |
||
| 568 | </div> |
||
| 569 | |||
| 570 | <div class="getpaid_repeatable_default getpaid_repeatable_default_wrapper"> |
||
| 571 | <label class="form-label d-block"><?php _e( 'Default', 'invoicing' ); ?></label> |
||
| 572 | <label class="getpaid-default-price"> |
||
| 573 | <input type="radio" <?php checked( $default_price_id, $key, true ); ?> class="getpaid_repeatable_default_input" name="_wpinv_default_price_id" value="<?php echo $key; ?>" /> |
||
| 574 | <span class="screen-reader-text"><?php printf( __( 'Set ID %s as default price', 'invoicing' ), $key ); ?></span> |
||
| 575 | </label> |
||
| 576 | </div> |
||
| 577 | |||
| 578 | </div> |
||
| 579 | |||
| 580 | <div class="wpinv-custom-price-option-settings-wrap"> |
||
| 581 | <div class="wpinv-custom-price-option-settings"> |
||
| 582 | <div class="wpinv-custom-price-option-setting"> |
||
| 583 | |||
| 584 | <div class="wpinv-custom-price-option-setting-title"><?php _e( 'Recurring Payments Settings', 'invoicing' ); ?></div> |
||
| 585 | |||
| 586 | <div class="wpinv-recurring-enabled"> |
||
| 587 | <label class="form-label"><?php _e( 'Recurring', 'invoicing' ); ?></label> |
||
| 588 | <?php |
||
| 589 | aui()->select( |
||
| 590 | array( |
||
| 591 | 'name' => 'wpinv_variable_prices[' . $key . '][is-recurring]', |
||
| 592 | 'value' => esc_attr( $args['is-recurring'] ), |
||
| 593 | 'class' => 'custom-select-sm', |
||
| 594 | 'no_wrap' => true, |
||
| 595 | 'options' => array( |
||
| 596 | 'no' => __( 'No', 'invoicing' ), |
||
| 597 | 'yes' => __( 'Yes', 'invoicing' ), |
||
| 598 | ), |
||
| 599 | ), |
||
| 600 | true |
||
| 601 | ); |
||
| 602 | ?> |
||
| 603 | </div> |
||
| 604 | |||
| 605 | <div class="wpinv-recurring-free-trial"> |
||
| 606 | <label class="form-label"><?php _e( 'Free Trial', 'invoicing' ); ?></label> |
||
| 607 | <?php |
||
| 608 | aui()->input( |
||
| 609 | array( |
||
| 610 | 'type' => 'number', |
||
| 611 | 'id' => 'wpinv_variable_prices[' . $key . '][trial-interval]', |
||
| 612 | 'name' => 'wpinv_variable_prices[' . $key . '][trial-interval]', |
||
| 613 | 'value' => absint( $args['trial-interval'] ), |
||
| 614 | 'class' => 'form-control-sm d-inline-block', |
||
| 615 | 'no_wrap' => true, |
||
| 616 | 'extra_attributes' => $extra_attributes, |
||
| 617 | ), |
||
| 618 | true |
||
| 619 | ); |
||
| 620 | ?> |
||
| 621 | |||
| 622 | <?php |
||
| 623 | aui()->select( |
||
| 624 | array( |
||
| 625 | 'id' => 'wpinv_variable_prices[' . $key . '][trial-period]', |
||
| 626 | 'name' => 'wpinv_variable_prices[' . $key . '][trial-period]', |
||
| 627 | 'value' => esc_attr( $args['trial-period'] ), |
||
| 628 | 'class' => 'custom-select-sm w-auto d-inline-block', |
||
| 629 | 'no_wrap' => true, |
||
| 630 | 'extra_attributes' => ( ! $is_recurring ? array( 'disabled' => true ) : array()), |
||
| 631 | 'options' => array( |
||
| 632 | 'D' => __( 'Day(s)', 'invoicing' ), |
||
| 633 | 'W' => __( 'Week(s)', 'invoicing' ), |
||
| 634 | 'M' => __( 'Month(s)', 'invoicing' ), |
||
| 635 | 'Y' => __( 'Year(s)', 'invoicing' ), |
||
| 636 | ), |
||
| 637 | ), |
||
| 638 | true |
||
| 639 | ); |
||
| 640 | ?> |
||
| 641 | </div> |
||
| 642 | |||
| 643 | <div class="wpinv-recurring-interval"> |
||
| 644 | <label class="form-label"><?php _e( 'Every', 'invoicing' ); ?></label> |
||
| 645 | <?php |
||
| 646 | aui()->input( |
||
| 647 | array( |
||
| 648 | 'type' => 'number', |
||
| 649 | 'id' => 'wpinv_variable_prices[' . $key . '][recurring-interval]', |
||
| 650 | 'name' => 'wpinv_variable_prices[' . $key . '][recurring-interval]', |
||
| 651 | 'value' => absint( $args['recurring-interval'] ), |
||
| 652 | 'class' => 'form-control-sm', |
||
| 653 | 'no_wrap' => true, |
||
| 654 | 'extra_attributes' => $extra_attributes, |
||
| 655 | ), |
||
| 656 | true |
||
| 657 | ); |
||
| 658 | ?> |
||
| 659 | </div> |
||
| 660 | |||
| 661 | <div class="wpinv-recurring-period"> |
||
| 662 | <label class="form-label"><?php _e( 'Period', 'invoicing' ); ?></label> |
||
| 663 | <?php |
||
| 664 | aui()->select( |
||
| 665 | array( |
||
| 666 | 'id' => 'wpinv_variable_prices[' . $key . '][recurring-period]', |
||
| 667 | 'name' => 'wpinv_variable_prices[' . $key . '][recurring-period]', |
||
| 668 | 'value' => esc_attr( $args['recurring-period'] ), |
||
| 669 | 'class' => 'custom-select-sm', |
||
| 670 | 'extra_attributes' => ( ! $is_recurring ? array( 'disabled' => true ) : array()), |
||
| 671 | 'no_wrap' => true, |
||
| 672 | 'options' => array( |
||
| 673 | 'D' => __( 'Day(s)', 'invoicing' ), |
||
| 674 | 'W' => __( 'Week(s)', 'invoicing' ), |
||
| 675 | 'M' => __( 'Month(s)', 'invoicing' ), |
||
| 676 | 'Y' => __( 'Year(s)', 'invoicing' ), |
||
| 677 | ), |
||
| 678 | ), |
||
| 679 | true |
||
| 680 | ); |
||
| 681 | ?> |
||
| 682 | </div> |
||
| 683 | |||
| 684 | <div class="wpinv-recurring-limit"> |
||
| 685 | <label class="form-label"><?php _e( 'Maximum Renewals', 'invoicing' ); ?></label> |
||
| 686 | <?php |
||
| 687 | aui()->input( |
||
| 688 | array( |
||
| 689 | 'type' => 'number', |
||
| 690 | 'id' => 'wpinv_variable_prices[' . $key . '][recurring-limit]', |
||
| 691 | 'name' => 'wpinv_variable_prices[' . $key . '][recurring-limit]', |
||
| 692 | 'value' => esc_attr( $args['recurring-limit'] ), |
||
| 693 | 'class' => 'form-control-sm', |
||
| 694 | 'no_wrap' => true, |
||
| 695 | 'extra_attributes' => array_merge( |
||
| 696 | $extra_attributes, |
||
| 697 | array( 'size' => 4 ) |
||
| 698 | ), |
||
| 699 | ), |
||
| 700 | true |
||
| 701 | ); |
||
| 702 | ?> |
||
| 703 | </div> |
||
| 704 | </div> |
||
| 705 | |||
| 706 | <?php do_action( 'wpinv_download_price_option_row', $item->ID, $key, $args ); ?> |
||
| 707 | </div> |
||
| 708 | </div> |
||
| 709 | <?php |
||
| 710 | } |
||
| 711 | |||
| 712 | /** |
||
| 713 | * Save meta box data. |
||
| 714 | * |
||
| 715 | * @param int $post_id |
||
| 716 | */ |
||
| 717 | public static function save( $post_id ) { |
||
| 755 | } |
||
| 756 | } |
||
| 757 |