From e01cf300fe0c51e507c606ba808d669530b94c90 Mon Sep 17 00:00:00 2001 From: Alexandre Lara Date: Mon, 24 Jul 2023 11:45:40 -0300 Subject: [PATCH] Add to cart form: Fix fatal error when missing `product` param in add_to_cart_redirect_filter (#10316) * Transform product param optional in add_to_cart_redirect_filter method * Remove unnecessary argument from add_to_cart_redirect_filter * Remove mocked filter call * Remove unnecessary argument from function docs --- src/BlockTypes/AddToCartForm.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/BlockTypes/AddToCartForm.php b/src/BlockTypes/AddToCartForm.php index 2bb0c3de4de..113ffec0dc4 100644 --- a/src/BlockTypes/AddToCartForm.php +++ b/src/BlockTypes/AddToCartForm.php @@ -29,7 +29,7 @@ class AddToCartForm extends AbstractBlock { protected function initialize() { parent::initialize(); add_filter( 'wc_add_to_cart_message_html', array( $this, 'add_to_cart_message_html_filter' ), 10, 2 ); - add_filter( 'woocommerce_add_to_cart_redirect', array( $this, 'add_to_cart_redirect_filter' ), 10, 2 ); + add_filter( 'woocommerce_add_to_cart_redirect', array( $this, 'add_to_cart_redirect_filter' ), 10, 1 ); } /** @@ -155,10 +155,9 @@ public function add_to_cart_message_html_filter( $message ) { * is clicked. * * @param string $url The URL to redirect to after the product is added to the cart. - * @param object $product The product being added to the cart. * @return string The filtered redirect URL. */ - public function add_to_cart_redirect_filter( $url, $product ) { + public function add_to_cart_redirect_filter( $url ) { // phpcs:ignore if ( isset( $_POST['is-descendent-of-single-product-block'] ) && 'true' == $_POST['is-descendent-of-single-product-block'] ) { return wp_validate_redirect( wp_get_referer(), $url );