When loading the Marketing -> Overview section, there is a request to fetch the campaigns, but it currently fails because the campaign types are not loaded. The campaign types are only loaded if the filter woocommerce_gla_enable_mcm returns true.
The fatal error is the below:
undefined array key "google-ads" in /opt/homebrew/var/www/wp-content/plugins/google-listings-and-ads/src/MultichannelMarketing/GLAChannel.php on line 195, referer: https://civet-pleasing-internally.ngrok-free.app/wp-admin/admin.php?page=wc-admin&path=%2Fmarketing
[Thu Jun 06 16:19:22.787147 2024] [php:error] [pid 2819] [client ::1:56339] PHP Fatal error: Uncaught TypeError: Automattic\\WooCommerce\\Admin\\Marketing\\MarketingCampaign::__construct(): Argument #2 ($type) must be of type Automattic\\WooCommerce\\Admin\\Marketing\\MarketingCampaignType, null given, called in /opt/homebrew/var/www/wp-content/plugins/google-listings-and-ads/src/MultichannelMarketing/GLAChannel.php on line 194 and defined in /opt/homebrew/var/www/wp-content/plugins/woocommerce-dev/plugins/woocommerce/src/Admin/Marketing/MarketingCampaign.php:68\nStack trace:\n#0 /opt/homebrew/var/www/wp-content/plugins/google-listings-and-ads/src/MultichannelMarketing/GLAChannel.php(194): Automattic\\WooCommerce\\Admin\\Marketing\\MarketingCampaign->__construct('21359526875', NULL, 'Campaign 2024-0...', 'https://civet-p...', Object(Automattic\\WooCommerce\\Admin\\Marketing\\Price))\
Screenshots:
This PR prevents the error by checking if the campaign types have been enabled before fetching the campaigns.
Detailed test instructions:
Checkout develop.
Go to Marketing -> Overview.
Check your PHP errors or open the console and see how the campaign request fails.
Checkout this branch.
Refresh the Marketing -> Overview page.
See that we prevent the fatal error.
Add the following filter: add_filter( 'woocommerce_gla_enable_mcm', '__return_true' );
8 Refresh and see that now the campaigns are loaded.
Changes proposed in this Pull Request:
When loading the Marketing -> Overview section, there is a request to fetch the campaigns, but it currently fails because the campaign types are not loaded. The campaign types are only loaded if the filter
woocommerce_gla_enable_mcm
returns true.The fatal error is the below:
Screenshots:
This PR prevents the error by checking if the campaign types have been enabled before fetching the campaigns.
Detailed test instructions:
develop
.Additional details:
Tests are failing because of this issue: https://github.com/woocommerce/google-listings-and-ads/pull/2415#issuecomment-2149368962 however you can run the tests locally and see if everything is OK
Changelog entry