Reputation: 377
I'm adding additional fields to woocommerce, the thing I cant able to store the custom value in the session. I have tried adding the wisdmlabs.com woocommerce customisation code, but cant able to var_dump it the variables.
In functions.php file var_dump is not working.
I'm using woocommerce version 3.2.5. Please somebody help me to add custom data in session and retrieve for cart.
here is the code
add_action('wp_ajax_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
add_action('wp_ajax_nopriv_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
function wdm_add_user_custom_data_options_callback()
{
//Custom data - Sent Via AJAX post method
$product_id = $_POST['id']; //This is product ID
var_dump($product_id);
$user_custom_data_values = $_POST['Volume']; //This is User custom value sent via AJAX
session_start();
$_SESSION['wdm_user_custom_data'] = $user_custom_data_values;
die();
}
Thanks
Upvotes: 3
Views: 6940
Reputation: 3419
You can add custom data to the Woocommerce session by using the following function:
WC()->session->set( 'cart_id', 'some-example-data' );
Upvotes: 4