Cleaner coupon types. Closes #40.

This commit is contained in:
Mike Jolley 2011-10-04 10:51:55 +01:00
parent 280803e088
commit 19de729ff8
4 changed files with 33 additions and 9 deletions

View File

@ -37,7 +37,7 @@ function woocommerce_edit_coupon_columns($columns){
add_action('manage_shop_coupon_posts_custom_column', 'woocommerce_custom_coupon_columns', 2);
function woocommerce_custom_coupon_columns($column) {
global $post;
global $post, $woocommerce;
$type = get_post_meta($post->ID, 'discount_type', true);
$amount = get_post_meta($post->ID, 'coupon_amount', true);
@ -49,7 +49,7 @@ function woocommerce_custom_coupon_columns($column) {
switch ($column) {
case "type" :
echo $type;
echo $woocommerce->get_coupon_discount_type($type);
break;
case "amount" :
echo $amount;

View File

@ -15,7 +15,8 @@
* Displays the meta box
*/
function woocommerce_coupon_data_meta_box($post) {
global $woocommerce;
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
?>
@ -26,12 +27,7 @@ function woocommerce_coupon_data_meta_box($post) {
<?php
// Type
$discount_types = apply_filters('woocommerce_coupon_discount_types', array(
'fixed_cart' => __('Cart Discount', 'woothemes'),
'percent' => __('Cart % Discount', 'woothemes'),
'fixed_product' => __('Product Discount', 'woothemes')
));
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __('Discount type', 'woothemes'), 'options' => $discount_types ) );
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __('Discount type', 'woothemes'), 'options' => $woocommerce->get_coupon_discount_types() ) );
// Amount
woocommerce_wp_text_input( array( 'id' => 'coupon_amount', 'label' => __('Coupon amount', 'woothemes'), 'placeholder' => __('0.00', 'woothemes'), 'description' => __('Enter an amount e.g. 2.99 or an integer for percentages e.g. 20%', 'woothemes') ) );

View File

@ -206,6 +206,32 @@ class woocommerce {
if ($label) return $label; else return ucfirst($name);
}
/*-----------------------------------------------------------------------------------*/
/* Coupons */
/*-----------------------------------------------------------------------------------*/
/**
* Get coupon types
*/
function get_coupon_discount_types() {
if (!isset($this->coupon_discount_types)) :
$this->coupon_discount_types = apply_filters('woocommerce_coupon_discount_types', array(
'fixed_cart' => __('Cart Discount', 'woothemes'),
'percent' => __('Cart % Discount', 'woothemes'),
'fixed_product' => __('Product Discount', 'woothemes')
));
endif;
return $this->coupon_discount_types;
}
/**
* Get a coupon type's name
*/
function get_coupon_discount_type( $type = '' ) {
$types = (array) $this->get_coupon_discount_types();
if (isset($types[$type])) return $types[$type];
}
/*-----------------------------------------------------------------------------------*/
/* Nonce Field Helpers */

View File

@ -63,6 +63,8 @@ For further documentation on using WooCommerce, please sign up for free at http:
* Made image size settings clearer
* Cleaned up coupon code settings/write panel and added a few more hooks
* Fixed 'product ids' setting in coupons
* Fixed notices on shop pages due to WP_QUERY
* Cleaned up discount types and made some helper functions for getting them
= 1.0.2 - 02/10/2011 =
* Fix in woocommerce_templates for when a shop is the front-page