Skip to content

Conversation

@mabfahad
Copy link

@mabfahad mabfahad commented Sep 3, 2025

Summary

Fixes a fatal error in Mailchimp for WooCommerce when updating or deleting products. WordPress can pass null for $post_after or $post_before in the post_updated hook, but the function signature required WP_Post, causing a TypeError.

Fix

  • Updated method signature to accept nullable parameters:

public function handleProductUpdated( int $post_ID, ?WP_Post $post_after, ?WP_Post $post_before )

  • Added safeguard inside the function:
if ( ! $post_after instanceof WP_Post ) {
    return;
}

Testing

  • Product updates and deletions no longer trigger fatal errors.
  • Tested on WordPress 6.x, WooCommerce latest, PHP 8.1/8.2

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