I cannot figure out what i am missing here.
I am creating a hidden field on the checkout page, that contains a value after a customer's choice.
This part is working, as i can see in the inspector on the checkout page.
The hidden field should be saved to the logged-in user, as i need it on another place in the website.
I have the following:
//This part is working!!
add_action( 'woocommerce_after_checkout_billing_form', function() {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
if( isset($values['programmakeuze']) ){
echo '<input type="hidden" name="programchoice" id="programchoice" class="input-hidden" value="'.$values['programmakeuze'].'">';
}
}
});
//Save hidden field to user
function elearning_checkout_update_user_meta( $customer_id, $posted ) {
if (!empty($_POST['programchoice'])) {
$program = intval($_POST['programchoice'] );
update_user_meta( $customer_id, 'programchoice', $program);
}
}
add_action( 'woocommerce_checkout_update_user_meta', 'elearning_checkout_update_user_meta', 10, 2 );
function testing(){
$id = get_current_user_id();
$value = get_user_meta($id,'programchoice',true);
if ( !empty($value)) {
var_dump ($value);
}
}
add_action('wp_head','testing');
The $value
returns nothing. What am i missing here?