function jigoshop_custom_coupon_columns($column)
{
    global $post;
    $type = get_post_meta($post->ID, 'type', true);
    $amount = get_post_meta($post->ID, 'amount', true);
    $usage_limit = get_post_meta($post->ID, 'usage_limit', true);
    $usage_count = (int) get_post_meta($post->ID, 'usage', true);
    $start_date = get_post_meta($post->ID, 'date_from', true);
    $end_date = get_post_meta($post->ID, 'date_to', true);
    $individual = get_post_meta($post->ID, 'individual_use', true);
    switch ($column) {
        case "coupon_code":
            echo '<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '">' . $post->post_name . '</a>';
            break;
        case 'coupon_type':
            $types = JS_Coupons::get_coupon_types();
            echo $types[$type];
            break;
        case 'coupon_amount':
            echo $amount;
            break;
        case 'usage_limit':
            echo $usage_limit > 0 ? $usage_limit : '&ndash;';
            break;
        case 'usage_count':
            echo $usage_count;
            break;
        case 'start_date':
            echo $start_date != '' ? date('Y-m-d', $start_date) : '&ndash;';
            break;
        case 'end_date':
            echo $end_date != '' ? date('Y-m-d', $end_date) : '&ndash;';
            break;
        case 'individual':
            echo $individual ? __('Yes', 'jigoshop') : '&ndash;';
            break;
    }
}
Ejemplo n.º 2
0
/**
 * Coupon data meta box
 *
 * Displays the meta box
 */
function jigoshop_coupon_data_box($post)
{
    global $jigoshop;
    wp_nonce_field('jigoshop_save_data', 'jigoshop_meta_nonce');
    $coupon_code = '';
    $coupon_code .= "<p class='form-field'>";
    $coupon_code .= "<label>" . __('Coupon Code', 'jigoshop') . "</label>";
    $coupon_code .= "<span><strong>" . $post->post_name . "</strong></span>";
    $coupon_code .= '<span class="description">' . __('Will not appear until coupon is saved.  This is the front end code for use on the Cart.', 'jigoshop') . '</span>';
    $coupon_code .= "</p>";
    // disable the permalink slug display
    ?>
		<style type="text/css">#edit-slug-box { display:none }</style>

		<div id="coupon_options" class="panel jigoshop_options_panel">

			<div class="options_group">

			<?php 
    // The coupon code from the title after 'sanitize_title'
    echo $coupon_code;
    // Coupon Types
    $args = array('id' => 'type', 'label' => __('Coupon Type', 'jigoshop'), 'options' => JS_Coupons::get_coupon_types());
    echo Jigoshop_Forms::select($args);
    // Amount
    $args = array('id' => 'amount', 'label' => __('Coupon Amount', 'jigoshop'), 'type' => 'number', 'min' => 0, 'desc' => __('Enter an amount e.g. 9.99.', 'jigoshop'), 'tip' => __('Amount this coupon is worth. If it is a percentange, just include the number without the percentage sign.', 'jigoshop'), 'placeholder' => '0.00');
    echo Jigoshop_Forms::input($args);
    // Date From
    $coupon_date_from = get_post_meta($post->ID, 'date_from', true);
    $args = array('id' => 'date_from', 'label' => __('Date From', 'jigoshop'), 'desc' => __('yyyy-mm-dd', 'jigoshop'), 'tip' => __('Choose between which dates this coupon is enabled.  Leave empty for any date.', 'jigoshop'), 'class' => 'short date-pick', 'placeholder' => __('Any date', 'jigoshop'), 'value' => $coupon_date_from != '' ? date('Y-m-d', $coupon_date_from) : '');
    echo Jigoshop_Forms::input($args);
    // Date To
    $coupon_date_to = get_post_meta($post->ID, 'date_to', true);
    $args = array('id' => 'date_to', 'label' => __('Date To', 'jigoshop'), 'desc' => __('yyyy-mm-dd', 'jigoshop'), 'tip' => __('Choose between which dates this coupon is enabled.  Leave empty for any date.', 'jigoshop'), 'class' => 'short date-pick', 'placeholder' => __('Any date', 'jigoshop'), 'value' => $coupon_date_to != '' ? date('Y-m-d', $coupon_date_to) : '');
    echo Jigoshop_Forms::input($args);
    // Usage limit
    $usage = get_post_meta($post->ID, 'usage', true);
    $args = array('id' => 'usage_limit', 'label' => __('Usage Limit', 'jigoshop'), 'type' => 'number', 'desc' => sprintf(__('Times used: %s', 'jigoshop'), !empty($usage) ? $usage : '0'), 'tip' => __('Control how many times this coupon may be used.', 'jigoshop'), 'placeholder' => '0');
    echo Jigoshop_Forms::input($args);
    // Individual use
    $args = array('id' => 'individual_use', 'label' => __('Individual Use', 'jigoshop'), 'desc' => __('Prevent other coupons from being used while this one is applied to the Cart.', 'jigoshop'), 'value' => false);
    echo Jigoshop_Forms::checkbox($args);
    // Free shipping
    $args = array('id' => 'free_shipping', 'label' => __('Free shipping', 'jigoshop'), 'desc' => __('Show the Free Shipping method on the Checkout with this enabled.', 'jigoshop'), 'value' => false);
    echo Jigoshop_Forms::checkbox($args);
    ?>
			</div><div class="options_group">
		<?php 
    // Order total minimum
    $args = array('id' => 'order_total_min', 'label' => __('Order total min', 'jigoshop'), 'type' => 'number', 'desc' => __('Set the required minimum subtotal for this coupon to be valid on an order.', 'jigoshop'), 'placeholder' => __('No min', 'jigoshop'));
    echo Jigoshop_Forms::input($args);
    // Order total maximum
    $args = array('id' => 'order_total_max', 'label' => __('Order total max', 'jigoshop'), 'type' => 'number', 'desc' => __('Set the required maximum subtotal for this coupon to be valid on an order.', 'jigoshop'), 'placeholder' => __('No max', 'jigoshop'));
    echo Jigoshop_Forms::input($args);
    ?>
			</div><div class="options_group">
		<?php 
    // Include product ID's
    $selected = get_post_meta($post->ID, 'include_products', true);
    $selected = implode(',', (array) $selected);
    $args = array('id' => 'include_products', 'type' => 'hidden', 'class' => 'long', 'label' => __('Include Products', 'jigoshop'), 'desc' => __('Control which products this coupon can apply to.', 'jigoshop'), 'value' => $selected);
    echo Jigoshop_Forms::input($args);
    // Exclude product ID's
    $selected = get_post_meta($post->ID, 'exclude_products', true);
    $selected = implode(',', (array) $selected);
    $args = array('id' => 'exclude_products', 'type' => 'hidden', 'class' => 'long', 'label' => __('Exclude Products', 'jigoshop'), 'desc' => __('Control which products this coupon cannot be applied to.', 'jigoshop'), 'value' => $selected);
    echo Jigoshop_Forms::input($args);
    ?>
			</div><div class="options_group">
		<?php 
    // Include Categories
    $categories = get_terms('product_cat', array('hide_empty' => false));
    $coupon_cats = array();
    foreach ($categories as $category) {
        $coupon_cats[$category->term_id] = $category->name;
    }
    $args = array('id' => 'include_categories', 'label' => __('Include Categories', 'jigoshop'), 'desc' => __('Control which product categories this coupon can apply to.', 'jigoshop'), 'multiple' => true, 'placeholder' => __('Any category', 'jigoshop'), 'options' => $coupon_cats);
    echo Jigoshop_Forms::select($args);
    // Exclude Categories
    $args = array('id' => 'exclude_categories', 'label' => __('Exclude Categories', 'jigoshop'), 'desc' => __('Control which product categories this coupon cannot be applied to.', 'jigoshop'), 'multiple' => true, 'placeholder' => __('No exclusions', 'jigoshop'), 'options' => $coupon_cats);
    echo Jigoshop_Forms::select($args);
    ?>
			</div><div class="options_group">
		<?php 
    // Payment methods
    $payment_methods = array();
    $available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
    if (!empty($available_gateways)) {
        foreach ($available_gateways as $id => $info) {
            $payment_methods[$id] = $info->title;
        }
    }
    $args = array('id' => 'pay_methods', 'label' => __('Payment Methods', 'jigoshop'), 'desc' => __('Control which payment methods are allowed for this coupon to be effective.', 'jigoshop'), 'multiple' => true, 'placeholder' => __('Any method', 'jigoshop'), 'options' => $payment_methods);
    echo Jigoshop_Forms::select($args);
    // javascript for product includes and excludes -- need to move this
    ?>
			<script type="text/javascript">
			/*<![CDATA[*/
				jQuery(document).ready(function($) {
					$('#date_from').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} );
					$('#date_to').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} );

					// allow searching of products to use on a coupon
					$("#include_products").select2({
						minimumInputLength: 3,
						multiple: true,
						closeOnSelect: true,
						placeholder: "<?php 
    _e('Any product', 'jigoshop');
    ?>
",
						ajax: {
							url: "<?php 
    echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
    ?>
",
							dataType: 'json',
							quietMillis: 100,
							data: function(term, page) {
								return {
									term:       term,
									action:     'jigoshop_json_search_products_and_variations',
									security:   '<?php 
    echo wp_create_nonce("search-products");
    ?>
'
								};
							},
							results: function( data, page ) {
								return { results: data };
							}
						},
						initSelection: function( element, callback ) {
							var stuff = {
								action:     'jigoshop_json_search_products_and_variations',
								security:   '<?php 
    echo wp_create_nonce("search-products");
    ?>
',
								term:       element.val()
							};
							var data = [];
							$.ajax({
								type: 		'GET',
								url:        "<?php 
    echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
    ?>
",
								dataType: 	"json",
								data: 		stuff,
								success: 	function( result ) {
									callback( result );
								}
							});
						}
					});

					// allow searching of products to exclude on a coupon
					$("#exclude_products").select2({
						minimumInputLength: 3,
						multiple: true,
						closeOnSelect: true,
						placeholder: "<?php 
    _e('No exclusions', 'jigoshop');
    ?>
",
						ajax: {
							url: "<?php 
    echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
    ?>
",
							dataType: 'json',
							quietMillis: 100,
							data: function(term, page) {
								return {
									term:       term,
									action:     'jigoshop_json_search_products_and_variations',
									security:   '<?php 
    echo wp_create_nonce("search-products");
    ?>
'
								};
							},
							results: function( data, page ) {
								return { results: data };
							}
						},
						initSelection: function( element, callback ) {
							var stuff = {
								action:     'jigoshop_json_search_products_and_variations',
								security:   '<?php 
    echo wp_create_nonce("search-products");
    ?>
',
								term:       element.val()
							};
							$.ajax({
								type: 		'GET',
								url:        "<?php 
    echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
    ?>
",
								dataType: 	"json",
								data: 		stuff,
								success: 	function( result ) {
									callback( result );
								}
							});
						}
					});
				});
			/*]]>*/
			</script>
		</div></div>
	<?php 
}