• Hello.

    How can I use email placeholders (like {display_name}, {usermeta:permit_code}, {usermeta:location}, {usermeta:item_type}, {usermeta:item_size}, etc.) in the user’s profile?

    Here’s the story:
    The client will input paintball gear types (jackets, pants, masks, etc) and sizes for each gear through the profile form. On profile update, an email is sent to the client, the email contains the reserved gear, legal rules and regulations, safety instructions, range rules, warnings, etc., which the client will print at home and it will be signed and used as a contract/agreement when entering the range. Paintball range owner wants to be fully covered legally and he needs to have this agreement available on the client’s profile too.

    For this, I’ve tried to use a content block in the profile form, added everything we need, it looks good visually, but the placeholders are still visible, they’re not replaced with the user’s info.

    I’ve tried using the instructions from this page
    https://docs.ultimatemember.com/article/226-restrict-content-on-a-page-post-to-specific-users-community-role
    as it say

    Adding tags to text
    Common placeholders (tags) can be used inside the shortcode. The shortcode then converts these to their proper values.

    but that didn’t worked, the whole shortcode, including the placeholder, is displayed.
    Then I tried using the code from the bottom of this page in my child theme’s functions.php file
    https://docs.ultimatemember.com/article/1340-placeholders-for-email-templates
    but that didn’t worked either.

    I even added both shortcodes and placeholders directly in profile.php file, that didn’t worked either. I also tried echo do_shortcode(), which worked, but, as expected, it displayed my info, not the info from the profile I was viewing.

    Can you point me in the right direction regarding how to achieve this? Any functions I could use? Tips, tricks?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • @ovidiu-zeicu

    it displayed my info, not the info from the profile I was viewing.

    Try to replace $replace[] = um_user( 'ID' );
    with $replace[] = um_profile_id();

    Thread Starter Ovidiu Zeicu

    (@ovidiu-zeicu)

    No luck, I’ve tried different variations based on your suggestion, haven’t been able to make it work. It works with WP’s data (like {display_name}), but I couldn’t make it work with UM placeholders. This process, which should be pretty simple, is way too confusing, anyway (search placeholders one by one, then replace them one by one… then when adding it in the page it’s placeholder inside a shortcode inside a PHP echo…).

    I would’ve liked a PHP solution, but I’ve ended up using JS to replace those placeholders and I even managed to automate the process and not change it one by one. It will replace any {usermeta:placeholder} placeholder in the target element with the text value of the corresponding .um-field[data-key="placeholder"] .um-field-value'). It works great.

    Thank you for the help, anyway.

    PS: For anyone looking for similar functionality, this is the code I’ve used, it may help someone, or at least it’ll be a good starting point for different goals:

    document.addEventListener('DOMContentLoaded', function() {
      function replacePlaceholders() {
        var agreementElements = document.querySelectorAll('.agreement');
        agreementElements.forEach(function(agreementElement) {
          var html = agreementElement.innerHTML;
          var matches = html.match(/{usermeta:[^}]+}/g);
          if (matches) {
            matches.forEach(function(placeholder) {
              var key = placeholder.replace('{usermeta:', '').replace('}', '');
              var valueElement = document.querySelector('.um-field[data-key="' + key + '"] .um-field-value');
              var value = '-----'; // Default value if not found
              if (valueElement) {
                value = valueElement.textContent.trim() || '-----';
              }
              html = html.replace(new RegExp(placeholder, 'g'), value);
            });
            agreementElement.innerHTML = html;
          }
        });
      }
      replacePlaceholders();
    });
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Usage of email placeholders in content’ is closed to new replies.