Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
Devuelve el valor original jquery/php

Estoy usando este código para ejecutar mi botón adicional. Cambia el valor del precio original al valor personalizado. ¿Es posible hacer clic nuevamente en el botón llamado "botón después del clic" para obtener el precio con el valor original, lo que significa obtener el precio regular y restablecer todo, por lo que podría ser posible hacer clic nuevamente y obtener el valor personalizado, luego hacer clic y obtener el valor del precio regular, etc.? etc.?

// Přidání bestpprice' vlastního pole $bestprice = get_post_meta( $product->get_id(), '_bestprice', true);

 if( ! empty($bestprice) ): $bestprice = wc_get_price_to_display( $product, array( 'price' => $bestprice ) ); $reg_price = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ); $range = wc_format_sale_price( $reg_price, $bestprice ); ?> <!-- The button and hidden field --> <div class="bestprice-wrapper"><br> <a href="" class="get_bestprice button alt" id="get_bestprice"><?php _e('Aktivovat lepší cenu');?></a> <input type="hidden" name="bestprice" id="bestprice" class="bestprice" value="" /> </div> <!-- The jQuery code --> <script type="text/javascript"> (function($){ var b = '<?php echo $bestprice; ?>', i = 'input[name=bestprice]', p = 'p.price', r = '<?php echo $range; ?>', t = 'a#get_bestprice' u = true; $(t).click( function(e){ e.preventDefault(); if(u){ $(p).html(r); // Replacing price with the range $(i).val(b); // Set the best price in hidden input field $(t).text(‚Activated'); // change button text $(t).removeClass('alt'); // Remove button 'alt' class for styling $(t).removeClass('get_bestprice') $(t).addClass(‚afterclickbutton') u = false; // Disable button } }); })(jQuery); </script> <?php endif; }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Actualización 2:

 if( ! empty($bestprice) ): $bestprice = wc_get_price_to_display( $product, array( 'price' => $bestprice ) ); $reg_price = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ); $range = wc_format_sale_price( $reg_price, $bestprice ); ?> <!-- The button and hidden field --> <div class="bestprice-wrapper"><br> <a href="" class="get_bestprice button alt" id="get_bestprice"><?php _e('Aktivovat lepší cenu');?></a> <input type="hidden" name="bestprice" id="bestprice" class="bestprice" value="" /> </div> <!-- The jQuery code --> <script type="text/javascript"> (function($){ var b = '<?php echo $bestprice; ?>', o = $('p.price').clone().find('del').remove().end().text().trim().replace(/[^\d.,]/g, ''), i = 'input[name=bestprice]', p = 'p.price', r = '<?php echo $range; ?>', t = 'a#get_bestprice' u = true; $(t).click( function(e){ e.preventDefault(); if(u){ if ($(p).attr('type') == undefined){ $(p).attr('type','_regular_price') }; if ($(`${p}[type="_best_price"]`).length == 0) { $(p).hide().after(`<p class="price" type="_best_price">${r}</p>`); // add best price and hide regulare }else{ $(`${p}[type="_regular_price"]`).hide(); $(`${p}[type="_best_price"]`).show(); } //$(p).html(r); // Replacing price with the range $(i).val(b); // Set the best price in hidden input field $(t).text('Activated') // change button text .removeClass('alt get_bestprice') // Remove button 'alt' class for styling .addClass('afterclickbutton'); u = false; // Disable button }else{ $(`${p}[type="_best_price"]`).hide(); $(`${p}[type="_regular_price"]`).show(); $(i).val(o); $(t).text('Active best price') .addClass('alt get_bestprice') .removeClass('afterclickbutton'); u = true; } }); })(jQuery); </script> <?php endif; }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda