Automattic\WooCommerce\Blocks\BlockTypes

AddToCartWithOptions::add_to_cart_redirect_filter()publicWC 1.0

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.

Метод класса: AddToCartWithOptions{}

Хуков нет.

Возвращает

Строку. The filtered redirect URL.

Использование

$AddToCartWithOptions = new AddToCartWithOptions();
$AddToCartWithOptions->add_to_cart_redirect_filter( $url );
$url(строка) (обязательный)
The URL to redirect to after the product is added to the cart.

Код AddToCartWithOptions::add_to_cart_redirect_filter() WC 9.7.1

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;
}