Make compatible with multicurrency plugins#522
Open
girishpanchal30 wants to merge 2 commits intodevelopmentfrom
Open
Make compatible with multicurrency plugins#522girishpanchal30 wants to merge 2 commits intodevelopmentfrom
girishpanchal30 wants to merge 2 commits intodevelopmentfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new ppom_option_price filter and applies it across PPOM option-price rendering/calculation paths to improve compatibility with multi-currency plugins (per issue #553).
Changes:
- Added
apply_filters( 'ppom_option_price', ... )in multiple templates and pricing helpers before displaying/storing option prices. - Registered a new
ppom_option_pricehandler (ppom_convert_price) to convert amounts via common multi-currency plugin hooks/functions. - Updated cart/mini-cart display paths to use the filtered prices and adjusted the PHPStan baseline accordingly.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
classes/plugin.class.php |
Registers ppom_option_price and implements ppom_convert_price() multi-currency conversion logic. |
templates/render-fields.php |
Filters file/cropper file_cost before label wc_price() formatting. |
templates/input/quantities.php |
Filters quantity option prices before display and data attributes. |
templates/frontend/inputs/*.php |
Filters per-input option prices (text, number, select, radio, checkbox, image, file, etc.). |
templates/frontend/component/quantities/*-layout.php |
Filters quantity layout prices before use. |
inc/woocommerce.php |
Filters fees/meta/cart display prices (mini-cart fixed fee, cart item meta, matrix “least price”). |
inc/prices.php |
Filters generated field price before wc_price() label construction. |
inc/nmInput.class.php |
Filters prices in legacy HTML builder paths (select/checkbox/radio/image/pricematrix/etc.). |
classes/inputs/input.measure.php |
Filters measure option price before formatting. |
phpstan-baseline.neon |
Removes a baseline entry related to wc_price() string/float typing. |
Comments suppressed due to low confidence (3)
templates/frontend/inputs/image.php:72
- In the image input, ppom_option_price is applied to $image_price before the “price set in %” branch recalculates the amount. If the stored price is a percent string (e.g., '10%'), the conversion callback may coerce it to a numeric value, and the filter work is also discarded immediately after when $image_price is overwritten. Apply the currency conversion after the percent-to-amount calculation (and only for numeric amounts) to avoid incorrect coercion and double-work.
$image_price = isset( $image['price'] ) ? $image['price'] : 0;
$option_id = $fm->data_name() . '-' . $image_id;
$opt_percent = isset( $value['percent'] ) ? $value['percent'] : '';
$image_price = apply_filters( 'ppom_option_price', $image_price );
// If price set in %
if ( strpos( $image['price'], '%' ) !== false ) {
$image_price = ppom_get_amount_after_percentage( $product->get_price(), $image['price'] );
}
inc/nmInput.class.php:1065
- Same issue as the legacy-view branch above: ppom_option_price is applied to $image_price before checking for a percentage price and recalculating it. To avoid coercing percent strings and to ensure the conversion applies to the final numeric amount, move the filter call to after the percent-to-amount calculation (and guard it with an is_numeric check).
$image_title = isset( $image['raw'] ) ? stripslashes( $image['raw'] ) : '';
$image_label = isset( $image['label'] ) ? stripslashes( $image['label'] ) : '';
$image_price = isset( $image['price'] ) ? $image['price'] : 0;
$image_price = apply_filters( 'ppom_option_price', $image_price );
$option_id = $id . '-' . $image_id;
// If price set in %
if ( strpos( $image['price'], '%' ) !== false ) {
$image_price = ppom_get_amount_after_percentage( $product->get_price(), $image['price'] );
}
inc/nmInput.class.php:969
- ppom_option_price is applied to $image_price before the percentage-price branch in the legacy view. If $image['price'] is a percent string, a converter that casts to float will coerce it (e.g. '10%' -> 10) and the conversion is then overwritten by the percent-to-amount calculation. Apply the filter after the percentage amount is computed (and only for numeric values).
$image_full = isset( $image['link'] ) ? $image['link'] : 0;
$image_id = isset( $image['image_id'] ) ? $image['image_id'] : 0;
$image_title = isset( $image['raw'] ) ? stripslashes( $image['raw'] ) : '';
$image_label = isset( $image['label'] ) ? stripslashes( $image['label'] ) : '';
$image_price = isset( $image['price'] ) ? $image['price'] : 0;
$image_price = apply_filters( 'ppom_option_price', $image_price );
$option_id = $id . '-' . $image_id;
// If price set in %
if ( strpos( $image['price'], '%' ) !== false ) {
$image_price = ppom_get_amount_after_percentage( $product->get_price(), $image['price'] );
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
classes/plugin.class.php
Outdated
Comment on lines
+1078
to
+1094
| * @param float $price The price to convert. | ||
| * @return float The converted price. | ||
| */ | ||
| public function ppom_convert_price( $price ) { | ||
| // WCML. | ||
| if ( has_filter( 'wcml_raw_price_amount' ) ) { | ||
| return apply_filters( 'wcml_raw_price_amount', (float) $price ); | ||
| } | ||
|
|
||
| // FOX - Currency Switcher. | ||
| if ( has_filter( 'woocs_exchange_value' ) ) { | ||
| return apply_filters( 'woocs_exchange_value', (float) $price ); | ||
| } | ||
|
|
||
| // CURCY - WooCommerce Multi Currency. | ||
| if ( function_exists( 'wmc_get_price' ) ) { | ||
| return wmc_get_price( (float) $price ); |
Soare-Robert-Daniel
approved these changes
Mar 17, 2026
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.
Summary
Added filter
ppom_option_priceto convert the currency value.Check before Pull Request is ready:
Closes https://github.com/Codeinwp/ppom-pro/issues/553