I want to add the some custom fields at checkout with woocommerce and then use this info to call an API to validate the data provided. For this I need these fields to be created and registered in the process so that I can get this data later, however I am having some issue with the get_value() function as it leads to a PHP fatal error.
add_action( 'woocommerce_checkout_before_order_review_heading', 'insurance_choice_checkout');
function insurance_choice_checkout () {
function insurance_validation_div() {
woocommerce_form_field( 'gender-selection', array(
'type' => 'radio',
'required' => true,
'label' => pll__('Veuillez indiquer votre sexe'),
'class' => array('radio-checkout'),
'options' => array(
'male' => pll__('Homme'),
'female' => pll__('Femme'),
)), $checkout->get_value('gender-selection'));
woocommerce_form_field( 'insurance-birthdate', array(
'type' => 'date',
'id' => 'birthpicker',
'class' => array('insurebd'), // CSS Class
'label_class' => array('insurelabelbd'),
'input_class' => array('insureinputbd'),
'required' => true, // Mandatory or Optional
'label' => pll__('Veuillez entrer votre date de naissance'),
), $checkout->get_value('insurance-birthdate'));
}
?>
<div id="insurance_row_checkout">
<div class="loader" id="loaderdiv"></div>
<h2 class="insurancecheckout">
<div class="insurancegb" style="display:none;">
<?php insurance_validation_div()?>
</div>
</div>
I removed everything from the code that wasn't relevant for simplicity. Basically, since i added $checkout->get_value('insurance-birthdate')) and $checkout->get_value('gender-selection')) to register these custom fields in the checkout process I get the following PHP error:
Uncaught Error: Call to a member function get_value() on null
I am struggling to find why this is causing this.