Added option to globally enable/disable the use of coupons for clients

This commit is contained in:
Geert De Deckere 2012-03-12 10:25:06 +01:00
parent 3b74269ed2
commit 0401e79ed4
6 changed files with 35 additions and 8 deletions

View File

@ -134,6 +134,14 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
'checkboxgroup' => 'start'
),
array(
'desc' => __( 'Enable coupons', 'woocommerce' ),
'id' => 'woocommerce_enable_coupons',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Enable coupon form on checkout', 'woocommerce' ),
'id' => 'woocommerce_enable_coupon_form_on_checkout',

View File

@ -155,4 +155,13 @@ jQuery(function(){
}).change();
// Enable/disable the coupon form on checkout checkbox
var $woocommerce_enable_coupons = jQuery('#woocommerce_enable_coupons'),
$woocommerce_enable_coupon_form_on_checkout = jQuery('#woocommerce_enable_coupon_form_on_checkout'),
toggle_woocommerce_enable_coupon_form_on_checkout = function () {
$woocommerce_enable_coupon_form_on_checkout.closest('fieldset').attr('disabled', ! $woocommerce_enable_coupons.is(':checked'));
};
toggle_woocommerce_enable_coupon_form_on_checkout();
$woocommerce_enable_coupons.change(toggle_woocommerce_enable_coupon_form_on_checkout);
});

View File

@ -1225,6 +1225,9 @@ class WC_Cart {
function add_discount( $coupon_code ) {
global $woocommerce;
// Coupons are globally disabled
if ( get_option( 'woocommerce_enable_coupons' ) == 'no' ) return false;
$the_coupon = new WC_Coupon($coupon_code);
if ($the_coupon->id) :

View File

@ -86,9 +86,13 @@ global $woocommerce;
?>
<tr>
<td colspan="6" class="actions">
<?php if ( get_option( 'woocommerce_enable_coupons' ) == 'yes' ) { ?>
<div class="coupon">
<label for="coupon_code"><?php _e('Coupon', 'woocommerce'); ?>:</label> <input name="coupon_code" class="input-text" id="coupon_code" value="" /> <input type="submit" class="button" name="apply_coupon" value="<?php _e('Apply Coupon', 'woocommerce'); ?>" />
</div>
<?php } ?>
<?php $woocommerce->nonce_field('cart') ?>
<input type="submit" class="button" name="update_cart" value="<?php _e('Update Cart', 'woocommerce'); ?>" /> <a href="<?php echo esc_url( $woocommerce->cart->get_checkout_url() ); ?>" class="checkout-button button alt"><?php _e('Proceed to Checkout &rarr;', 'woocommerce'); ?></a>
<?php do_action('woocommerce_proceed_to_checkout'); ?>

View File

@ -2,7 +2,7 @@
/**
* Checkout Coupon Form
*/
if (get_option('woocommerce_enable_coupon_form_on_checkout')=="no") return;
if ( get_option( 'woocommerce_enable_coupons' ) == 'no' || get_option( 'woocommerce_enable_coupon_form_on_checkout' ) == 'no' ) return;
$info_message = apply_filters('woocommerce_checkout_coupon_message', __('Have a coupon?', 'woocommerce'));
?>

View File

@ -591,6 +591,9 @@ function woocommerce_process_login() {
function woocommerce_process_coupon_form() {
global $woocommerce;
// Do nothing if coupons are globally disabled
if ( get_option( 'woocommerce_enable_coupons' ) == 'no' ) return;
if (isset($_POST['coupon_code']) && $_POST['coupon_code']) :
$coupon_code = stripslashes(trim($_POST['coupon_code']));