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

Commit

Permalink
Add to cart form: Fix fatal error when missing product param in add…
Browse files Browse the repository at this point in the history
…_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
  • Loading branch information
thealexandrelara authored and alexflorisca committed Jul 25, 2023
1 parent 96435da commit b6193cc
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/BlockTypes/AddToCartForm.php
Original file line number Diff line number Diff line change
@@ -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 );

0 comments on commit b6193cc

Please sign in to comment.