Changeset 2860469
- Timestamp:
- 02/05/2023 06:10:29 PM (3 years ago)
- Location:
- disable-coupons-at-product-level
- Files:
-
- 5 added
- 2 edited
-
tags/1.1 (added)
-
tags/1.1/css (added)
-
tags/1.1/css/admin.css (added)
-
tags/1.1/disable-coupons.php (added)
-
tags/1.1/readme.txt (added)
-
trunk/disable-coupons.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
disable-coupons-at-product-level/trunk/disable-coupons.php
r2857355 r2860469 3 3 * Plugin Name: Disable Coupons At Product Level 4 4 * Description: A plugin to disable coupons on selected products 5 * Version: 1. 0.15 * Version: 1.1 6 6 * Author: Phil Clerkin 7 7 * Author URI: https://greyphox.com/ … … 43 43 44 44 45 46 45 // Save the checkbox choice and update all excluded product ids in option WP settings 47 46 add_action( 'woocommerce_process_product_meta', 'DCAPL_save_custom_field_general_product_fields', 10, 1 ); … … 62 61 add_filter('woocommerce_coupon_is_valid_for_product', 'DCAPL_set_coupon_validity_for_excluded_products', 12, 4); 63 62 function DCAPL_set_coupon_validity_for_excluded_products($valid, $product, $coupon, $values ){ 64 $disabled_products = get_option( 'DCAPL_products_disable_coupons' );65 $valid = count( $disabled_products ) > 0 && in_array( $product->get_id(), $disabled_products) ? false : $valid;66 return $valid;63 $disabled_products = get_option( 'DCAPL_products_disable_coupons' ); 64 $valid = count( $disabled_products ) > 0 && ( in_array( $product->get_id(), $disabled_products ) || ( $product->get_parent_id() && in_array( $product->get_parent_id(), $disabled_products ) ) ) ? false : $valid; 65 return $valid; 67 66 } 67 68 68 69 69 // Set the discount to zero 70 70 add_filter( 'woocommerce_coupon_get_discount_amount', 'DCAPL_zero_discount_for_excluded_products', 12, 5 ); 71 71 function DCAPL_zero_discount_for_excluded_products($discount, $discounting_amount, $cart_item, $single, $coupon ){ 72 $disabled_products = get_option( 'DCAPL_products_disable_coupons' );73 $discount = count( $disabled_products ) > 0 && in_array( $cart_item['product_id'], $disabled_products ) ? 0 : $discount;74 return $discount;72 $disabled_products = get_option( 'DCAPL_products_disable_coupons' ); 73 $discount = count( $disabled_products ) > 0 && in_array( $cart_item['product_id'], $disabled_products ) ? 0 : $discount; 74 return $discount; 75 75 } 76 77 78 add_filter( 'woocommerce_cart_totals_coupon_html', 'DCAPL_add_message_for_ineligible_products', 10, 2 ); 79 function DCAPL_add_message_for_ineligible_products( $coupon_html, $coupon ) { 80 global $woocommerce; 81 $cart = $woocommerce->cart->get_cart(); 82 $disabled_products = get_option( 'DCAPL_products_disable_coupons' ); 83 84 $ineligible_items = false; 85 foreach ( $cart as $cart_item ) { 86 $ineligible_items = in_array( $cart_item['product_id'], $disabled_products ) ? true : $ineligible_items; 87 } 88 89 return $coupon_html . ( $ineligible_items ? '<small class="not-eligible-message">' . __( 'Some items in your cart are not eligible for this coupon', 'woocommerce' ) . '</small>' : '' ); 90 } 91 76 92 77 93 -
disable-coupons-at-product-level/trunk/readme.txt
r2857355 r2860469 7 7 License: GPLv2 or later 8 8 License URI: [http://www.gnu.org/licenses/gpl-2.0.html](http://www.gnu.org/licenses/gpl-2.0.html) 9 Stable tag: 1. 0.19 Stable tag: 1.1 10 10 11 11 A Wordpress plugin that allows users to disable customers use of coupons on selected products in WooCommerce … … 16 16 17 17 Particularly useful if you have a large number of coupons as saves having to go through each coupon code and update the rules to exclude certain items. 18 18 19 19 20 == Installation == … … 33 34 34 35 - Fixed: Checkbox field status not saving on product page 36 37 = 1.1 = 38 39 - New: Message shows at checkout and cart page to inform user that some or all products in the cart are not eligible for discount 40 - New: Now works with variable products, at parent level
Note: See TracChangeset
for help on using the changeset viewer.