OiO.lk Blog jQuery Additional cost from multiple custom fields during WooCommerce checkout
jQuery

Additional cost from multiple custom fields during WooCommerce checkout


I’ve added some custom fields to my website that show up in the checkout. It’s about child registration for a Summer Camp.

They are select fields:

function person_details( $checkout ) {
    global $woocommerce;

    $count = $woocommerce->cart->cart_contents_count;
    $i = 0;

    for( $k=1; $k<= $count; $k++ ) {
        $i++;
        
        print ('<h3>Gegevens van kind #'.$i.'</h3>');

        woocommerce_form_field( 'cstm_care'.$i, array(
            'type'                       => 'select',
            'required'                   => true,
            'class'                      => array( 'my-field-class form-row-last' ),
            'label'                      => __( 'Voor- en na zorg' ),
            'options'                    => array(
                    'Geen'                   => __( 'Geen', 'njengah' ),
                    'Voorzorg'               => __( 'Pre-care (€30)', 'njengah' ),
                    'Nazorg'                 => __( 'Aftercare (€30)', 'njengah' ),
                    'Voor- en na zorg'       => __( 'Pre- & Aftercare (€50)', 'njengah' )
        )), $checkout->get_value( 'cstm_care'.$i ));
    }
}

I want to change the total during the checkout based on the chosen options:

  • Pre-care (€30)
  • Aftercare (€30)
  • Pre- & Aftercare (€50)

How can I achieve this? Is it even possible?



You need to sign in to view this answers

Exit mobile version