Created
June 27, 2015 10:37
-
-
Save vajrasar/8a8aa97de1b39f18ef29 to your computer and use it in GitHub Desktop.
Working php session logic (changes made in functions.php file)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vg_show_post_id() { | |
$p_id = $_REQUEST['post_id']; | |
$title = get_the_title( $p_id ); | |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | |
if (!empty($_SESSION['cart']) && array_key_exists( $p_id, $_SESSION['cart'] ) ) { | |
$cnt = $_SESSION['cart'][$p_id]; | |
$cnt++; | |
$_SESSION['cart'][$p_id] = $cnt; | |
} else { | |
$_SESSION['cart'][$p_id] = 1; | |
} | |
echo '<pre>'; | |
print_r( $_SESSION['cart'] ); | |
echo '</pre>'; | |
die(); | |
} else { | |
echo "Not in admin-ajax"; | |
} | |
} | |
add_action( 'wp_ajax_nopriv_vg_show_post_id', 'vg_show_post_id' ); // for ajax | |
add_action( 'wp_ajax_vg_show_post_id', 'vg_show_post_id' ); // for ajax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment