Automattic\WooCommerce\Blocks\BlockTypes
AddToCartForm::add_to_cart_redirect_filter()
Hooks into the woocommerce_add_to_cart_redirect to prevent redirecting to another page when the block is inside the Single Product block and the Add to Cart button is clicked.
Method of the class: AddToCartForm{}
No Hooks.
Return
String
. The filtered redirect URL.
Usage
$AddToCartForm = new AddToCartForm(); $AddToCartForm->add_to_cart_redirect_filter( $url );
- $url(string) (required)
- The URL to redirect to after the product is added to the cart.
AddToCartForm::add_to_cart_redirect_filter() AddToCartForm::add to cart redirect filter code WC 9.4.2
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'] ) { if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { return wc_get_cart_url(); } return wp_validate_redirect( wp_get_referer(), $url ); } return $url; }