New coupon system
This commit is contained in:
parent
416f78de00
commit
3a5b322c4a
|
@ -90,7 +90,9 @@ function woocommerce_dashboard() {
|
|||
</table>
|
||||
</div>
|
||||
<div class="versions">
|
||||
<p id="wp-version-message"><?php _e('You are using', 'woothemes'); ?> <strong>WooCommerce <?php echo WOOCOMMERCE_VERSION; ?>.</strong></p>
|
||||
|
||||
<p id="wp-version-message"><?php _e('You are using', 'woothemes'); ?> <strong>WooCommerce <?php echo WOOCOMMERCE_VERSION; ?></strong> <?php _e('and', 'woothemes'); ?> <strong><?php if (is_multisite()) echo 'WPMU'; else echo 'WP'; ?> <?php echo bloginfo('version'); ?></strong> <?php _e('running on PHP', 'woothemes'); ?> <?php if(function_exists('phpversion')) echo phpversion(); ?> (<?php echo $_SERVER['SERVER_SOFTWARE']; ?>). <?php if(function_exists('fsockopen')) echo '<span style="color:green">' . __('Your server supports fsockopen.', 'woothemes'). '</span>'; else echo '<span style="color:red">' . __('Your server does not support fsockopen.', 'woothemes'). '</span>'; ?></p>
|
||||
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
|
|
@ -36,8 +36,6 @@ function woocommerce_admin_menu() {
|
|||
add_menu_page(__('WooCommerce'), __('WooCommerce'), 'manage_woocommerce', 'woocommerce' , 'woocommerce_dashboard', woocommerce::plugin_url() . '/assets/images/icons/menu_icons.png', 56);
|
||||
add_submenu_page('woocommerce', __('Dashboard', 'woothemes'), __('Dashboard', 'woothemes'), 'manage_woocommerce', 'woocommerce', 'woocommerce_dashboard');
|
||||
add_submenu_page('woocommerce', __('General Settings', 'woothemes'), __('Settings', 'woothemes') , 'manage_woocommerce', 'woocommerce-settings', 'woocommerce_settings');
|
||||
add_submenu_page('woocommerce', __('Coupons', 'woothemes'), __('Coupons', 'woothemes') , 'manage_woocommerce', 'woocommerce-coupons', 'woocommerce_coupons');
|
||||
add_submenu_page('woocommerce', __('System Info', 'woothemes'), __('System Info', 'woothemes'), 'manage_options', 'sysinfo', 'woocommerce_system_info');
|
||||
add_submenu_page('edit.php?post_type=product', __('Attributes', 'woothemes'), __('Attributes', 'woothemes'), 'manage_woocommerce', 'attributes', 'woocommerce_attributes');
|
||||
}
|
||||
|
||||
|
@ -72,7 +70,7 @@ function woocommerce_admin_custom_menu_order() {
|
|||
|
||||
return true;
|
||||
}
|
||||
add_action('admin_menu', 'woocommerce_admin_menu');
|
||||
add_action('admin_menu', 'woocommerce_admin_menu', 9);
|
||||
add_action('menu_order', 'woocommerce_admin_menu_order');
|
||||
add_action('custom_menu_order', 'woocommerce_admin_custom_menu_order');
|
||||
|
||||
|
@ -97,93 +95,6 @@ function woocommerce_admin_head() {
|
|||
add_action('admin_head', 'woocommerce_admin_head');
|
||||
|
||||
|
||||
/**
|
||||
* System info
|
||||
*
|
||||
* Shows the system info panel which contains version data and debug info
|
||||
*/
|
||||
function woocommerce_system_info() {
|
||||
?>
|
||||
<div class="wrap woocommerce">
|
||||
<div class="icon32 icon32-woocommerce-debug" id="icon-woocommerce"><br/></div>
|
||||
<h2><?php _e('System Information', 'woothemes')?></h2>
|
||||
<br class="clear" />
|
||||
<table class="widefat fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" width="200px"><?php _e('Versions', 'woothemes')?></th>
|
||||
<th scope="col"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('WooCommerce Version', 'woothemes')?></td>
|
||||
<td class="forminp"><?php echo woocommerce::get_var('version'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('WordPress Version', 'woothemes')?></td>
|
||||
<td class="forminp"><?php if (is_multisite()) echo 'WPMU'; else echo 'WP'; ?> <?php echo bloginfo('version'); ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" width="200px"><?php _e('Server', 'woothemes')?></th>
|
||||
<th scope="col"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('PHP Version', 'woothemes')?></td>
|
||||
<td class="forminp"><?php if(function_exists('phpversion')) echo phpversion(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('Server Software', 'woothemes')?></td>
|
||||
<td class="forminp"><?php echo $_SERVER['SERVER_SOFTWARE']; ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" width="200px"><?php _e('Debug Information', 'woothemes')?></th>
|
||||
<th scope="col"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('UPLOAD_MAX_FILESIZE', 'woothemes')?></td>
|
||||
<td class="forminp"><?php
|
||||
if(function_exists('phpversion')) echo (woocommerce_let_to_num(ini_get('upload_max_filesize'))/(1024*1024))."MB";
|
||||
?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('POST_MAX_SIZE', 'woothemes')?></td>
|
||||
<td class="forminp"><?php
|
||||
if(function_exists('phpversion')) echo (woocommerce_let_to_num(ini_get('post_max_size'))/(1024*1024))."MB";
|
||||
?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('WordPress Memory Limit', 'woothemes')?></td>
|
||||
<td class="forminp"><?php
|
||||
echo (woocommerce_let_to_num(WP_MEMORY_LIMIT)/(1024*1024))."MB";
|
||||
?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('WP_DEBUG', 'woothemes')?></td>
|
||||
<td class="forminp"><?php if (WP_DEBUG) echo __('On', 'woothemes'); else __('Off', 'woothemes'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('DISPLAY_ERRORS', 'woothemes')?></td>
|
||||
<td class="forminp"><?php if(function_exists('phpversion')) echo ini_get('display_errors'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="titledesc"><?php _e('FSOCKOPEN', 'woothemes')?></td>
|
||||
<td class="forminp"><?php if(function_exists('fsockopen')) echo '<span style="color:green">' . __('Your server supports fsockopen.', 'woothemes'). '</span>'; else echo '<span style="color:red">' . __('Your server does not support fsockopen.', 'woothemes'). '</span>'; ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Feature a product from admin
|
||||
*/
|
||||
|
|
|
@ -12,7 +12,53 @@
|
|||
/**
|
||||
* Custom columns
|
||||
**/
|
||||
function woocommerce_edit_variation_columns($columns){
|
||||
function woocommerce_edit_coupon_columns($columns){
|
||||
|
||||
$columns = array();
|
||||
|
||||
$columns["cb"] = "<input type=\"checkbox\" />";
|
||||
$columns["title"] = __("Code", 'woothemes');
|
||||
$columns["type"] = __("Coupon type", 'woothemes');
|
||||
$columns["amount"] = __("Coupon amount", 'woothemes');
|
||||
$columns["products"] = __("Product IDs", 'woothemes');
|
||||
$columns["usage_limit"] = __("Usage limit", 'woothemes');
|
||||
$columns["usage_count"] = __("Usage count", 'woothemes');
|
||||
|
||||
return $columns;
|
||||
}
|
||||
add_filter('manage_edit-shop_coupon_columns', 'woocommerce_edit_coupon_columns');
|
||||
|
||||
function woocommerce_custom_coupon_columns($column) {
|
||||
global $post;
|
||||
|
||||
$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);
|
||||
|
||||
switch ($column) {
|
||||
case "type" :
|
||||
echo $type;
|
||||
break;
|
||||
case "amount" :
|
||||
echo $amount;
|
||||
break;
|
||||
case "products" :
|
||||
if (sizeof($product_ids)>0) echo implode(', ', $product_ids); else echo '–';
|
||||
break;
|
||||
case "usage_limit" :
|
||||
if ($usage_limit) echo $usage_limit; else echo '–';
|
||||
break;
|
||||
case "usage_count" :
|
||||
echo $usage_count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
add_action('manage_shop_coupon_posts_custom_column', 'woocommerce_custom_coupon_columns', 2);
|
||||
|
||||
function woocommerce_edit_variation_columns($columns){
|
||||
|
||||
$columns = array();
|
||||
|
||||
|
|
|
@ -536,49 +536,6 @@ function woocommerce_update_options($options) {
|
|||
endfor;
|
||||
|
||||
update_option($value['id'], $tax_rates);
|
||||
|
||||
elseif (isset($value['id']) && $value['id']=='woocommerce_coupons') :
|
||||
|
||||
$coupon_code = array();
|
||||
$coupon_type = array();
|
||||
$coupon_amount = array();
|
||||
$product_ids = array();
|
||||
$coupons = array();
|
||||
$individual = array();
|
||||
|
||||
if (isset($_POST['coupon_code'])) $coupon_code = $_POST['coupon_code'];
|
||||
if (isset($_POST['coupon_type'])) $coupon_type = $_POST['coupon_type'];
|
||||
if (isset($_POST['coupon_amount'])) $coupon_amount = $_POST['coupon_amount'];
|
||||
if (isset($_POST['product_ids'])) $product_ids = $_POST['product_ids'];
|
||||
if (isset($_POST['individual'])) $individual = $_POST['individual'];
|
||||
|
||||
for ($i=0; $i<sizeof($coupon_code); $i++) :
|
||||
|
||||
if ( isset($coupon_code[$i]) && isset($coupon_type[$i]) && isset($coupon_amount[$i]) ) :
|
||||
|
||||
$code = woocommerce_clean($coupon_code[$i]);
|
||||
$type = woocommerce_clean($coupon_type[$i]);
|
||||
$amount = woocommerce_clean($coupon_amount[$i]);
|
||||
|
||||
if (isset($product_ids[$i]) && $product_ids[$i]) $products = array_map('trim', explode(',', $product_ids[$i])); else $products = array();
|
||||
|
||||
if (isset($individual[$i]) && $individual[$i]) $individual_use = 'yes'; else $individual_use = 'no';
|
||||
|
||||
if ($code && $type && $amount) :
|
||||
$coupons[$code] = array(
|
||||
'code' => $code,
|
||||
'amount' => $amount,
|
||||
'type' => $type,
|
||||
'products' => $products,
|
||||
'individual_use' => $individual_use
|
||||
);
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
endfor;
|
||||
|
||||
update_option($value['id'], $coupons);
|
||||
|
||||
elseif (isset($value['type']) && $value['type']=='multi_select_countries') :
|
||||
|
||||
|
@ -931,94 +888,4 @@ function woocommerce_settings() {
|
|||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Coupons page
|
||||
*
|
||||
* Handles the display of the coupons page in admin.
|
||||
*/
|
||||
function woocommerce_coupons() {
|
||||
$coupons = new woocommerce_coupons();
|
||||
$coupon_codes = $coupons->get_coupons();
|
||||
?><tr>
|
||||
<td class="titledesc"><?php echo $value['name'] ?>:</td>
|
||||
<td class="forminp" id="coupon_codes">
|
||||
<table class="coupon_rows" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e('Coupon Code', 'woothemes'); ?></th>
|
||||
<th><?php _e('Coupon Type', 'woothemes'); ?></th>
|
||||
<th><?php _e('Coupon Amount', 'woothemes'); ?></th>
|
||||
<th><?php _e('Product ids', 'woothemes'); ?></th>
|
||||
<th><?php _e('Individual use', 'woothemes'); ?></th>
|
||||
<th><?php _e('Delete', 'woothemes'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$i = -1;
|
||||
if ($coupon_codes && is_array($coupon_codes) && sizeof($coupon_codes)>0) foreach( $coupon_codes as $coupon ) : $i++;
|
||||
echo '<tr class="coupon_row"><td><input type="text" value="'.$coupon['code'].'" name="coupon_code['.$i.']" title="'.__('Coupon Code', 'woothemes').'" placeholder="'.__('Coupon Code', 'woothemes').'" class="text" /></td><td><select name="coupon_type['.$i.']" title="Coupon Type">';
|
||||
|
||||
$discount_types = array(
|
||||
'fixed_cart' => __('Cart Discount', 'woothemes'),
|
||||
'percent' => __('Cart % Discount', 'woothemes'),
|
||||
'fixed_product' => __('Product Discount', 'woothemes')
|
||||
);
|
||||
|
||||
foreach ($discount_types as $type => $label) :
|
||||
$selected = ($coupon['type']==$type) ? 'selected="selected"' : '';
|
||||
echo '<option value="'.$type.'" '.$selected.'>'.$label.'</option>';
|
||||
endforeach;
|
||||
|
||||
echo '</select></td><td><input type="text" value="'.$coupon['amount'].'" name="coupon_amount['.$i.']" title="'.__('Coupon Amount', 'woothemes').'" placeholder="'.__('Coupon Amount', 'woothemes').'" class="text" /></td><td><input type="text" value="'.implode(', ', $coupon['products']).'" name="product_ids['.$i.']" placeholder="'.__('1, 2, 3', 'woothemes').'" class="text" /></td><td><label><input type="checkbox" name="individual['.$i.']" ';
|
||||
|
||||
if (isset($coupon['individual_use']) && $coupon['individual_use']=='yes') echo 'checked="checked"';
|
||||
|
||||
echo ' /> '.__('Individual use only', 'woothemes').'</label></td><td><a href="#" class="remove button">×</a></td></tr>';
|
||||
endforeach;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="#" class="add button"><?php _e('+ Add Coupon', 'woothemes'); ?></a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<script type="text/javascript">
|
||||
/* <![CDATA[ */
|
||||
jQuery(function() {
|
||||
jQuery('#coupon_codes a.add').live('click', function(){
|
||||
var size = jQuery('#coupon_codes table.coupon_rows tbody .coupon_row').size();
|
||||
|
||||
// Make sure tbody exists
|
||||
var tbody_size = jQuery('#coupon_codes table.coupon_rows tbody').size();
|
||||
if (tbody_size==0) jQuery('#coupon_codes table.coupon_rows').append('<tbody></tbody>');
|
||||
|
||||
// Add the row
|
||||
jQuery('<tr class="coupon_row">\
|
||||
<td><input type="text" value="" name="coupon_code[' + size + ']" title="<?php _e('Coupon Code', 'woothemes'); ?>" placeholder="<?php _e('Coupon Code', 'woothemes'); ?>" class="text" /></td>\
|
||||
<td><select name="coupon_type[' + size + ']" title="Coupon Type">\
|
||||
<option value="percent"><?php _e('% Discount', 'woothemes'); ?></option>\
|
||||
<option value="fixed_product"><?php _e('Product Discount', 'woothemes');?></option>\
|
||||
<option value="fixed_cart"><?php _e('Cart Discount', 'woothemes'); ?></option>\
|
||||
</select></td>\
|
||||
<td><input type="text" value="" name="coupon_amount[' + size + ']" title="<?php _e('Coupon Amount', 'woothemes'); ?>" placeholder="<?php _e('Coupon Amount', 'woothemes'); ?>" class="text" /></td>\
|
||||
<td><input type="text" value="" name="product_ids[' + size + ']" placeholder="<?php _e('1, 2, 3', 'woothemes'); ?>" class="text" /></td>\
|
||||
<td><label><input type="checkbox" name="individual[' + size + ']" /> <?php _e('Individual use only', 'woothemes'); ?></label></td>\
|
||||
<td><a href="#" class="remove button">×</a></td></tr>').appendTo('#coupon_codes table.coupon_rows tbody');
|
||||
return false;
|
||||
});
|
||||
jQuery('#coupon_codes a.remove').live('click', function(){
|
||||
var answer = confirm("<?php _e('Delete this coupon?', 'woothemes'); ?>")
|
||||
if (answer) {
|
||||
jQuery('input', jQuery(this).parent().parent()).val('');
|
||||
jQuery(this).parent().parent().hide();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
/* ]]> */
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
/**
|
||||
* Coupon Data
|
||||
*
|
||||
* Functions for displaying the coupon data meta box
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Admin Write Panels
|
||||
* @package WooCommerce
|
||||
*/
|
||||
|
||||
/**
|
||||
* Coupon data meta box
|
||||
*
|
||||
* Displays the meta box
|
||||
*/
|
||||
function woocommerce_coupon_data_meta_box($post) {
|
||||
|
||||
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
|
||||
|
||||
?>
|
||||
<style type="text/css">
|
||||
#edit-slug-box { display:none }
|
||||
</style>
|
||||
<div id="coupon_options" class="panel woocommerce_options_panel">
|
||||
<?php
|
||||
|
||||
// Type
|
||||
$value = get_post_meta($post->ID, 'discount_type', true);
|
||||
$field = array( 'id' => 'discount_type', 'label' => __('Discount type', 'woothemes') );
|
||||
echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].':</label><select name="'.$field['id'].'" id="'.$field['id'].'">';
|
||||
|
||||
$discount_types = array(
|
||||
'fixed_cart' => __('Cart Discount', 'woothemes'),
|
||||
'percent' => __('Cart % Discount', 'woothemes'),
|
||||
'fixed_product' => __('Product Discount', 'woothemes')
|
||||
);
|
||||
|
||||
foreach ($discount_types as $type => $label) :
|
||||
echo '<option value="'.$type.'" ';
|
||||
selected($type, $value);
|
||||
echo '>'.$label.'</option>';
|
||||
endforeach;
|
||||
|
||||
echo '</select></p>';
|
||||
|
||||
// Amount
|
||||
$value = get_post_meta($post->ID, 'coupon_amount', true);
|
||||
$field = array( 'id' => 'coupon_amount', 'label' => __('Coupon amount', 'woothemes') );
|
||||
echo '<p class="form-field">
|
||||
<label for="'.$field['id'].'">'.$field['label'].':</label>
|
||||
<input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$value.'" /> <span class="description">' . __('Enter an amount e.g. 2.99 or an integer for percentages e.g. 20', 'woothemes') . '</span></p>';
|
||||
|
||||
// Individual use
|
||||
$value = get_post_meta($post->ID, 'individual_use', true);
|
||||
$field = array( 'id' => 'individual_use', 'label' => __('Individual use', 'woothemes') );
|
||||
echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].':</label>';
|
||||
echo '<input type="checkbox" class="checkbox" name="'.$field['id'].'" id="'.$field['id'].'" ';
|
||||
checked($value, 1);
|
||||
echo ' /> <span class="description">' . __('Check this box if the coupon cannot be used in conjuction with other coupons', 'woothemes');
|
||||
echo '</span></p>';
|
||||
|
||||
// Product ids
|
||||
$value = get_post_meta($post->ID, 'product_ids', true);
|
||||
$field = array( 'id' => 'product_ids', 'label' => __('Product IDs', 'woothemes') );
|
||||
echo '<p class="form-field">
|
||||
<label for="'.$field['id'].'">'.$field['label'].':</label>
|
||||
<input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$value.'" /> <span class="description">' . __('(optional) Comma separate product IDs which are required for this coupon to work', 'woothemes') . '</span></p>';
|
||||
|
||||
// Usage
|
||||
$value = get_post_meta($post->ID, 'usage_limit', true);
|
||||
$field = array( 'id' => 'usage_limit', 'label' => __('Usage limit', 'woothemes') );
|
||||
echo '<p class="form-field">
|
||||
<label for="'.$field['id'].'">'.$field['label'].':</label>
|
||||
<input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$value.'" /> <span class="description">' . __('(optional) How many times this coupon can be used before it is void', 'woothemes') . '</span></p>';
|
||||
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Coupon data meta box
|
||||
*
|
||||
* Displays the meta box
|
||||
*/
|
||||
add_filter('enter_title_here', 'woocommerce_coupon_enter_title_here', 1, 2);
|
||||
|
||||
function woocommerce_coupon_enter_title_here( $text, $post ) {
|
||||
if ($post->post_type=='shop_coupon') return __('Coupon code', 'woothemes');
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Coupon Data Save
|
||||
*
|
||||
* Function for processing and storing all coupon data.
|
||||
*/
|
||||
add_action('woocommerce_process_shop_coupon_meta', 'woocommerce_process_shop_coupon_meta', 1, 2);
|
||||
|
||||
function woocommerce_process_shop_coupon_meta( $post_id, $post ) {
|
||||
global $wpdb;
|
||||
|
||||
$woocommerce_errors = array();
|
||||
|
||||
if (!$_POST['coupon_amount']) $woocommerce_errors[] = __('Coupon amount is required', 'woothemes');
|
||||
|
||||
// Add/Replace data to array
|
||||
$type = strip_tags(stripslashes( $_POST['discount_type'] ));
|
||||
$amount = strip_tags(stripslashes( $_POST['coupon_amount'] ));
|
||||
$product_ids = strip_tags(stripslashes( $_POST['product_ids'] ));
|
||||
$usage_limit = (isset($_POST['usage_limit']) && $_POST['usage_limit']>0) ? (int) $_POST['usage_limit'] : '';
|
||||
$individual_use = isset($_POST['individual_use']) ? 1 : 0;
|
||||
|
||||
// Save
|
||||
update_post_meta( $post_id, 'discount_type', $type );
|
||||
update_post_meta( $post_id, 'coupon_amount', $amount );
|
||||
update_post_meta( $post_id, 'individual_use', $individual_use );
|
||||
update_post_meta( $post_id, 'product_ids', $product_ids );
|
||||
update_post_meta( $post_id, 'usage_limit', $usage_limit );
|
||||
|
||||
// Error Handling
|
||||
if (sizeof($woocommerce_errors)>0) update_option('woocommerce_errors', $woocommerce_errors);
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
require_once('writepanel-product_data.php');
|
||||
require_once('writepanel-product-types.php');
|
||||
require_once('writepanel-order_data.php');
|
||||
require_once('writepanel-coupon_data.php');
|
||||
|
||||
/**
|
||||
* Init the meta boxes
|
||||
|
@ -32,6 +33,11 @@ function woocommerce_meta_boxes() {
|
|||
|
||||
remove_meta_box( 'commentstatusdiv', 'shop_order' , 'normal' );
|
||||
remove_meta_box( 'slugdiv', 'shop_order' , 'normal' );
|
||||
|
||||
add_meta_box( 'woocommerce-coupon-data', __('Coupon Data', 'woothemes'), 'woocommerce_coupon_data_meta_box', 'shop_coupon', 'normal', 'high');
|
||||
|
||||
remove_meta_box( 'commentstatusdiv', 'shop_coupon' , 'normal' );
|
||||
remove_meta_box( 'slugdiv', 'shop_coupon' , 'normal' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +54,7 @@ function woocommerce_meta_boxes_save( $post_id, $post ) {
|
|||
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
|
||||
if ( !isset($_POST['woocommerce_meta_nonce']) || (isset($_POST['woocommerce_meta_nonce']) && !wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ))) return $post_id;
|
||||
if ( !current_user_can( 'edit_post', $post_id )) return $post_id;
|
||||
if ( $post->post_type != 'product' && $post->post_type != 'shop_order' ) return $post_id;
|
||||
if ( $post->post_type != 'product' && $post->post_type != 'shop_order' && $post->post_type != 'shop_coupon' ) return $post_id;
|
||||
|
||||
do_action( 'woocommerce_process_'.$post->post_type.'_meta', $post_id, $post );
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
#menu-posts-product:hover .wp-menu-image,#menu-posts-product.wp-has-current-submenu .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -35px 0px !important;}
|
||||
#menu-posts-shop_order .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -70px -32px !important;}
|
||||
#menu-posts-shop_order:hover .wp-menu-image,#menu-posts-shop_order.wp-has-current-submenu .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -70px 0px !important;}
|
||||
#icon-woocommerce,.woocommerce_icon,.icon32-posts-product,.icon32-posts-shop_order{background-image:url(../images/icons/woocommerce-icons.png) !important;background-position:-11px -6px;}
|
||||
#icon-woocommerce,.woocommerce_icon,.icon32-posts-product,.icon32-posts-shop_order,.icon32-posts-shop_coupon,.icon32-posts-product_variation{background-image:url(../images/icons/woocommerce-icons.png) !important;background-position:-11px -6px;}
|
||||
.icon32-posts-product{background-position:-185px -6px !important;}
|
||||
.icon32-posts-product{background-position:-69px -6px !important;}
|
||||
.icon32-posts-shop_order{background-position:-127px -6px !important;}
|
||||
.icon32-attributes{background-position:-185px -6px !important;}
|
||||
.icon32-attributes,.icon32-posts-product_variation{background-position:-185px -6px !important;}
|
||||
.icon32-woocommerce-settings{background-position:-359px -6px !important;}
|
||||
.icon32-woocommerce-debug{background-position:-417px -6px !important;}
|
||||
.icon32-posts-shop_coupon{background-position:-475px -6px !important;}
|
||||
.order_actions{color:#999;font-size:11px;}.order_actions li{border-top:1px solid #fff;border-bottom:1px solid #ddd;padding:6px;margin:0;line-height:1.6em;}
|
||||
#woocommerce-order-items .inside{margin:0;padding:0;background:#fefefe;}
|
||||
#woocommerce-order-items .buttons{float:left;padding-left:6px;vertical-align:top;}#woocommerce-order-items .buttons .item_id{width:300px;vertical-align:top;}
|
||||
|
@ -135,7 +135,7 @@ a.tips{height:16px;width:16px;margin:4px -8px 0 0;float:right;background:url(../
|
|||
.woocommerce_options_panel textarea,.woocommerce_options_panel input,.woocommerce_options_panel select{margin:0;}
|
||||
.woocommerce_options_panel textarea{width:50% !important;float:left;}
|
||||
.woocommerce_options_panel input{width:50%;float:left;}
|
||||
.woocommerce_options_panel .checkbox,table.woocommerce_variable_attributes .checkbox{vertical-align:middle;margin:7px 0;}
|
||||
.woocommerce_options_panel .checkbox,table.woocommerce_variable_attributes .checkbox{vertical-align:middle;margin:7px 0;width:auto;}
|
||||
.woocommerce_options_panel select{float:left;}
|
||||
.woocommerce_options_panel .short{width:20%;}
|
||||
#woocommerce_attributes{padding:12px;}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
}
|
||||
|
||||
|
||||
#icon-woocommerce, .woocommerce_icon, .icon32-posts-product, .icon32-posts-shop_order {
|
||||
#icon-woocommerce, .woocommerce_icon, .icon32-posts-product, .icon32-posts-shop_order, .icon32-posts-shop_coupon, .icon32-posts-product_variation {
|
||||
background-image: url(../images/icons/woocommerce-icons.png) !important;
|
||||
background-position: -11px -6px;
|
||||
}
|
||||
|
@ -39,14 +39,14 @@
|
|||
.icon32-posts-shop_order {
|
||||
background-position: -127px -6px !important;
|
||||
}
|
||||
.icon32-attributes {
|
||||
.icon32-attributes, .icon32-posts-product_variation {
|
||||
background-position: -185px -6px !important;
|
||||
}
|
||||
.icon32-woocommerce-settings {
|
||||
background-position: -359px -6px !important;
|
||||
}
|
||||
.icon32-woocommerce-debug {
|
||||
background-position: -417px -6px !important;
|
||||
.icon32-posts-shop_coupon {
|
||||
background-position: -475px -6px !important;
|
||||
}
|
||||
|
||||
/* Orders */
|
||||
|
@ -734,6 +734,7 @@ a.tips {
|
|||
.woocommerce_options_panel .checkbox, table.woocommerce_variable_attributes .checkbox {
|
||||
vertical-align: middle;
|
||||
margin: 7px 0;
|
||||
width: auto;
|
||||
}
|
||||
.woocommerce_options_panel select {
|
||||
float: left;
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 8.6 KiB |
|
@ -519,13 +519,13 @@ class woocommerce_cart {
|
|||
endif;
|
||||
|
||||
// If its individual use then remove other coupons
|
||||
if ($the_coupon['individual_use']=='yes') :
|
||||
if ($the_coupon['individual_use']==1) :
|
||||
self::$applied_coupons = array();
|
||||
endif;
|
||||
|
||||
foreach (self::$applied_coupons as $coupon) :
|
||||
$coupon = woocommerce_coupons::get_coupon($coupon);
|
||||
if ($coupon['individual_use']=='yes') :
|
||||
if ($coupon['individual_use']==1) :
|
||||
self::$applied_coupons = array();
|
||||
endif;
|
||||
endforeach;
|
||||
|
|
|
@ -584,6 +584,9 @@ class woocommerce_checkout {
|
|||
if (is_wp_error($order_id)) :
|
||||
woocommerce::add_error( 'Error: Unable to create order. Please try again.' );
|
||||
break;
|
||||
else :
|
||||
// Inserted successfully
|
||||
do_action('woocommerce_new_order', $order_id);
|
||||
endif;
|
||||
endif;
|
||||
|
||||
|
@ -595,9 +598,6 @@ class woocommerce_checkout {
|
|||
wp_set_object_terms( $order_id, 'pending', 'shop_order_status' );
|
||||
|
||||
$order = &new woocommerce_order($order_id);
|
||||
|
||||
// Inserted successfully
|
||||
do_action('woocommerce_new_order', $order_id);
|
||||
|
||||
if (woocommerce_cart::needs_payment()) :
|
||||
|
||||
|
|
|
@ -11,31 +11,74 @@
|
|||
*/
|
||||
class woocommerce_coupons {
|
||||
|
||||
/** get coupons from the options database */
|
||||
function get_coupons() {
|
||||
$coupons = get_option('woocommerce_coupons') ? $coupons = (array) get_option('woocommerce_coupons') : $coupons = array();
|
||||
return $coupons;
|
||||
}
|
||||
|
||||
/** get coupon with $code */
|
||||
function get_coupon($code) {
|
||||
$coupons = get_option('woocommerce_coupons') ? $coupons = (array) get_option('woocommerce_coupons') : $coupons = array();
|
||||
if (isset($coupons[$code])) return $coupons[$code];
|
||||
function get_coupon( $code ) {
|
||||
|
||||
$coupon = get_page_by_title( $code, 'OBJECT', 'shop_coupon' );
|
||||
|
||||
if ($coupon && $coupon->post_status == 'publish') :
|
||||
|
||||
$type = get_post_meta($coupon->ID, 'discount_type', true);
|
||||
$amount = get_post_meta($coupon->ID, 'coupon_amount', true);
|
||||
$individual_use = get_post_meta($coupon->ID, 'individual_use', true);
|
||||
$product_ids = array_map('trim', explode(',', get_post_meta($coupon->ID, 'product_ids', true)));
|
||||
$usage_limit = get_post_meta($coupon->ID, 'usage_limit', true);
|
||||
$usage_count = (int) get_post_meta($coupon->ID, 'usage_count', true);
|
||||
|
||||
if (!$amount) return false;
|
||||
|
||||
return array(
|
||||
'id' => $coupon->ID,
|
||||
'code' => $code,
|
||||
'type' => $type,
|
||||
'amount' => $amount,
|
||||
'individual_use' => $individual_use,
|
||||
'products' => $product_ids,
|
||||
'usage_limit' => $usage_limit,
|
||||
'usage_count' => $usage_count
|
||||
);
|
||||
|
||||
endif;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Check coupon is valid by looking at cart */
|
||||
/** Increase usage count */
|
||||
function inc_usage_count( $code ) {
|
||||
$coupon = get_page_by_title( $code, 'OBJECT', 'shop_coupon' );
|
||||
if ($coupon) :
|
||||
$usage_count = (int) get_post_meta($coupon->ID, 'usage_count', true);
|
||||
$usage_count++;
|
||||
update_post_meta($coupon->ID, 'usage_count', $usage_count);
|
||||
endif;
|
||||
}
|
||||
|
||||
/** Check coupon is valid */
|
||||
function is_valid($code) {
|
||||
$coupon = self::get_coupon($code);
|
||||
if (sizeof($coupon['products'])>0) :
|
||||
$valid = false;
|
||||
if (sizeof(woocommerce_cart::$cart_contents)>0) : foreach (woocommerce_cart::$cart_contents as $item_id => $values) :
|
||||
if (in_array($item_id, $coupon['products'])) :
|
||||
$valid = true;
|
||||
|
||||
if ($coupon) :
|
||||
|
||||
if (sizeof($coupon['products'])>0) :
|
||||
$valid = false;
|
||||
if (sizeof(woocommerce_cart::$cart_contents)>0) : foreach (woocommerce_cart::$cart_contents as $item_id => $values) :
|
||||
if (in_array($item_id, $coupon['products'])) :
|
||||
$valid = true;
|
||||
endif;
|
||||
endforeach; endif;
|
||||
if (!$valid) return false;
|
||||
endif;
|
||||
|
||||
if ($coupon['usage_limit']>0) :
|
||||
if ($coupon['usage_count']>$coupon['usage_limit']) :
|
||||
return false;
|
||||
endif;
|
||||
endforeach; endif;
|
||||
return $valid;
|
||||
endif;
|
||||
|
||||
return true;
|
||||
|
||||
endif;
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* Actions/functions/hooks for WooCommerce related events.
|
||||
*
|
||||
* - Increase coupon usage count
|
||||
* - Get variation
|
||||
* - Add order item
|
||||
* - When default permalinks are enabled, redirect shop page to post type archive url
|
||||
|
@ -19,6 +20,18 @@
|
|||
* @author WooThemes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Increase coupon usage count
|
||||
*/
|
||||
add_action('woocommerce_new_order', 'woocommerce_increase_coupon_counts');
|
||||
|
||||
function woocommerce_increase_coupon_counts() {
|
||||
if (woocommerce_cart::$applied_coupons) foreach (woocommerce_cart::$applied_coupons as $code) :
|
||||
woocommerce_coupons::inc_usage_count($code);
|
||||
endforeach;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get variation price etc when using frontend form
|
||||
*/
|
||||
|
|
|
@ -203,7 +203,7 @@ function woocommerce_post_type() {
|
|||
'capability_type' => 'post',
|
||||
'publicly_queryable' => false,
|
||||
'exclude_from_search' => true,
|
||||
'menu_position' => 58,
|
||||
'show_in_menu' => 'woocommerce',
|
||||
'hierarchical' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'rewrite' => false,
|
||||
|
@ -236,6 +236,38 @@ function woocommerce_post_type() {
|
|||
'rewrite' => false,
|
||||
)
|
||||
);
|
||||
|
||||
register_post_type( "shop_coupon",
|
||||
array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Coupons', 'woothemes' ),
|
||||
'singular_name' => __( 'Coupon', 'woothemes' ),
|
||||
'add_new' => __( 'Add Coupon', 'woothemes' ),
|
||||
'add_new_item' => __( 'Add New Coupon', 'woothemes' ),
|
||||
'edit' => __( 'Edit', 'woothemes' ),
|
||||
'edit_item' => __( 'Edit Coupon', 'woothemes' ),
|
||||
'new_item' => __( 'New Coupon', 'woothemes' ),
|
||||
'view' => __( 'View Coupons', 'woothemes' ),
|
||||
'view_item' => __( 'View Coupon', 'woothemes' ),
|
||||
'search_items' => __( 'Search Coupons', 'woothemes' ),
|
||||
'not_found' => __( 'No Coupons found', 'woothemes' ),
|
||||
'not_found_in_trash' => __( 'No Coupons found in trash', 'woothemes' ),
|
||||
'parent' => __( 'Parent Coupon', 'woothemes' )
|
||||
),
|
||||
'description' => __( 'This is where you can add new coupons that customers can use in your store.', 'woothemes' ),
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
'capability_type' => 'post',
|
||||
'publicly_queryable' => true,
|
||||
'exclude_from_search' => true,
|
||||
'show_in_menu' => 'woocommerce',
|
||||
'hierarchical' => false,
|
||||
'rewrite' => false,
|
||||
'query_var' => false,
|
||||
'supports' => array( 'title' ),
|
||||
'show_in_nav_menus' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if (get_option('woocommerce_update_rewrite_rules')=='1') :
|
||||
// Re-generate rewrite rules
|
||||
|
|
Loading…
Reference in New Issue