• Resolved casciari

    (@casciari)


    Hey!

    I’m using the WooCommerce trigger ‘A user purchases a product’ for my shop and the WordPress action to send them an email after the purchase.

    I have this special promotion where the user has to register his/her friends. For each friend there’re 3 fields. Name, last name and email. I’ve added those fields dynamically with a plugin so those only show when the product is on the cart.

    I need to send an email to those friends notifying them of the gift when it has been purchased. The amount of friends is unlimited, sort of. I’ve added up to 10 sets of fields of each (name, last name and email).

    Since those fields aren’t really originally from WooCommerce, they’re not displaying on the WooCommerce dropdown. I’ve seen there’s a custom way to add fields with {{USERMETA:KEY}}. I was wondering how would i be able to get the data from my custom fields using those ids to add my custom fields inside your plugin.

    I’d grateful for any help provided.

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Uncanny Owl

    (@uncannyowl)

    Hi there,

    The {{USERMETA:KEY}} token will work with any user metadata. The KEY component should be replaced with whatever metadata you want to display here.

    So, if all the extra details are saved in the usermeta of the customer, each in its own key, you’d be able to do something like {{USERMETA:_my_custom_user_first_name_1}} and {{USERMETA:_my_custom_user_email_1}} and so on.

    If there is no information for the key, the token will simply be replaced with an empty string.

    If you need to do something more complex (like storing and fetching this metadata as an array, or storing it in the order’s metadata), you’d need custom code.

    You can basically use the ‘automator_maybe_parse_field_text’ to replace a custom identifier like {{GIFTUSERDATA}} (won’t appear in dropdowns) with the additional field information:

    
    add_filter( 'automator_maybe_parse_field_text', 'my_custom_function_2234', 10, 2 );
    
    function my_custom_function_2234( $field_text, $match ) {
            // only apply to the custom token match
            if ( 'GIFTUSERDATA' !== $match ) {
                     return $field_text;
            }
    
            // some code here that fetches the markup for the gift user details
    
            return str_replace( '{{' . $match . '}}', $giftuserdata, $field_text );
    }
    

    See: wp-content/plugins/uncanny-automator/src/core/mu-classes/composite-classes/automator-input-parser.php

    I hope this helps. Let us know if you have any other questions.

    Thread Starter casciari

    (@casciari)

    Hello,

    I’ve been all day trying to make it work but all the times it returns empty.
    It’s like if it was not recognizing the value, or wasn’t able to grab it from the order.

    I’m using this plugin to add the fields to the checkout and display them using product conditionals:
    https://woocommerce.com/products/woocommerce-checkout-field-editor/

    Also, i’ve noticed that email recipient fields in the automator actions cannot be other than user mail or admin mail, it doesnt allow to place dynamic fields. That’d be nice to have too.

    {{USERMETA:_friend_one_first_name}}
    {{USERMETA:_friend_one_last_name}}
    {{USERMETA:_friend_one_email}}

    Those are the fields i’ve tested with, and the plugin made the fields with the keys friend_one_first_name… friend….. and so on.

    Any help would be gladly appreciated, i’m running out of time :/

    Plugin Author Uncanny Owl

    (@uncannyowl)

    Hi @casciari,

    Sorry to give you bad news, but our expectation is that you’re trying to look up information related to the orders; the customer data will be in postmeta rather than usermeta. Trying to pull information from the order and the post is unfortunately much harder and will require a code solution.

    If you proceed with values we don’t currently support in postmeta for orders, maybe start by reviewing /wp-content/plugins/uncanny-automator/src/integrations/woocommerce/tokens/wc-tokens.php to see how the existing tokens work and the filters that would be appropriate for adding some of your own. You might also need to check the other plugin to confirm exactly how they are storing data from the custom fields on your checkout page.

    If you run into any questions during development about custom tokens or our code, let us know and we can take a look for you, but I’m afraid we don’t currently have a generic solution for pulling custom data associated with orders.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom WooCommerce checkout fields in actions’ is closed to new replies.