Untitled

 avatar
unknown
plain_text
2 years ago
1.8 kB
4
Indexable
// JavaScript para manejar la corrección de texto y AJAX en el checkout
function custom_text_change_script() {
    if ( is_checkout() ) {
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function($) {
                // Realiza la solicitud AJAX para obtener la corrección de texto
                function performTextCorrection() {
                    $.ajax({
                        type: 'POST',
                        url: ajaxurl,
                        data: {
                            action: 'custom_text'
                        },
                        success: function(response) {
                            // Actualiza el contenido del bloque de revisión del checkout con la corrección de texto
                            $('.woocommerce-checkout-review-order').html(response);
                        }
                    });
                }

                // Ejecuta la corrección de texto después de que se actualice el bloque de revisión del checkout
                $(document.body).on('updated_checkout', function() {
                    performTextCorrection();
                });

                // Ejecuta la corrección de texto al cargar la página inicialmente
                performTextCorrection();
            });
        </script>
        <?php
    }
}
add_action('wp_footer', 'custom_text_change_script');

// PHP para manejar la solicitud AJAX
function custom_text_ajax() {
    // Realiza la corrección de texto nuevamente aquí
    echo apply_filters('the_content', 'Larghezza:'); // Reemplaza con tu propia lógica
    wp_die();
}

add_action('wp_ajax_custom_text', 'custom_text_ajax');
add_action('wp_ajax_nopriv_custom_text', 'custom_text_ajax');
Editor is loading...