diff --git a/admin/woocommerce-admin-settings.php b/admin/woocommerce-admin-settings.php index e2c4faeef8e..786395ea94f 100644 --- a/admin/woocommerce-admin-settings.php +++ b/admin/woocommerce-admin-settings.php @@ -133,7 +133,15 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings', 'type' => 'checkbox', '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', diff --git a/assets/js/admin/woocommerce_admin.js b/assets/js/admin/woocommerce_admin.js index 5b8cfb16860..2ce76bbcc4f 100644 --- a/assets/js/admin/woocommerce_admin.js +++ b/assets/js/admin/woocommerce_admin.js @@ -154,5 +154,14 @@ 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); + }); \ No newline at end of file diff --git a/classes/class-wc-cart.php b/classes/class-wc-cart.php index ee0b1bd1c57..1545161fec6 100644 --- a/classes/class-wc-cart.php +++ b/classes/class-wc-cart.php @@ -1224,7 +1224,10 @@ 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) : diff --git a/templates/cart/cart.php b/templates/cart/cart.php index ced8cd1fe6e..31892e439c7 100644 --- a/templates/cart/cart.php +++ b/templates/cart/cart.php @@ -86,9 +86,13 @@ global $woocommerce; ?> -
- -
+ + +
+ +
+ + nonce_field('cart') ?> diff --git a/templates/checkout/form-coupon.php b/templates/checkout/form-coupon.php index 24122457906..cfd764f70cf 100644 --- a/templates/checkout/form-coupon.php +++ b/templates/checkout/form-coupon.php @@ -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')); ?> diff --git a/woocommerce-functions.php b/woocommerce-functions.php index 56d7eb7df1d..13d805dd32b 100644 --- a/woocommerce-functions.php +++ b/woocommerce-functions.php @@ -590,7 +590,10 @@ 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']));