Skip to content

Resolve checkout level so level-restricted field groups show on signup form#74

Open
dwanjuki wants to merge 1 commit into
strangerstudios:devfrom
dwanjuki:fix/level-restricted-field-groups
Open

Resolve checkout level so level-restricted field groups show on signup form#74
dwanjuki wants to merge 1 commit into
strangerstudios:devfrom
dwanjuki:fix/level-restricted-field-groups

Conversation

@dwanjuki

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

When the Signup Shortcode renders a form for a level, User Field groups that are restricted to that level were not appearing, even though they appear on the level's normal checkout page.

The cause is that PMPro resolves which field groups to display via pmpro_getLevelAtCheckout() (used by PMPro_Field_Group::get_fields_to_display() and the legacy pmpro_checkout_boxes_fields()). That function ignores the $pmpro_level global the shortcode sets and instead reads the level from the request — $_REQUEST['pmpro_level'], then the legacy $_REQUEST['level'], then the post's default-level meta, then the lowest level ID.

On a signup shortcode page, there is no level in the request, so it fell back to the default/lowest level and any group restricted to a different level was filtered out.

This PR populates $_REQUEST['pmpro_level'] with the shortcode's level before the pmpro_checkout_preheader and field hooks fire, so field group resolution matches the rest of the form (hidden level input, title, cost). It is set in single level mode only; multi level mode already disables custom_fields.

How to test the changes in this Pull Request:

  1. Under Memberships > Settings > User Fields, create a field group with one or more fields and restrict it to a specific level that is not the lowest/default level.
  2. Place [pmpro_signup level="X"] on a page, where X is that restricted level, and view the page — the restricted group's fields now appear.
  3. Place [pmpro_signup level="Y"] for a different level Y and confirm the group does not appear (the restriction is still enforced, not always-on).
  4. Submit the form and confirm the field values save correctly to the member.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run tests with your changes locally?

Changelog entry

BUG FIX: Fixed level-restricted User Field groups not displaying on signup forms.

…p form

PMPro filters restricted user-field groups against pmpro_getLevelAtCheckout(),
which derives the level from the request (not the $pmpro_level global). On a
signup-shortcode page there was no level in the request, so it fell back to the
default/lowest level and level-restricted field groups were filtered out.

Set $_REQUEST['pmpro_level'] to the shortcode's level before the checkout hooks
fire so field-group resolution matches the form.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant