Improved handling of posted field values for clones#564
Merged
Soare-Robert-Daniel merged 2 commits intodevelopmentfrom Apr 14, 2026
Merged
Improved handling of posted field values for clones#564Soare-Robert-Daniel merged 2 commits intodevelopmentfrom
Soare-Robert-Daniel merged 2 commits intodevelopmentfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates server-side validation to better account for repeated (“cloned”) field instances when adding products to the cart, addressing issue #504.
Changes:
- Update
ppom_has_posted_field_value()to evaluate posted values across cloned field instances rather than stopping at the first match. - Align clone key parsing in max/min checked validation by switching the split token to
__clone_.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+980
to
1016
| // Every instance (the original field AND every clone) must have a value. | ||
| $has_value = true; | ||
| foreach ( $matching_keys as $instance_value ) { | ||
|
|
||
| if ( $quantity > 0 ) { | ||
| $has_value = true; | ||
| } | ||
| $instance_has_value = false; | ||
|
|
||
| break; | ||
|
|
||
| case 'fonts': | ||
| if ( isset( $value['font'] ) && $value['font'] != '' ) { | ||
| $has_value = true; | ||
| } | ||
| switch ( $type ) { | ||
|
|
||
| break; | ||
| case 'quantities': | ||
| $quantity = 0; | ||
| foreach ( (array) $instance_value as $qty ) { | ||
| $quantity += intval( $qty ); | ||
| } | ||
| if ( $quantity > 0 ) { | ||
| $instance_has_value = true; | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| if ( $value != '' ) { | ||
| $has_value = true; | ||
| } | ||
| break; | ||
| case 'fonts': | ||
| if ( isset( $instance_value['font'] ) && '' !== $instance_value['font'] ) { | ||
| $instance_has_value = true; | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| if ( '' !== $instance_value ) { | ||
| $instance_has_value = true; | ||
| } | ||
| break; | ||
|
|
||
| } | ||
|
|
||
| if ( $has_value ) { | ||
| break; | ||
| } | ||
| } | ||
| if ( ! $instance_has_value ) { | ||
| $has_value = false; | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
This change alters required-field validation semantics for cloned fields (now requiring all instances to have values). Given validation is a core path, please add/update PHPUnit coverage for ppom_has_posted_field_value() with at least one cloned-field case (including a failing clone instance) to prevent regressions.
Soare-Robert-Daniel
approved these changes
Apr 14, 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
Checked the value for all the clone fields to validate them while adding the product to the cart.
Check before Pull Request is ready:
Closes https://github.com/Codeinwp/ppom-pro/issues/504