Okay
  Public Ticket #3769294
Dynamic Placeholder contains no data
Closed

Comments

  • Tom started the conversation

    Hi,

    I've been trying all day and can't get this to work so need some help.

    Following the guidance at https://wpamelia.com/wp-hooks-notifications/ I've created a custom hook but it doesn't seem to be able to call any data from $data

    function amelia_customerisvip($data) {

    $appt_id = $data['appointment_id'];
    return 'VIP Status:'.$appt_id;

    }

    // Add filter to handle dynamic placeholder
    add_filter('amelia_dynamic_placeholder_customerisVIP', 'amelia_customerisvip', 10, 1);


    Ultimately I want to be able to do manipulate the appointment ID but at this stage I can't get it to pull out any data from $data. I can, by testing with Uncanny Automator's hooks function, that $data returns all of these options but they all seem to be empty:

    argument_0.appointment_idnumeric
    argument_0.appointment_statusstring
    argument_0.appointment_notesstring
    argument_0.appointment_datestring
    argument_0.appointment_date_timestring
    argument_0.appointment_start_timestring
    argument_0.appointment_end_timestring
    argument_0.initial_appointment_datestring
    argument_0.initial_appointment_date_timestring
    argument_0.initial_appointment_start_timestring
    argument_0.initial_appointment_end_timestring
    argument_0.lesson_space_urlstring
    argument_0.zoom_host_urlstring
    argument_0.zoom_join_urlstring
    argument_0.google_meet_urlstring
    argument_0.time_zonestring
    argument_0.category_namestring
    argument_0.category_idnumeric
    argument_0.service_descriptionstring
    argument_0.reservation_descriptionstring
    argument_0.service_durationstring
    argument_0.service_namestring
    argument_0.service_idnumeric
    argument_0.reservation_namestring
    argument_0.service_pricestring
    argument_0.appointment_durationstring
    argument_0.service_extra_19_namestring
    argument_0.service_extra_19_quantitystring
    argument_0.service_extra_19_pricestring
    argument_0.service_extra_20_namestring
    argument_0.service_extra_20_quantitystring
    argument_0.service_extra_20_pricestring
    argument_0.service_extra_21_namestring
    argument_0.service_extra_21_quantitystring
    argument_0.service_extra_21_pricestring
    argument_0.service_extra_22_namestring
    argument_0.service_extra_22_quantitystring
    argument_0.service_extra_22_pricestring
    argument_0.service_extrasstring
    argument_0.depositboolean
    argument_0.service_extras_detailsstring
    argument_0.employee_idnumeric
    argument_0.employee_emailstring
    argument_0.employee_first_namestring
    argument_0.employee_last_namestring
    argument_0.employee_full_namestring
    argument_0.employee_phonestring
    argument_0.employee_notestring
    argument_0.employee_descriptionstring
    argument_0.employee_panel_urlstring
    argument_0.location_addressstring
    argument_0.location_phonenumeric
    argument_0.location_idnumeric
    argument_0.location_namestring
    argument_0.location_descriptionstring
    argument_0.location_latitudenumeric
    argument_0.location_longitudenumeric
    argument_0.payment_link_woocommercestring
    argument_0.payment_link_stripestring
    argument_0.payment_link_paypalstring
    argument_0.payment_link_razorpaystring
    argument_0.payment_link_molliestring
    argument_0.payment_link_squarestring
    argument_0.appointment_pricestring
    argument_0.booking_pricestring
    argument_0.appointment_cancel_urlstring
    argument_0.appointment_approve_urlstring
    argument_0.appointment_reject_urlstring
    argument_0.appointment_deposit_paymentstring
    argument_0.payment_typestring
    argument_0.payment_statusstring
    argument_0.payment_gatewaystring
    argument_0.payment_createdstring
    argument_0.payment_invoice_numbernumeric
    argument_0.payment_gateway_titlestring
    argument_0.payment_due_amountstring
    argument_0.number_of_personsstring
    argument_0.coupon_usedstring
    argument_0.custom_field_1string
    argument_0.custom_field_2string
    argument_0.recurring_appointments_detailsstring
    argument_0.group_appointment_detailsstring
    argument_0.company_addressstring
    argument_0.company_namestring
    argument_0.company_phonenumeric
    argument_0.company_websitestring
    argument_0.company_emailstring
    argument_0.company_logostring
    argument_0.booked_customerstring
    argument_0.customer_emailstring
    argument_0.customer_first_namestring
    argument_0.customer_last_namestring
    argument_0.customer_full_namestring
    argument_0.customer_phonenumeric
    argument_0.customer_phone_localnumeric
    argument_0.customer_notestring


    Ideally, rather than Appointment ID, I'd like the customer ID if that's possible? 


    What am I doing wrong?

  •  1,552
    Uroš replied

    Hello Tom,

    It seems like you're on the right track, but the issue may lie in the timing of when the $data is being populated or passed to your custom hook. The placeholder data you’re trying to use may not be available at the time you're trying to access it. Let's walk through a few things you can try:

    1. Make Sure Data Is Available:
      The placeholders you’re trying to access, like appointment_id, may not be populated at the moment the hook runs, depending on how and when the notification is triggered. Ensure that the data you're trying to manipulate is available at the point of execution.

    2. Check Hook Context:
      Confirm that the hook is triggered in the correct context, where the $data array contains the values you're expecting. It’s possible that the data isn't available when your hook is firing, or it may need to be initialized first.

    3. Customer ID:
      If you're looking for the customer ID instead of the appointment ID, you can check the $data array for keys related to the customer. Typically, customer_id should be available. You can try this in your function to see if it's populated correctly:

       
      function amelia_customerisvip($data) { // Check if customer ID is available if (isset($data['customer_id'])) { $customer_id = $data['customer_id']; return 'Customer ID: ' . $customer_id; } else { return 'Customer ID not found'; } }

      This will check if the customer_id is in the $data array and output it accordingly.

    4. Using the Right Hook:
      Ensure you are using the correct hook for your desired outcome. You are using amelia_dynamic_placeholder_customerisVIP, which might not always pass the expected data. You might need a different hook depending on what you need to do with the data.

    If you still cannot access the customer_id or other expected data from $data, you can also try logging the $data array at runtime to see exactly what’s being passed:

     
    function amelia_customerisvip($data) { // Log the entire $data array to check what’s inside error_log(print_r($data, true)); if (isset($data['customer_id'])) { $customer_id = $data['customer_id']; return 'Customer ID: ' . $customer_id; } else { return 'Customer ID not found'; } }

    This will help you debug the structure of $data and confirm what’s available to you.

    Let me know if that helps or if you need further assistance!

    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