Coupon description. Closes #1560.

This commit is contained in:
Mike Jolley 2012-10-12 18:28:34 +01:00
parent 68749697b1
commit c9a6680438
4 changed files with 37 additions and 24 deletions

View File

@ -23,9 +23,9 @@ function woocommerce_edit_coupon_columns($columns){
$columns["title"] = __("Code", 'woocommerce');
$columns["type"] = __("Coupon type", 'woocommerce');
$columns["amount"] = __("Coupon amount", 'woocommerce');
$columns["description"] = __("Description", 'woocommerce');
$columns["products"] = __("Product IDs", 'woocommerce');
$columns["usage_limit"] = __("Usage limit", 'woocommerce');
$columns["usage_count"] = __("Usage count", 'woocommerce');
$columns["usage"] = __("Usage / Limit", 'woocommerce');
$columns["expiry_date"] = __("Expiry date", 'woocommerce');
return $columns;
@ -44,32 +44,39 @@ add_filter('manage_edit-shop_coupon_columns', 'woocommerce_edit_coupon_columns')
function woocommerce_custom_coupon_columns($column) {
global $post, $woocommerce;
$type = get_post_meta($post->ID, 'discount_type', true);
$amount = get_post_meta($post->ID, 'coupon_amount', true);
$individual_use = get_post_meta($post->ID, 'individual_use', true);
$product_ids = (get_post_meta($post->ID, 'product_ids', true)) ? explode(',', get_post_meta($post->ID, 'product_ids', true)) : array();
$usage_limit = get_post_meta($post->ID, 'usage_limit', true);
$usage_count = (int) get_post_meta($post->ID, 'usage_count', true);
$expiry_date = get_post_meta($post->ID, 'expiry_date', true);
switch ($column) {
case "type" :
echo $woocommerce->get_coupon_discount_type($type);
echo $woocommerce->get_coupon_discount_type( get_post_meta( $post->ID, 'discount_type', true ) );
break;
case "amount" :
echo $amount;
echo get_post_meta( $post->ID, 'coupon_amount', true );
break;
case "products" :
if (sizeof($product_ids)>0) echo implode(', ', $product_ids); else echo '–';
$product_ids = get_post_meta($post->ID, 'product_ids', true) ? explode(',', get_post_meta($post->ID, 'product_ids', true)) : array();
if ( sizeof( $product_ids ) > 0 ) echo implode( ', ', $product_ids ); else echo '–';
break;
case "usage_limit" :
if ($usage_limit) echo $usage_limit; else echo '–';
$usage_limit = get_post_meta($post->ID, 'usage_limit', true);
if ( $usage_limit ) echo $usage_limit; else echo '–';
break;
case "usage_count" :
echo $usage_count;
case "usage" :
$usage_count = absint( get_post_meta( $post->ID, 'usage_count', true ) );
$usage_limit = get_post_meta($post->ID, 'usage_limit', true);
if ( $usage_limit )
printf( __( '%s / %s', 'woocommerce' ), $usage_count, $usage_limit );
else
printf( __( '%s / ∞', 'woocommerce' ), $usage_count );
break;
case "expiry_date" :
if ($expiry_date) echo date_i18n( 'F j, Y', strtotime( $expiry_date ) ); else echo '–';
$expiry_date = get_post_meta($post->ID, 'expiry_date', true);
if ( $expiry_date ) echo date_i18n( 'F j, Y', strtotime( $expiry_date ) ); else echo '–';
break;
case "description" :
echo $post->post_excerpt;
break;
}
}

View File

@ -25,19 +25,22 @@ function woocommerce_coupon_data_meta_box($post) {
?>
<style type="text/css">
#edit-slug-box { display:none }
#edit-slug-box, #minor-publishing-actions { display:none }
</style>
<div id="coupon_options" class="panel woocommerce_options_panel">
<?php
echo '<div class="options_group">';
// Type
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __('Discount type', 'woocommerce'), 'options' => $woocommerce->get_coupon_discount_types() ) );
// Amount
woocommerce_wp_text_input( array( 'id' => 'coupon_amount', 'label' => __('Coupon amount', 'woocommerce'), 'placeholder' => '0.00', 'description' => __('Enter an amount e.g. 2.99', 'woocommerce') ) );
// Description
woocommerce_wp_text_input( array( 'id' => 'coupon_description', 'label' => __('Coupon description', 'woocommerce'), 'description' => __('Optionally enter a description for this coupon', 'woocommerce'), 'value' => $post->post_excerpt, 'name' => 'excerpt' ) );
// Individual use
woocommerce_wp_checkbox( array( 'id' => 'individual_use', 'label' => __('Individual use', 'woocommerce'), 'description' => __('Check this box if the coupon cannot be used in conjunction with other coupons', 'woocommerce') ) );
@ -179,6 +182,7 @@ function woocommerce_process_shop_coupon_meta( $post_id, $post ) {
AND $wpdb->posts.post_title = '%s'
AND $wpdb->posts.ID != %s
", esc_attr( $_POST['post_title'] ), $post_id ) );
if ( $coupon_found )
$woocommerce_errors[] = __( 'Coupon code already exists.', 'woocommerce' );

View File

@ -312,12 +312,13 @@ add_action( 'admin_notices', 'woocommerce_meta_boxes_show_errors' );
function woocommerce_wp_text_input( $field ) {
global $thepostid, $post, $woocommerce;
if (!$thepostid) $thepostid = $post->ID;
if (!isset($field['placeholder'])) $field['placeholder'] = '';
if (!isset($field['class'])) $field['class'] = 'short';
if (!isset($field['value'])) $field['value'] = get_post_meta($thepostid, $field['id'], true);
if ( ! $thepostid ) $thepostid = $post->ID;
if ( ! isset( $field['placeholder'] ) ) $field['placeholder'] = '';
if ( ! isset( $field['class'] ) ) $field['class'] = 'short';
if ( ! isset( $field['value'] ) ) $field['value'] = get_post_meta( $thepostid, $field['id'], true );
if ( ! isset( $field['name'] ) ) $field['name'] = $field['id'];
echo '<p class="form-field '.$field['id'].'_field"><label for="'.$field['id'].'">'.$field['label'].'</label><input type="text" class="'.$field['class'].'" name="'.$field['id'].'" id="'.$field['id'].'" value="'.esc_attr( $field['value'] ).'" placeholder="'.$field['placeholder'].'" /> ';
echo '<p class="form-field '.$field['id'].'_field"><label for="'.$field['id'].'">'.$field['label'].'</label><input type="text" class="'.$field['class'].'" name="'.$field['name'].'" id="'.$field['id'].'" value="'.esc_attr( $field['value'] ).'" placeholder="'.$field['placeholder'].'" /> ';
if ( isset( $field['description'] ) && $field['description'] ) {

View File

@ -196,6 +196,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - Recoded add_to_cart_action for better handling of variations and groups.
* Tweak - Admin sales stats show totals.
* Tweak - product_variations_{id} changed to product_variations array
* Tweak - Coupon description field.
* Fix - Added more error messages for coupons.
* Fix - Variation sku updating after selection.