• When disabling the ajax option in your plugin, upon adding a product to the cart that has the popup enabled, I get a PHP warning display that the header has been already sent.

    Reason is that the popup code gets injected into the <head> of the HTML document. This happens since the woocommerce_add_to_cart you are hooking into already fires before any content gets displayed.

    By making the following modification to the top of your wup-noajax.php file, the popup gets added to the page right after the <body> opening tag. Feel free to modify to your needs:

    function thp_upsell_popup_trigger($cart_item_key, $product_id) {
    	global $thp_addtocart_popup_btn;
    
    	if ((! is_ajax()) && ($thp_addtocart_popup_btn != true)) {
    		global $thp_global_popup_html;
    		ob_start();
    			thp_fire_php_include( $product_id );
    		$thp_popup_html = ob_get_clean();
    	}
    }
    add_action( 'woocommerce_add_to_cart', 'thp_upsell_popup_trigger', 10, 2 );
    
    function thp_insert_popup() {
    	global $thp_popup_html;
    	echo $thp_popup_html ?? '';
    }
    
    add_action('wp_body_open', 'thp_insert_popup');

    Can you consider adding the fix or similar?

    Thank you!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Warning: Header Already Sent’ is closed to new replies.