mailchimp / mc-woocommerce

MailChimp for Woocommerce Integration. Syncs all data (subscriber, customers, orders, products) and enables marketing automation with email campaigns, automations, ads, postcards and more.
https://wordpress.org/plugins/mailchimp-for-woocommerce/
GNU General Public License v2.0
82 stars 66 forks source link

[BUG] Uncaught Error: Call to a member function deleteStoreProduct() on bool #1135

Closed tomkowa64 closed 6 months ago

tomkowa64 commented 7 months ago

Describe the bug

Uncaught Error: Call to a member function deleteStoreProduct() on bool in C:\wamp64\www\wordpress\wp-content\plugins\mailchimp-for-woocommerce\includes\class-mailchimp-woocommerce-service.php

When i try to delete variation of my woocommerce product, the delete proccess gets stuck (only on frontend). I debugged it a bit on my localhost clean enviroment and came to the conclusion that it is casused due to the not configured plugin. I maintain one of client website and looks like someone of previous devs installed this plugin and never used it. Kinda rare use case but i guess it'd be nice to fix it.

To Reproduce

  1. Get yourself clean wordpress instance and install MC for woocommerce
  2. DO NOT CONFIGURE THE PLUGIN
  3. Try to delete variation of a product.

Expected behavior Product variation gets deleted (on frontend), and no fatal error.

Operating environment (please complete the following information):

Suggested fix for class-mailchimp-woocommerce-service.php:

public function handleDeleteProductVariation($variation_id) {
    try {
        // Do not call `->deleteStoreProduct(mailchimp_get_store_id(), $variation_id)` on false
        if (!mailchimp_is_configured()) return;

        $deleted = mailchimp_get_api()->deleteStoreProduct(mailchimp_get_store_id(), $variation_id);
        if ($deleted) mailchimp_log('product.deleted', "deleted product variation {$variation_id}");
        else mailchimp_log('product.delete_fail', "Unable to deleted product variation {$variation_id}");
    } catch (Exception $e) {
        mailchimp_error('delete product variation', $e->getMessage());
    }
}
ryanhungate commented 7 months ago

@tomkowa64 thanks - yeah that's not a problem at all. We'll patch this up in our current iteration. Super quick and easy 👍

ryanhungate commented 6 months ago

@tomkowa64 this is patched in the latest release 4.0 that just went out today. Let us know if you're still facing that same issue after upgrade.