Skip to content

feat: support custom plans in membership renewals - #1693

Merged
superdav42 merged 1 commit into
mainfrom
fix/custom-plan-membership-swap-workspace
Aug 5, 2026
Merged

feat: support custom plans in membership renewals#1693
superdav42 merged 1 commit into
mainfrom
fix/custom-plan-membership-swap-workspace

Conversation

@superdav42

@superdav42 superdav42 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a pre-totals renewal payment extension point for auditable metered line items
  • allow membership swaps to registered custom product types such as hosted networks
  • cover renewal previews and custom-plan swaps

Verification

  • vendor/bin/phpunit --filter 'test_membership_create_new_payment_exposes_pre_totals_action|test_swap_replaces_plan_for_registered_custom_plan_type'
  • pre-commit PHPCS and PHPStan

Dependency context

This is the core prerequisite for the companion Metered Plans hosted active-site billing change.


aidevops.sh v3.32.226 plugin for OpenCode v1.18.9 with gpt-5.6-sol

Summary by CodeRabbit

  • New Features

    • Added an extension point for adjusting membership payment details before totals are calculated.
    • Custom plan types are now recognized correctly when switching membership plans.
  • Bug Fixes

    • Improved plan replacement behavior for memberships using registered custom plan types.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The changes add a pre-total payment action and update membership swaps to recognize custom registered plan product types. Tests cover payment line-item injection, hook flags, custom plan replacement, and addon exclusion.

Changes

Membership behavior updates

Layer / File(s) Summary
Pre-total payment hook
inc/functions/membership.php, tests/WP_Ultimo/Functions/Membership_Functions_Test.php
wu_membership_create_new_payment fires wu_membership_new_payment_pre_totals before totals are recalculated. The test verifies callback flags, an injected fee, and the resulting total.
Custom plan type swap
inc/models/class-membership.php, tests/WP_Ultimo/Models/Membership_Test.php
Membership::swap() uses wu_is_plan_type() to identify custom plan types. The test verifies plan replacement and excludes the product from addon IDs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant wu_membership_create_new_payment
  participant HookListener
  participant PaymentTotals
  wu_membership_create_new_payment->>HookListener: fire wu_membership_new_payment_pre_totals
  HookListener->>wu_membership_create_new_payment: modify unsaved payment
  wu_membership_create_new_payment->>PaymentTotals: recalculate totals
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: supporting custom plans in membership renewals.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/custom-plan-membership-swap-workspace

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Performance Test Results

Performance test results for 3360125 are in 🛎️!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/WP_Ultimo/Models/Membership_Test.php`:
- Around line 1094-1110: Replace the manual Product construction,
skip-validation call, and save in the network product fixture with the
`wu_create_product()` helper, preserving the existing network product
attributes. Assert that the helper result is not a `WP_Error` before using it to
create the cart.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5668977d-f8d7-436c-b5ec-2d4d78a12e8e

📥 Commits

Reviewing files that changed from the base of the PR and between f5ae9b2 and 8f89d56.

📒 Files selected for processing (4)
  • inc/functions/membership.php
  • inc/models/class-membership.php
  • tests/WP_Ultimo/Functions/Membership_Functions_Test.php
  • tests/WP_Ultimo/Models/Membership_Test.php

Comment on lines +1094 to +1110
$network_product = new Product(
[
'name' => 'Network Plan',
'slug' => 'network-plan-' . wp_generate_password(6, false),
'description' => 'A custom plan type registered by an addon',
'pricing_type' => 'paid',
'amount' => 49.00,
'currency' => 'USD',
'duration' => 1,
'duration_unit' => 'month',
'type' => 'network',
'recurring' => true,
'active' => true,
]
);
$network_product->set_skip_validation(true);
$network_product->save();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use wu_create_product() for the product fixture.

The test rules require wu_create_*() helpers for test data. Assert that the helper does not return WP_Error before creating the cart.

Proposed fix
-		$network_product = new Product(
-			[
+		$network_product = wu_create_product(
+			[
 				'name'          => 'Network Plan',
 				'slug'          => 'network-plan-' . wp_generate_password(6, false),
 				'description'   => 'A custom plan type registered by an addon',
@@
 				'active'        => true,
+				'skip_validation' => true,
 			]
 		);
-		$network_product->set_skip_validation(true);
-		$network_product->save();
+		$this->assertNotWPError($network_product);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$network_product = new Product(
[
'name' => 'Network Plan',
'slug' => 'network-plan-' . wp_generate_password(6, false),
'description' => 'A custom plan type registered by an addon',
'pricing_type' => 'paid',
'amount' => 49.00,
'currency' => 'USD',
'duration' => 1,
'duration_unit' => 'month',
'type' => 'network',
'recurring' => true,
'active' => true,
]
);
$network_product->set_skip_validation(true);
$network_product->save();
$network_product = wu_create_product(
[
'name' => 'Network Plan',
'slug' => 'network-plan-' . wp_generate_password(6, false),
'description' => 'A custom plan type registered by an addon',
'pricing_type' => 'paid',
'amount' => 49.00,
'currency' => 'USD',
'duration' => 1,
'duration_unit' => 'month',
'type' => 'network',
'recurring' => true,
'active' => true,
'skip_validation' => true,
]
);
$this->assertNotWPError($network_product);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WP_Ultimo/Models/Membership_Test.php` around lines 1094 - 1110, Replace
the manual Product construction, skip-validation call, and save in the network
product fixture with the `wu_create_product()` helper, preserving the existing
network product attributes. Assert that the helper result is not a `WP_Error`
before using it to create the cart.

Source: Coding guidelines

@superdav42
superdav42 merged commit 6fffbf6 into main Aug 5, 2026
11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

DISPATCH_CLAIM nonce=0f021b62f6c974caa1c92766fd165b16 runner=superdav42 ts=2026-08-05T17:34:19Z max_age_s=120 version=3.32.226 opencode_version=1.18.9 lease_token=0f021b62f6c974caa1c92766fd165b16 device=device-1783824528-2609248-26808 session=issue-1693 phase=prelaunch expires_at=1785951381

@superdav42

Copy link
Copy Markdown
Collaborator Author

REVIEW_FOLLOWUP_CREATED source_pr=1693 issue=1694 fingerprint=source-pr-1693 runner=superdav42 ts=2026-08-05T17:34:41Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant