/** * Define the data to be displayed in each of the custom columns for the Package post types * * @since 1.4 * @param str $column_name The name of the column to display * @param int $post_id The current post ID * @return */ function mdjm_package_posts_custom_column($column_name, $post_id) { global $post; switch ($column_name) { // Items case 'items': $items = mdjm_get_package_addons($post_id); if ($items) { $i = 0; foreach ($items as $item) { echo '<a href="' . admin_url("post.php?post={$item}&action=edit") . '">' . mdjm_get_addon_name($item) . '</a>'; $i++; if ($i < count($items)) { echo '<br />'; } } } break; // Category // Category case 'package_category': echo get_the_term_list($post_id, 'package-category', '', ', ', ''); break; // Availability // Availability case 'availability': $output = array(); if (!mdjm_package_is_restricted_by_date($post_id)) { $output[] = __('Always', 'mobile-dj-manager'); } else { $availability = mdjm_get_package_months_available($post_id); if (!$availability) { $output[] = __('Always', 'mobile-dj-manager'); } else { $i = 0; foreach ($availability as $month) { $output[] = mdjm_month_num_to_name($availability[$i]); $i++; } } } echo implode(', ', $output); break; // Event Types // Event Types case 'event_types': $output = array(); $event_label = mdjm_get_label_singular(); $event_types = mdjm_get_package_event_types($post_id); if (in_array('all', $event_types)) { $output[] = sprintf(__('All %s Types', 'mobile-dj-manager'), $event_label); } else { foreach ($event_types as $event_type) { $term = get_term($event_type, 'event-types'); if (!empty($term)) { $output[] = $term->name; } } } echo implode(', ', $output); break; // Employees // Employees case 'employees': $employees = mdjm_get_employees_with_package($post_id); $output = array(); if (in_array('all', $employees)) { $output[] .= __('All Employees', 'mobile-dj-manager'); } else { foreach ($employees as $employee) { if ('all' == $employee) { continue; } $output[] = '<a href="' . get_edit_user_link($employee) . '">' . mdjm_get_employee_display_name($employee) . '</a>'; } } echo implode('<br />', $output); break; // Price // Price case 'price': if (mdjm_package_has_variable_prices($post_id)) { $range = mdjm_get_package_price_range($post_id); echo mdjm_currency_filter(mdjm_format_amount($range['low'])); echo ' — '; echo mdjm_currency_filter(mdjm_format_amount($range['high'])); } else { echo mdjm_currency_filter(mdjm_format_amount(mdjm_get_package_price($post_id))); } break; case 'usage': $count = mdjm_count_events_with_package($post_id); echo $count . ' ' . _n(mdjm_get_label_singular(), mdjm_get_label_plural(), $count, 'mobile-dj-manager'); break; } // switch }
/** * Retrieve a packages price range. * * @since 1.4 * @param int $package_id ID of the package. * @return arr Array of low and high prices. */ function mdjm_get_package_price_range($package_id) { if (!mdjm_package_has_variable_prices($package_id)) { return; } $range = array(); $prices = mdjm_get_package_variable_prices($package_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_package_price_range', $range, $package_id); }
/** * Output the package availability pricing options row * * @since 1.4 * @param int $post The WP_Post object. * @return str */ function mdjm_package_metabox_pricing_options_row($post) { $month = 1; $price = mdjm_get_package_price($post->ID); $variable = mdjm_package_has_variable_prices($post->ID); $prices = mdjm_get_package_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-package-regular-price-field" class="mdjm_pricing_fields"> <?php $price_args = array('name' => '_package_price', 'value' => isset($price) ? esc_attr(mdjm_format_amount($price)) : '', 'class' => 'mdjm-currency', 'desc' => __('Will be used if variable pricing is not in use, or for months that are not defined within variable pricing', 'mobile-dj-manager'), 'placeholder' => mdjm_format_amount('10.00')); ?> <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_package_price_field', $post->ID); ?> </div> <?php do_action('mdjm_after_package_price_field', $post->ID); ?> <div id="package-variable-price"> <p><?php echo MDJM()->html->checkbox(array('name' => '_package_variable_pricing', 'current' => $variable)); ?> <label for="_package_variable_pricing"><?php _e('Enable variable pricing', 'mobile-dj-manager'); ?> </label></p> </div> <?php do_action('mdjm_after_package_variable_pricing_field', $post->ID); ?> </div> <div id="mdjm-package-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_package_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_package_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_package_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 }