Ecommerce Shopify WordPress Discussion

Get a php variable to another function

Im trying get a php variable from function to another function. I tried it with seasson, but there is error "PHP Warning: session_start(): Session cannot be started after headers have already been sent" $jsonContent = json_encode($dataLayerContent); if (!session_id()) session_start(); error_log("Data Layer content: " . $jsonContent); $jsonContent = json_encode($dataLayerContent); $_SESSION['jsonContent'] = $jsonContent; $response_body = wp_remote_retrieve_body($response); error_log("API request successful, sent data to CRM: $body_json, response: $response_body, Data Layer content: " . json_encode($jsonContent)); } } } } add_action('wpcf7_form_response_output', 'wpcf7_form_response_output'); function wpcf7_form_response_output($output) { if (!session_id()) session_start(); // Zajistí, že je session spuštěna $jsonContent = isset($_SESSION['jsonContent']) ? $_SESSION['jsonContent'] : '[]'; $output .= "<script type='text/javascript'> window.dataLayer = window.dataLayer || []; window.dataLayer.push(JSON.parse('".addslashes($jsonContent)."')); </script>"; return $output; } Variable $jsonContent value need to be in function wpcf7_form_response_output. How to get it there, when i cant use session or global variable (because caching)?
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.