Skip to content

Make compatible with multicurrency plugins#522

Open
girishpanchal30 wants to merge 2 commits intodevelopmentfrom
bugfix/pro/553
Open

Make compatible with multicurrency plugins#522
girishpanchal30 wants to merge 2 commits intodevelopmentfrom
bugfix/pro/553

Conversation

@girishpanchal30
Copy link
Copy Markdown
Contributor

Summary

Added filter ppom_option_price to convert the currency value.

Check before Pull Request is ready:

Closes https://github.com/Codeinwp/ppom-pro/issues/553

@girishpanchal30 girishpanchal30 requested a review from Copilot March 16, 2026 12:32
@girishpanchal30 girishpanchal30 added the pr-checklist-skip Allow this Pull Request to skip checklist. label Mar 16, 2026
@pirate-bot pirate-bot added pr-checklist-complete The Pull Request checklist is complete. (automatic label) labels Mar 16, 2026
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Mar 16, 2026

Plugin build for dcf7544 is ready 🛎️!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_price handler (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.

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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants