• Resolved kelvinmarlow

    (@kelvinmarlow)


    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 above

    add_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)
  • Thread Starter kelvinmarlow

    (@kelvinmarlow)

    can someone help me on this?

    Hi there!

    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

    From what I gather, this is custom code you are sharing in the thread here. This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    Kindly keep in mind we are not developers and only offer support for existing functionality.

    Please see our Support Policy: https://www.woocommerce.com/support-policy/

    For assistance with customization or development with your site, we recommend that you seek help from:

    * A local web developer
    * Codeable.io
    * WooExperts
    * Stackexchange

    If you are comfortable coding yourself and have questions, I would also recommend that you consider:

    * WooCommerce developer Portal
    * WooCommerce Slack Community
    * Advanced WooCommerce Facebook group

    I hope that helps you to figure it out.

    Sorry for the late reply, we had a problem in our internal system recently.

    Feel free to get back to us if you have further questions.

    • This reply was modified 2 years, 3 months ago by anastas10s. Reason: rephrase
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.