Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a filter for the items to apply coupons array. #45791

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/45791-tweak-45790
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: tweak

WC_Discount: Add a filter for the items to apply coupons array.
15 changes: 14 additions & 1 deletion plugins/woocommerce/includes/class-wc-discounts.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check notice on line 1 in plugins/woocommerce/includes/class-wc-discounts.php

View workflow job for this annotation

GitHub Actions / Analyze Branch Changes

new filter found - woocommerce_coupon_get_items_to_apply

\'woocommerce_coupon_get_items_to_apply\' introduced in 8.8.0
/**
* Discount calculation
*
Expand Down Expand Up @@ -333,7 +333,20 @@

$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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @budzanowski . I added the missing docbloc here: ace39fa

}

/**
Expand Down