feat: add conditional variable display#590
feat: add conditional variable display#590Soare-Robert-Daniel wants to merge 15 commits intodevelopmentfrom
Conversation
|
Tip You can preview the changes in the Playground Plugin build for 7c74e27 is ready 🛎️!
|
There was a problem hiding this comment.
Pull request overview
Adds “attach PPOM group to specific variations” support so PPOM groups can be conditionally displayed on variable products, with corresponding backend filtering to prevent inactive-group fields/prices from being validated or priced.
Changes:
- Store per-product variation rule maps and expose helper APIs to resolve active PPOM groups per selected variation.
- Update add-to-cart validation, cart item payload handling, and pricing to ignore PPOM fields belonging to inactive variation-restricted groups.
- Add admin UI support (Select2 variation search + save flow) and frontend show/hide behavior, plus unit + E2E coverage.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| woocommerce-product-addon.php | Defines meta key constant used to store variation display rules. |
| src/Support/Helpers.php | Adds variation rule-map storage + filtering helpers for posted payloads. |
| templates/frontend/ppom-fields.php | Emits group wrapper metadata (data-ppom-allowed-variations) for frontend toggling. |
| js/ppom-variation-rules.js | Implements variation-driven group show/hide + input disabling on product pages. |
| src/WooCommerce/Product/ProductHandler.php | Extends validation to be variation-aware and skip inactive-group fields. |
| src/WooCommerce/Cart/CartHandler.php | Filters PPOM cart payload/fees by active variation to prevent stale/inactive data. |
| src/Pricing/Engine.php | Filters posted field list by active variation before pricing rows are built. |
| inc/woocommerce/product.php | Updates WC validation filter wrapper to accept variation context args. |
| inc/woocommerce/cart.php | Updates WC cart-item-data filter wrapper to accept variation/quantity args. |
| classes/plugin.class.php | Updates WooCommerce filter registrations to the new arg counts. |
| classes/frontend-scripts.class.php | Registers/enqueues the new variation rules frontend script. |
| classes/fields.class.php | Adds localized strings/actions needed for variation Select2 search. |
| js/admin/ppom-meta-table.js | Adds Select2 wiring for “attach to variations” in modal + inline UI. |
| classes/admin.class.php | Adds variation search endpoint + attach UI component + save plumbing for variation rules. |
| src/Admin/Manager.php | Persists inline attach selections (including variations) during group create/update. |
| inc/functions.php | Adds public wrapper functions for variation rule helpers. |
| tests/unit/test-variation-attach.php | Unit coverage for rule map storage and payload/validation filtering behavior. |
| tests/e2e/specs/variation-attach.spec.js | E2E coverage ensuring group renders only for allowed variation. |
| tests/e2e/fixtures/ppom.js | Adds fixture helper to attach a PPOM group to variations via bootstrap action. |
| tests/e2e/fixtures/index.js | Re-exports the new variations attach fixture helper. |
| bin/wp-env/mu-plugins/ppom-e2e-bootstrap.php | Adds an E2E bootstrap AJAX action to attach groups to variations. |
| phpcs.baseline.xml | Updates baseline for new/shifted PHPCS findings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function setGroupActive( $group, active ) { | ||
| if ( active ) { | ||
| $group.show().attr( 'aria-hidden', 'false' ); | ||
| setInputsDisabled( $group, false ); | ||
| setConditionHiddenClass( $group, false ); | ||
| $( document ).trigger( 'ppom_field_shown' ); | ||
| } else { | ||
| $group.hide().attr( 'aria-hidden', 'true' ); | ||
| setInputsDisabled( $group, true ); | ||
| setConditionHiddenClass( $group, true ); | ||
| $( document ).trigger( 'ppom_field_hidden' ); | ||
| } |
| array( | ||
| 'results' => $results, | ||
| 'pagination' => array( | ||
| 'more' => '' === $search_term && $page < (int) $query->max_num_pages, |
| $product_ids = get_posts( | ||
| array( | ||
| 'post_type' => 'product', | ||
| 'post_status' => 'publish', | ||
| 'posts_per_page' => -1, | ||
| 'fields' => 'ids', | ||
| 'no_found_rows' => true, | ||
| 'update_post_meta_cache' => false, | ||
| 'update_post_term_cache' => false, | ||
| 'meta_key' => PPOM_VARIATION_META_KEY, | ||
| ) | ||
| ); | ||
|
|
||
| $variation_ids = array(); | ||
| foreach ( $product_ids as $product_id ) { | ||
| $variation_ids = array_merge( | ||
| $variation_ids, | ||
| \PPOM\Support\Helpers::get_variation_ids_for_group( $product_id, $ppom_id ) | ||
| ); | ||
| } | ||
|
|
||
| return array_values( array_unique( array_filter( array_map( 'absint', $variation_ids ) ) ) ); |
|
@Soare-Robert-Daniel, I checked the PR and the variation conditions are working correctly. I have two questions:
I also noticed that if I deactivate the Pro version after adding a variation condition and then remove the parent product from the product list, some field types lose their registered title and data name. This seems like a bug—could you take a look? |
18727a1 to
4e0df9b
Compare
4e0df9b to
1f132f3
Compare
|
@Soare-Robert-Daniel, this issue e stil exists.
I noticed it with the color and font picker fields. Debug log has these entries |


Summary
Will affect visual aspect of the product
YES
Screenshots
Test instructions
Warning
This feature is marked as PRO. You will need to activate the PRO plugin.
Check before Pull Request is ready:
Closes https://github.com/Codeinwp/ppom-pro/issues/512