Skip to content

feat: add conditional variable display#590

Open
Soare-Robert-Daniel wants to merge 15 commits intodevelopmentfrom
feat/variation-product-attach
Open

feat: add conditional variable display#590
Soare-Robert-Daniel wants to merge 15 commits intodevelopmentfrom
feat/variation-product-attach

Conversation

@Soare-Robert-Daniel
Copy link
Copy Markdown
Contributor

Summary

Will affect visual aspect of the product

YES

Screenshots

CleanShot 2026-04-27 at 16 22 22@2x

Test instructions

Warning

This feature is marked as PRO. You will need to activate the PRO plugin.

  • Create a variable product & PPOM field group.
  • Test if you can attach the PPOM field group to a single variation of the variable product.
  • Test the purchase workflow to see if it works like the others (tags, categories, etc).
CleanShot 2026-04-27 at 15 45 56@2x CleanShot 2026-04-27 at 15 46 03@2x CleanShot 2026-04-27 at 15 47 58@2x

Check before Pull Request is ready:

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

@Soare-Robert-Daniel Soare-Robert-Daniel self-assigned this Apr 27, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Apr 27, 2026
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Apr 27, 2026

Tip

You can preview the changes in the Playground

Plugin build for 7c74e27 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

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.

Comment on lines +86 to +97
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' );
}
Comment thread classes/admin.class.php Outdated
array(
'results' => $results,
'pagination' => array(
'more' => '' === $search_term && $page < (int) $query->max_num_pages,
Comment thread classes/admin.class.php
Comment on lines +732 to +753
$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 Soare-Robert-Daniel changed the title feat: add conditional veriation display feat: add conditional variable display Apr 28, 2026
@poonam279
Copy link
Copy Markdown

poonam279 commented May 1, 2026

@Soare-Robert-Daniel, I checked the PR and the variation conditions are working correctly. I have two questions:

  1. Selecting a variation also attaches this group to its parent product, but removing all variations does not auto-detach the product. This might surprise merchants who expect the fields to disappear from the product once all variation restrictions are cleared. Is this expected behavior?

  2. When I type a keyword to search for a product, category, or variation, the keyword remains visible even after selection. Can we clear it after an item is selected?

Markup 2026-05-02 at 03 42 51

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?
Markup 2026-05-02 at 04 37 55
The error in debug log is [01-May-2026 23:01:07 UTC] PHP Warning: Undefined array key "title" in /s3-puzzledturkey/wordpress/wp-content/plugins/woocommerce-product-addon/src/Hooks/Callbacks.php on line 655

@Soare-Robert-Daniel Soare-Robert-Daniel changed the base branch from feat/search-products to development May 4, 2026 13:43
@Soare-Robert-Daniel Soare-Robert-Daniel force-pushed the feat/variation-product-attach branch from 18727a1 to 4e0df9b Compare May 4, 2026 13:48
@Soare-Robert-Daniel Soare-Robert-Daniel force-pushed the feat/variation-product-attach branch from 4e0df9b to 1f132f3 Compare May 4, 2026 14:02
@poonam279
Copy link
Copy Markdown

@Soare-Robert-Daniel, this issue e stil exists.

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?

I noticed it with the color and font picker fields.

Debug log has these entries

[04-May-2026 15:32:22 UTC] PHP Warning:  Undefined array key "visibility" in /s3-puzzledturkey/wordpress/wp-content/plugins/woocommerce-product-addon/classes/fields.class.php on line 961
[04-May-2026 15:32:22 UTC] PHP Warning:  Undefined array key "bound" in /s3-puzzledturkey/wordpress/wp-content/plugins/woocommerce-product-addon/classes/fields.class.php on line 963
[04-May-2026 15:47:30 UTC] PHP Warning:  Undefined array key "visibility" in /s3-puzzledturkey/wordpress/wp-content/plugins/woocommerce-product-addon/classes/fields.class.php on line 961
[04-May-2026 15:47:30 UTC] PHP Warning:  Undefined array key "bound" in /s3-puzzledturkey/wordpress/wp-content/plugins/woocommerce-product-addon/classes/fields.class.php on line 963
[04-May-2026 15:49:55 UTC] PHP Warning:  Undefined array key "visibility" in /s3-puzzledturkey/wordpress/wp-content/plugins/woocommerce-product-addon/classes/fields.class.php on line 961
[04-May-2026 15:49:55 UTC] PHP Warning:  Undefined array key "bound" in /s3-puzzledturkey/wordpress/wp-content/plugins/woocommerce-product-addon/classes/fields.class.php on line 963

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants