get_settings_for_display(); if ( 'surecart_form' === $settings['surecart_container_type'] ) { echo ''; } } /** * Add product wrapper end. * * @param \Elementor\Widget_Base $element The element. * * @return void */ public function addProductWrapperEnd( $element ) { $settings = $element->get_settings_for_display(); if ( 'surecart_form' === $settings['surecart_container_type'] ) { echo ''; } } /** * Adds the block serialization filter before Elementor content is processed. * * @return void */ public function preReturnSerializedBlock(): void { add_filter( 'pre_render_block', [ $this, 'serializeBlock' ], 10, 2 ); } /** * Disable Elementor render block. * * @param array $rendered The rendered block. * @param array $parsed_block The parsed block. * * @return array */ public function serializeBlock( $rendered, $parsed_block ) { // don't serialize if it includes the surecart/ prefix. if ( strpos( $parsed_block['blockName'] ?? '', 'surecart/' ) !== false ) { return $rendered; } return $rendered; } /** * Process Elementor content and remove the serialization filter. * * @param string $content The content to process. * * @return string The processed content */ public function doBlocksAtEnd( string $content ): string { remove_filter( 'pre_render_block', [ $this, 'serializeBlock' ], 10, 2 ); return do_blocks( $content ); } /** * Inject product form controls. * * @param \Elementor\Widget_Base $element The element. * * @return void */ public function injectProductFormControls( $element ) { $element->add_control( 'surecart_container_type', [ 'type' => \Elementor\Controls_Manager::SELECT, 'label' => esc_html__( 'Container Type', 'surecart' ), 'default' => 'default', 'options' => [ 'default' => esc_html__( 'Default', 'surecart' ), 'surecart_form' => esc_html__( 'Product Form', 'surecart' ), ], ] ); } /** * Show alert if not using product wrapper. * * @param string $content The content. * * @return string */ public function showAlertIfNotUsingProductWrapper( $content ) { // Show only to the users who has the permissions to edit the post // and if the current post is a product. if ( ! current_user_can( 'edit_posts', get_the_ID() ) || ! sc_get_product() ) { return $content; } $orphaned_blocks = $this->findOrphanedSurecartBlocks( $content ); if ( empty( $orphaned_blocks ) ) { return $content; } $alert = '