As previously announced via banners and our newsletters, support is no longer available through this platform.

For easier navigation, you can still click on "Submit a Ticket" here, choose the appropriate category, and you'll be redirected to the correct support channel for your plugin.

You can still access your previous tickets and browse public tickets, but please note that responding to tickets is no longer possible.

Paid customers: Please log in to your store account for support.

Pre-purchase questions: Use the support widget in the bottom-right corner of our websites:
https://wpamelia.com
https://wpdatatables.com
https://wpreportbuilder.com

Okay
  Public Ticket #3980227
Dynamic price for each service,
Open

Comments

  • Crisodevelop started the conversation

    I'm trying to display the dynamic price for each service, but I'm getting the person's value for each ride. 

    Example: 

    <div id="price-display">Price…</div>

     document.addEventListener('DOMContentLoaded', () => {   const serviceId = 10;     const apiUrl =      'https://macaooffroad.com/wp-admin/admin-ajax.php'     + '?action=wpamelia_api'     + '&call=/api/v1/services/' + serviceId;

      let priceBase = 0;   const priceEl = document.getElementById('price-display');

      // 1) Traer precio base del servicio   fetch(apiUrl, {     method: 'GET',     headers: {       'Content-Type': 'application/json',       'Amelia': 'Api-Key'     }   })   .then(res => res.json())   .then(json => {     priceBase = json.data.service.price;     updateDisplay();  // total inicial     bindQuantityListener();    })   .catch(err => {     console.error('Error al obtener el precio:', err);     priceEl.innerText = 'Error al cargar precio';   });

      // 2) Función para recalcular y mostrar   function updateDisplay() {     // leemos directamente la cantidad que Amelia ya está usando     const qtyEl = document.querySelector('input[name="persons"]');     const cantidad = parseInt(qtyEl.value, 10) || 1;     const total = priceBase * cantidad;     priceEl.innerText = `Total: $${total.toFixed(2)}`;   }

      // 3) Listener sobre el campo que Amelia inyecta   function bindQuantityListener() {     const qtyEl = document.querySelector('input[name="persons"]');     if (!qtyEl) {       console.warn('No encontré el campo de “persons” de Amelia');       return;     }     // con 'input' para cambios al vuelo     qtyEl.addEventListener('input', updateDisplay);   } }); 

    [Log] Initial readings of "persons" (horseback-ride, line 1006) [Log] By name: – null (horseback-ride, line 1007) [Log] By class: – null (horseback-ride, line 1008) [Log] By aria: – null (horseback-ride, line 1009) [Log] By shadow: – null (horseback-ride, line 1010) [Log] By editable: – null (horseback-ride, line 1011)

  •  1,718
    Uroš replied
     

    Hello,

    Thank you for sharing the code. It looks like you're trying to dynamically display the price based on the number of persons for a service.

    Could you please clarify if the issue you're facing is with retrieving the correct service price, or is it specifically with how the quantity input is being detected by the script? It seems like the script is unable to locate the "persons" input field.

    If possible, could you provide a link to the page where this is happening, or any additional details on how the services are set up (for example, if you're using Amelia's default fields or custom ones)?

    Looking forward to your response!

    Kind Regards, 

    Uros Jovanovic
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps, and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables