diff --git a/plugins/woocommerce/changelog/45791-tweak-45790 b/plugins/woocommerce/changelog/45791-tweak-45790 new file mode 100644 index 00000000000..4304e135d98 --- /dev/null +++ b/plugins/woocommerce/changelog/45791-tweak-45790 @@ -0,0 +1,4 @@ +Significance: minor +Type: tweak + +WC_Discount: Add a filter for the items to apply coupons array. \ No newline at end of file diff --git a/plugins/woocommerce/includes/class-wc-discounts.php b/plugins/woocommerce/includes/class-wc-discounts.php index 0bf8f974608..9fa1c5dad5e 100644 --- a/plugins/woocommerce/includes/class-wc-discounts.php +++ b/plugins/woocommerce/includes/class-wc-discounts.php @@ -333,7 +333,20 @@ class WC_Discounts { $items_to_apply[] = $item_to_apply; } - return $items_to_apply; + + /** + * Filters the items that a coupon should be applied to. + * + * This filter allows you to modify the items that a coupon will be applied to before the discount calculations take place. + * + * @since 8.8.0 + * @param array $items_to_apply The items that the coupon will be applied to. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $this The discounts instance. + * + * @return array The modified list of items that the coupon should be applied to. + */ + return apply_filters( 'woocommerce_coupon_get_items_to_apply', $items_to_apply, $coupon, $this ); } /**