@@ -19,7 +19,7 @@ public static function init($display)
1919 }
2020
2121 if (get_option (Helper::OPTIONS ['product-points ' ]['handle ' ])) {
22- add_action ('woocommerce_simple_add_to_cart ' , array (__CLASS__ , 'renderProductInfo ' ), 10 , 0 );
22+ add_action ('woocommerce_before_add_to_cart_form ' , array (__CLASS__ , 'renderProductInfo ' ), 10 , 0 );
2323 }
2424
2525 if (get_option (Helper::OPTIONS ['cart-notices ' ]['handle ' ])) {
@@ -120,8 +120,30 @@ public static function renderCartNotice()
120120 $ notice_earn_points = null ;
121121 $ notice_redeem_points = null ;
122122 $ notice_cancel_redemption = null ;
123+ $ redemption_params = self ::$ display ['redemption ' ];
123124
124125 $ cart_subtotal = Helper::getCart ()->cart_contents_total ;
126+
127+ # Customers do not get points when they purchase product in the excluded collections.
128+ # So they need to be removed from the points estimate.
129+ if (!empty ($ redemption_params ["excluded_collection_cms_ids " ])) {
130+ $ amount_to_exclude = 0 ;
131+ $ cart_items = Helper::getCart ()->get_cart ();
132+ foreach ($ cart_items as $ cart_item_key => $ values ) {
133+ $ product = $ values ['data ' ];
134+ if (
135+ is_a ($ product , "WC_Product " ) &&
136+ array_intersect (
137+ $ product ->get_category_ids ('edit ' ),
138+ $ redemption_params ["excluded_collection_cms_ids " ]
139+ )
140+ ) {
141+ $ amount_to_exclude += $ values ['line_subtotal ' ];
142+ }
143+ }
144+ $ cart_subtotal = $ cart_subtotal - $ amount_to_exclude ;
145+ }
146+
125147 $ cart_points = intval ($ cart_subtotal * self ::$ display ['beans_ccy_spent ' ]);
126148
127149 $ account = BeansAccount::getSession ();
0 commit comments