• Hi,

    I added some extra fields for my checkout page, but I am confused how to actually retrieve the data entered there (for example, how to put the gamer tag in the confirmation emails that I will send). Here’s the code I use to make the custom fields:

    add_filter( 'mt_cart_custom_fields', 'my_custom_fields', 10, 3 );
    function my_custom_fields( $custom_fields, $cart, $gateway ) {
    	$custom_fields['tag'] = '<p class="tag"><label for="tag">Gamer Tag</label> <input type="text" name="tag" id="tag" /></p>';
    	$custom_fields['country'] = '<p class="country"><label for="country">Country (required)</label> <input type="text" required name="country" id="country" /></p>';
    	return $custom_fields;
    }

    Thanks.

    https://www.ads-software.com/plugins/my-tickets/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Joe Dolson

    (@joedolson)

    If you’re referencing the example at GitHub (https://github.com/joedolson/plugin-extensions/blob/master/my-tickets/my-ticket-custom-cart-fields.php), then that’s in the bottom filter and function in the file: this inserts a template tag into the set of template tag options that can be shown in email notifications using a tag like {tag}

    Thread Starter Ardinata

    (@ardishamwow)

    Thanks for the prompt reply.

    I tried modifying the filter and function to fit my code but for some reason I cannot get it to work. I also tried using {tag} in emails, but it also does not display the inserted value. Can you help giving me an example code that works with a text input type?

    Thanks.

    Thread Starter Ardinata

    (@ardishamwow)

    So this is the function I have for my above code:

    add_filter( 'mt_handle_custom_cart_data', 'my_save_custom_field', 10, 2 );
    function my_save_custom_field( $payment, $post ) {
    	update_post_meta( $payment, '_tag', $_POST['tag'] );
    	update_post_meta( $payment, '_country', $_POST['country'] );
    }
    
    add_filter( 'mt_show_in_payment_fields', 'my_show_custom_field', 10, 2 );
    function my_show_custom_field( $output, $post_ID ) {
    	$tag = get_post_meta( $post_ID, '_tag' );
    	$country = get_post_meta( $post_ID, '_country' );
    	return $output . $tag . $country;
    }

    As far as I can find, the input data is still not showing anywhere. I must be doing something wrong here.

    Plugin Author Joe Dolson

    (@joedolson)

    When you call get_post_meta, be sure to define the 3rd parameter as ‘true’, like in the examples. Otherwise, you’ll pull the information as an array of responses instead of as a string, which won’t render on the page correctly.

    You also need to use *all* of the four functions in that example; filter for notifications is what provides you with the template tag for emails.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Field Form, How to Use’ is closed to new replies.