fix(emails): clarify free checkout notifications#1673
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughPayment success events now include derived payment states and email-specific subjects and intros. Sender supports conditional template blocks, and admin/customer payment emails render separate paid, free-signup, and trial content. ChangesPayment Email Flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Payment_Manager
participant wu_do_event
participant Email_Manager
participant Sender
participant Payment_Templates
Payment_Manager->>Payment_Manager: derive payment and membership state
Payment_Manager->>wu_do_event: emit payment_received payload
wu_do_event->>Email_Manager: deliver payload
Email_Manager->>Sender: process subject and template shortcodes
Sender->>Payment_Templates: render state-specific sections
Payment_Templates-->>Email_Manager: rendered payment email
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🔨 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! Login credentials: |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
inc/helpers/class-sender.php (1)
239-257: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winConditional blocks aren't stripped when payload is empty.
The early return at Line 241-243 runs before the new conditional-block preprocessing, so calling
process_shortcodes()with an empty payload leaves raw{{#key}}...{{/key}}markers (and their inner content) in the output instead of stripping them.🐛 Proposed fix
public static function process_shortcodes($content, $payload = []) { - if (empty($payload)) { - return $content; - } - /* * Allow templates to include a block only when the matching payload * value is truthy. This keeps a single transactional email template * useful for related outcomes, such as paid checkouts and free trials. */ $content = preg_replace_callback( '/{{#([a-zA-Z0-9_]+)}}(.*?){{\/\1}}/s', function ($matches) use ($payload) { return ! empty($payload[ $matches[1] ]) ? $matches[2] : ''; }, $content ); + if (empty($payload)) { + return $content; + } + $match = [];🤖 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 `@inc/helpers/class-sender.php` around lines 239 - 257, Update process_shortcodes so conditional-block preprocessing runs before any empty-payload return. Ensure empty payloads strip every {{`#key`}}...{{/key}} block and its contents, while preserving the existing truthy-payload behavior that retains matching block content.inc/managers/class-email-manager.php (1)
164-172: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winCompare against the rendered email subject when attaching invoice PDFs.
Sender::send_mail()replaces shortcodes in$args['subject']beforewp_mail(), so PHPMailer receives the interpolated subject.attach_invoice_pdf()comparesphpmailer_init’s$mail->Subjectagainst the raw template subject, so these payment emails miss their invoice attachments:$args['subject'] = 'Site - {{payment_email_admin_subject}}'runs the replacement, but the registered payload includes
payment_email_admin_subject => 'Payment received: ...'. Forpayment_received_admin/payment_received_customer, register the attachment with the same processed subject:🐛 Proposed fix
if ($invoice_payment) { $file_name = 'invoice-' . $invoice_payment->get_hash() . '.pdf'; - $this->attach_invoice_pdf($invoice_payment, $file_name, $args['subject']); + $this->attach_invoice_pdf($invoice_payment, $file_name, Sender::process_shortcodes($args['subject'], $payload)); }🤖 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 `@inc/managers/class-email-manager.php` around lines 164 - 172, Update the payment invoice attachment flow around attach_invoice_pdf() so payment_received_admin and payment_received_customer register the attachment using the subject after Sender::send_mail() shortcode replacement, matching PHPMailer’s rendered mail Subject rather than the raw $args['subject'] template. Preserve the existing invoice lookup, filename, and paid-status conditions.
🤖 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 `@inc/managers/class-payment-manager.php`:
- Around line 130-215: Guard all customer_name and payment_product_names reads
in the payment email subject and intro branches within the payment
payload-building method. Reuse the codebase’s defensive wu_get_isset() pattern,
supplying appropriate empty fallbacks when these payload keys are absent, while
preserving the existing paid, trial, and free-membership messaging behavior.
---
Outside diff comments:
In `@inc/helpers/class-sender.php`:
- Around line 239-257: Update process_shortcodes so conditional-block
preprocessing runs before any empty-payload return. Ensure empty payloads strip
every {{`#key`}}...{{/key}} block and its contents, while preserving the existing
truthy-payload behavior that retains matching block content.
In `@inc/managers/class-email-manager.php`:
- Around line 164-172: Update the payment invoice attachment flow around
attach_invoice_pdf() so payment_received_admin and payment_received_customer
register the attachment using the subject after Sender::send_mail() shortcode
replacement, matching PHPMailer’s rendered mail Subject rather than the raw
$args['subject'] template. Preserve the existing invoice lookup, filename, and
paid-status conditions.
🪄 Autofix (Beta)
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: 2defad8f-ce23-4ca8-b821-447c682017af
📒 Files selected for processing (7)
inc/helpers/class-sender.phpinc/managers/class-email-manager.phpinc/managers/class-payment-manager.phptests/WP_Ultimo/Helpers/Sender_Test.phptests/WP_Ultimo/Managers/Email_Manager_Test.phpviews/emails/admin/payment-received.phpviews/emails/customer/payment-received.php
🔨 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! Login credentials: |
Summary
Verification
aidevops.sh v3.32.180 plugin for OpenCode v1.18.4 Merged via PR #1673 to main. |
Summary
Verification
vendor/bin/phpcs inc/helpers/class-sender.php inc/managers/class-payment-manager.php inc/managers/class-email-manager.php views/emails/customer/payment-received.php views/emails/admin/payment-received.php tests/WP_Ultimo/Helpers/Sender_Test.php tests/WP_Ultimo/Managers/Email_Manager_Test.phpvendor/bin/phpstan analyse inc/helpers/class-sender.php inc/managers/class-email-manager.php inc/managers/class-payment-manager.phpvendor/bin/phpunit --filter 'Sender_Test|Email_Manager_Test|Payment_Manager_Test'aidevops.sh v3.32.180 plugin for OpenCode v1.18.4
Summary by CodeRabbit