/**
 * 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);
}
Beispiel #2
0
/**
 * 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 
}