/** * Retrieve an add-ons price range. * * @since 1.4 * @param int $addon_id ID of the addon. * @return arr Array of low and high prices. */ function mdjm_get_addon_price_range($addon_id) { if (!mdjm_addon_has_variable_prices($addon_id)) { return; } $range = array(); $prices = mdjm_get_addon_variable_prices($addon_id); foreach ($prices as $price) { if (empty($range['low']) || $price['amount'] < $range['low']) { $range['low'] = $price['amount']; } if (empty($range['high']) || $price['amount'] > $range['high']) { $range['high'] = $price['amount']; } } return apply_filters('mdjm_addon_price_range', $range, $addon_id); }
/** * Output the addon availability pricing options row * * @since 1.4 * @param int $post The WP_Post object. * @return str */ function mdjm_addon_metabox_pricing_options_row($post) { $month = 1; $price = mdjm_get_addon_price($post->ID); $variable = mdjm_addon_has_variable_prices($post->ID); $prices = mdjm_get_addon_variable_prices($post->ID); $variable_display = $variable ? '' : ' style="display:none;"'; $currency_position = mdjm_get_option('currency_format', 'before'); ?> <div class="mdjm_field_wrap mdjm_form_fields"> <div id="mdjm-addon-regular-price-field" class="mdjm_pricing_fields"> <?php $price_args = array('name' => '_addon_price', 'value' => isset($price) ? esc_attr(mdjm_format_amount($price)) : '', 'class' => 'mdjm-currency', 'placeholder' => mdjm_format_amount('10.00'), 'desc' => __('Will be used if variable pricing is not in use, or for months that are not defined within variable pricing', 'mobile-dj-manager')); ?> <p><label for="<?php echo $price_args['name']; ?> "><?php _e('Standard Price', 'mobile-dj-manager'); ?> </label><br /> <?php if ($currency_position == 'before') { ?> <?php echo mdjm_currency_filter(''); ?> <?php echo MDJM()->html->text($price_args); ?> <?php } else { ?> <?php echo MDJM()->html->text($price_args); ?> <?php echo mdjm_currency_filter(''); ?> <?php } ?> </p> <?php do_action('mdjm_addon_price_field', $post->ID); ?> </div> <?php do_action('mdjm_after_addon_price_field', $post->ID); ?> <div id="addon-variable-price"> <p><?php echo MDJM()->html->checkbox(array('name' => '_addon_variable_pricing', 'current' => $variable)); ?> <label for="_addon_variable_pricing"><?php _e('Enable variable pricing', 'mobile-dj-manager'); ?> </label></p> </div> <?php do_action('mdjm_after_addon_variable_pricing_field', $post->ID); ?> </div> <div id="mdjm-addon-variable-price-fields" class="mdjm_pricing_fields" <?php echo $variable_display; ?> > <input type="hidden" id="mdjm_variable_prices" class="mdjm_variable_prices_name_field" value=""/> <div id="mdjm_price_fields" class="mdjm_meta_table_wrap"> <table class="widefat mdjm_repeatable_table"> <thead> <tr> <th style="width: 50px;"><?php _e('Month', 'mobile-dj-manager'); ?> </th> <th style="width: 100px;"><?php _e('Price', 'mobile-dj-manager'); ?> </th> <?php do_action('mdjm_addon_price_table_head', $post->ID); ?> <th style="width: 2%"></th> </tr> </thead> <tbody> <?php if (!empty($prices)) { foreach ($prices as $key => $value) { $months = isset($value['months']) ? $value['months'] : ''; $amount = isset($value['amount']) ? $value['amount'] : ''; $index = isset($value['index']) ? $value['index'] : $key; $args = apply_filters('mdjm_price_row_args', compact('months', 'amount'), $value); ?> <tr class="mdjm_variable_prices_wrapper mdjm_repeatable_row" data-key="<?php echo esc_attr($key); ?> "> <?php do_action('mdjm_render_addon_price_row', $key, $args, $post->ID, $index); ?> </tr> <?php } } else { ?> <tr class="mdjm_variable_prices_wrapper mdjm_repeatable_row" data-key="1"> <?php do_action('mdjm_render_addon_price_row', 1, array(), $post->ID, 1); ?> </tr> <?php } ?> <tr> <td class="submit" colspan="3" style="float: none; clear:both; background:#fff;"> <a class="button-secondary mdjm_add_repeatable" style="margin: 6px 0;"><?php _e('Add New Price', 'mobile-dj-manager'); ?> </a> </td> </tr> </tbody> </table> </div> </div> <?php }