I am trying to get the currently selected payment gateway before the user finished checking out. I do this because I added some custom field when the user selects the 'bacs'payment method. But currently, my function returns the payment method that was selected when the checkout process starts, not the one that is currently selected. Here is the code I am using.
/**
* Process the checkout
*/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
$selected_payment_method_id = WC()->session->get( 'chosen_payment_method' ); // this code returns cod even when bacs is selected because cod was selected when the checkout process started
if($selected_payment_method_id == 'bacs'){
// Check if set, if its not set add an error.
if ( ! $_POST['extra_info_company'] || ! $_POST['extra_info_ordernumber'] || ! $_POST['extra_info_first_name'] || ! $_POST['extra_info_last_name'] || ! $_POST['extra_info_phonenumber'] || ! $_POST['extra_info_email'] )
wc_add_notice( __( 'Vul alle extra velden in.' ), 'error' );
}
}
Can anybody help me out?