Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Apply filter woocommerce_loop_add_to_cart_link is called with 2 params instead of 3 #8020

Closed
jorgemd24 opened this issue Dec 22, 2022 · 6 comments · Fixed by #8422 or woocommerce/google-listings-and-ads#1886
Assignees
Labels
block-type: product-query Issues related to/affecting all product-query variations. type: bug The issue/PR concerns a confirmed bug.

Comments

@jorgemd24
Copy link

jorgemd24 commented Dec 22, 2022

Describe the bug

While we were testing Google Listings & Ads and the Products Block (Beta) a fatal error was displayed, the issue is caused because the filter woocommerce_loop_add_to_cart_link is applied with two parameters instead of three.

See how WooCommerce applies the filter: https://github.com/woocommerce/woocommerce/blob/7.2.2/plugins/woocommerce/templates/loop/add-to-cart.php#L35

See WooCommerce Blocks:

See how GL&A use the filter: https://github.com/woocommerce/google-listings-and-ads/blob/d4b2dfd8751ebadb096f2a974de0202d08c048d0/src/Google/GlobalSiteTag.php#L153

Fatal error:

Uncaught ArgumentCountError: Too few arguments to function Automattic\WooCommerce\GoogleListingsAndAds\Google\GlobalSiteTag::Automattic\WooCommerce\GoogleListingsAndAds\Google\{closure}(), 2 passed in /var/www/html/wp-includes/class-wp-hook.php on line 308 and exactly 3 expected

The filter should be aligned with how WooCommerce applies the filter.

To reproduce

Steps to reproduce the behavior:

  1. Install Google Listings & Ads plugin.
  2. Create a page with the Products Block (Beta)

image

  1. See error: Uncaught ArgumentCountError: Too few arguments to function Automattic\WooCommerce\GoogleListingsAndAds\Google\GlobalSiteTag::Automattic\WooCommerce\GoogleListingsAndAds\Google\{closure}(), 2 passed in /var/www/html/wp-includes/class-wp-hook.php on line 308 and exactly 3 expected

Expected behavior

Not fatal errors.

@jorgemd24 jorgemd24 added the type: bug The issue/PR concerns a confirmed bug. label Dec 22, 2022
@opr opr added the block-type: product-grid Issues related to/affecting all product-grid type blocks. label Dec 22, 2022
@kmanijak kmanijak added block-type: product-query Issues related to/affecting all product-query variations. and removed block-type: product-grid Issues related to/affecting all product-grid type blocks. labels Jan 9, 2023
@kmanijak
Copy link
Contributor

kmanijak commented Jan 9, 2023

Thanks @jorgemd24 for raising this issue.

I followed the steps you provided, but I can't seem to reproduce the issue. On the other hand, from the links you provided, it looks like there is some inconsistency in the number of parameters provided to the filter.

@sunyatasattva, could you take a look at the issue as it's related to Products block, please?

@sunyatasattva
Copy link
Contributor

Thank you @kmanijak for tagging me. This sounds related to the Products block. If you and @jorgemd24 could provide reliable reproduction steps, then it'd be great if you'd add it to the woocommerce/woocommerce#42616 Epic 🙏

@kmanijak
Copy link
Contributor

Sounds good @sunyatasattva!

@jorgemd24, could I ask you for more details around testing steps? I followed those steps:

  1. Install Google Listings & Ads plugin.
  2. Create a page with the Products Block (Beta)

but that didn't trigger the error you mentioned:

  1. See error: Uncaught ArgumentCountError: Too few arguments to function Automattic\WooCommerce\GoogleListingsAndAds\Google\GlobalSiteTag::Automattic\WooCommerce\GoogleListingsAndAds\Google{closure}(), 2 passed in /var/www/html/wp-includes/class-wp-hook.php on line 308 and exactly 3 expected

This may be just formatting issue, but I spotted the testing steps are missing steps 3. and 4. Maybe they misplaced while raising an issue :)

@sunyatasattva
Copy link
Contributor

Hello @jorgemd24 , we tried to reproduce this issue but with no luck. Could you guide us further on reproducing it? Otherwise I'm going to need to close the issue.

@Aljullu
Copy link
Contributor

Aljullu commented Feb 14, 2023

I wasn't able to reproduce the fatal either, but I think it makes sense to align the number of parameters of the woocommerce_loop_add_to_cart_link filter with WC core. Besides that, we could easily add support to the woocommerce_loop_add_to_cart_args filter as well. I opened a PR that would fix this: #8422.

See how GL&A use the filter: https://github.com/woocommerce/google-listings-and-ads/blob/d4b2dfd8751ebadb096f2a974de0202d08c048d0/src/Google/GlobalSiteTag.php#L153

As a sidenote, GL&A is declaring the $args param but not using this. I think that could be simplified as well, I opened a PR in GL&A repo too: woocommerce/google-listings-and-ads#1886.

@Aljullu Aljullu self-assigned this Feb 14, 2023
@jorgemd24
Copy link
Author

jorgemd24 commented Feb 14, 2023

Sorry, not sure why I missed these comments! Here it is a video reproducing the error:

Screen.Capture.on.2023-02-14.at.15-52-45.mp4

And then in the logs, I see:

Uncaught ArgumentCountError: Too few arguments to function Automattic\WooCommerce\GoogleListingsAndAds\Google\GlobalSiteTag::Automattic\WooCommerce\GoogleListingsAndAds\Google\{closure}(), 2 passed in /var/www/html/wp-includes/class-wp-hook.php on line 308 and exactly 3 expected

Plugins:

WooCommerce 7.3.0
Google Listings and Ads 2.3.8

Thanks for fixing this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product-query Issues related to/affecting all product-query variations. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
5 participants