uct ); } return $product; } /** * Filter the add to cart message to prevent the Notice from being displayed when the Add to Cart form is a descendent of a Single Product block * and the Add to Cart button is clicked. * * @param string $message Message to be displayed when product is added to the cart. */ public function add_to_cart_message_html_filter( $message ) { // phpcs:ignore if ( isset( $_POST['is-descendent-of-single-product-block'] ) && 'true' === $_POST['is-descendent-of-single-product-block'] ) { return false; } return $message; } /** * Hooks into the `woocommerce_add_to_cart_redirect` filter to prevent redirecting * to another page when the block is inside the Single Product block and the Add to Cart button * 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 ) { // 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 ); } return $url; } /** * Get the frontend script handle for this block type. * * @param string $key Data to get, or default to everything. */ protected function get_block_type_script( $key = null ) { return null; } /** * It isn't necessary register block assets because it is a server side block. */ protected function register_block_type_assets() { return null; } }
Fatal error: Uncaught Error: Class "Automattic\WooCommerce\Blocks\BlockTypes\AddToCartForm" not found in /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/BlockTypesController.php:65 Stack trace: #0 /htdocs/wp-includes/class-wp-hook.php(310): Automattic\WooCommerce\Blocks\BlockTypesController->register_blocks('') #1 /htdocs/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array) #2 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /htdocs/wp-settings.php(632): do_action('init') #4 /htdocs/wp-config.php(96): require_once('/htdocs/wp-sett...') #5 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #6 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #7 /htdocs/index.php(17): require('/htdocs/wp-blog...') #8 {main} thrown in /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/BlockTypesController.php on line 65