Skip to content

Conversation

faisal-alvi
Copy link
Collaborator

All Submissions:

  • Does your code follow the WooCommerce Sniffs variant of WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Will this change require new documentation or changes to existing documentation?

Changes proposed in this Pull Request:

This PR fixes a critical issue where the Square plugin's filter_order_item_totals function causes fatal errors when generating PDF credit notes with third-party PDF invoice plugins.

The filter_order_item_totals function assumes the $order parameter is always a WC_Order object and calls $order->get_payment_method() without validation. However, when generating credit notes, PDF plugins pass a WC_Order_Refund object, which doesn't have the get_payment_method() method, causing a fatal error.

Closes https://linear.app/a8c/issue/SQUARE-180/square-plugin-crashes-pdf-credit-note-generation-for-3pd-plugin.

Steps to test the changes in this Pull Request:

I wasn’t able to reproduce the issue myself, but the fix is straightforward and non-harmful. Here are the steps that may help reproduce the issue and confirm the fix.

  1. Setup Test Environment:

    • Active WooCommerce Square plugin
    • Install a third-party PDF plugin (e.g., PDF Invoices & Packing Slips for WooCommerce)
    • Create a test order with Square payment method
  2. Test Regular PDF Generation:

    • Generate a PDF invoice for the test order
    • Verify the PDF generates successfully

Changelog entry

Fix - Prevent fatal error when generating PDF credit notes with third-party PDF plugins by adding type check for WC_Order objects in filter_order_item_totals function.

@faisal-alvi faisal-alvi self-assigned this Sep 25, 2025
@vikrampm1 vikrampm1 requested a review from dkotter September 29, 2025 15:16
@qasumitbagthariya
Copy link
Collaborator

QA Update - Need Feedback ⚠️


Hello @dkotter

I tested this from my end and I’m not able to reproduce the issue.

PDF Invoices & Packing Slips for WooCommerce

Screen.Recording.2025-10-03.at.11.37.25.PM.mov

Testing Environment

  • WordPress: 6.8.3
  • Theme: Twenty Twenty-Five 1.3
  • WooCommerce - 10.2.2
  • PDF Invoices & Packing Slips for WooCommerce - 4.7.0
  • PHP: 8.0.30
  • Web Server: Nginx 1.20.2
  • Browser: Chrome
  • OS: macOS 15.2
  • Branch: trunk

@dkotter
Copy link
Collaborator

dkotter commented Oct 6, 2025

I tested this from my end and I’m not able to reproduce the issue.

Looks like Faisal also wasn't able to reproduce this. Looking at the code change, I don't have any concern with us shipping this though also fine to close this out if we think that's best; cc: @jeffpaul @vikrampm1

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants