unable to save select option when ajax reload on checkout
-
Hi, I couldn’t save selected option when ajax run in the checkout with my custom field. I saw it in Select and Textarea option
Reproduce>
go to checkout> fill the form> select payment method (this do the ajax by a plugin) > should re-select dropdown for this custom code aboveadd_action( 'woocommerce_after_checkout_billing_form', 'arca_checkout_field' ); function arca_checkout_field( $checkout ) { echo '<div id="arca_envio_checkout_field"><h2>' . __('Detalles de Envio') . '</h2>'; woocommerce_form_field( 'arca_informacion_envio', array( 'type' => 'select', 'class' => array('select wc-enhanced-select form-row-wide'), 'label' => __('Método de Envío'), /*'placeholder' => _x('Elige una opción..', 'placeholder', 'woocommerce'),*/ 'required' => true, // or false //'clear' => false, //'default' => '', 'options' => array( '' => __( 'Elige una opción..', 'woocommerce' ), 'pasare_retirar' => __( 'Pasaré a retirar', 'woocommerce' ), 'enviar_por_delivery' => __( 'Enviar por Delivery - Cobrado en la entrega el pedido', 'woocommerce' )), ), $checkout->get_value( 'arca_informacion_envio' ));
I tried to uso these code to save the selected option but didn’t work:
add_action( 'wp_footer', 'woocommerce_tip_script2' ); function woocommerce_tip_script2() { // Only on checkout page if( ! is_checkout() ) return; ?> <script type="text/javascript"> jQuery(function($){ // On 'select#arca_informacion_envio' change (live event) $('form.checkout').on( 'change', 'select#arca_informacion_envio', function(){ // Set the select value in a variable var a = $(this).val(); // Update checkout event $('body').trigger('update_checkout'); //jQuery(document.body).trigger("update_checkout"); // Restoring the chosen option value $('select#arca_informacion_envio').prop('selected', true); // Just for testing (To be removed) //console.log('trigger "update_checkout"'); // Once checkout has been updated $('body').on('updated_checkout', function(){ // Restoring the chosen option value $('select#arca_informacion_envio option[value='+a+']').prop('selected', true); // Just for testing (To be removed) // console.log('"updated_checkout" event, restore selected option value: '+a); }); }); }) </script> <?php }
It only happens with dropdown and textarea Options
any help? please
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘unable to save select option when ajax reload on checkout’ is closed to new replies.