I want to check variable value in console I have tried everything but I am not getting the value in console.
// Here I want to check $cart_id value before if Statement
echo "Cart Id Before If Statement:" . $cart_id;
The above line is not working because the page add_cart skip and I am not able to check the value like I usually do. So I need to check this value on cosole like
console.log($cart_id);
But when I check console the console is showing empty. But When I click on network then I open preserve log then my file add_cart.php is showing and I am able to see cookie as well as form data but I have no idea how to check $cart_id in console or in any way.
I also tried in my helper.php class
function debug_to_console( $data ) {
$output = $data;
if ( is_array( $output ) )
$output = implode( ',', $output);
echo "<script>console.log( 'Debug Objects: " . $output . "' );
</script>";
}
And call it before my if statement
debug_to_console($cart_id);
But above also not working for me. I am not able to check the result of $cart_id before if statement. Nothing show on console.
if ($cart_id != '') {
}else{
$items_json = json_encode($item);
$cart_expire = date("Y-m-d H:i:s",strtotime("+30 days"));
$db->query("INSERT INTO cart (items,expire_date) VALUES ('{$items_json}','{$cart_expire}') ");
$cart_id = $db->insert_id;
setcookie(CART_COOKIE,$cart_id,CART_COOKIE_EXPIRE,'/',$domain,false);
}
Your valuable suggestion would be welcome.