feat: add discounted price mapping field#61
Draft
evrpress wants to merge 4 commits into
Draft
Conversation
Adds a "Discounted price" mapping option for paragraph, heading, and button blocks that applies the scope coupon discount to the current plan price.
Fetches coupon metadata from the Freemius API (`products/{id}/coupons.json?code=...`) in the block editor via a new `useCoupon` hook, and embeds coupon discount data in page output for frontend modifier updates. Shared JS/PHP helpers apply percentage or fixed-amount discounts (including multi-currency `discounts`). When no coupon is configured in scope, the field shows an editor error and renders empty on the frontend. Main files: `src/hooks/useMapping.js`, `src/scope/MappingSettings.js`, `src/blocks/modifier/view.js`, `includes/class-freemius-scope.php`, new `src/util/discountedPrice.js`.
Site owners can now display coupon-adjusted prices alongside regular pricing blocks without duplicating amounts manually.
Updated the `applies_to_plan` method in the Coupon class to utilize a new `normalize_plan_ids` method for improved handling of plan restrictions. This change allows for better normalization of plan IDs from various input formats. Additionally, the JavaScript utility function `normalizePlanIds` was added to mirror this functionality on the client side. New tests were introduced to ensure correct behavior when plans are provided as an array. This refactor improves code maintainability and consistency across PHP and JavaScript implementations.
4 tasks
Keep Cursor config in a local nested repo under .cursor/ and ignore it in the plugin repository so it is not pushed to origin. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a "Discounted price" mapping option for paragraph, heading, and button blocks that applies the scope coupon discount to the current plan price.
Fetches coupon metadata from the Freemius API (
products/{id}/coupons.json?code=...) in the block editor via a newuseCouponhook, and embeds coupon discount data in page output for frontend modifier updates. Shared JS/PHP helpers apply percentage or fixed-amount discounts (including multi-currencydiscounts). When no coupon is configured in scope, the field shows an editor error and renders empty on the frontend. Main files:src/hooks/useMapping.js,src/scope/MappingSettings.js,src/blocks/modifier/view.js,includes/class-freemius-scope.php, newsrc/util/discountedPrice.js.Site owners can now display coupon-adjusted prices alongside regular pricing blocks without duplicating amounts manually.