{"id":1959847,"date":"2024-05-31T17:44:05","date_gmt":"2024-05-31T21:44:05","guid":{"rendered":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/?p=1959847"},"modified":"2024-09-05T10:31:11","modified_gmt":"2024-09-05T14:31:11","slug":"divide-name-field-into-separate-first-and-last-name-fields","status":"publish","type":"post","link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/divide-name-field-into-separate-first-and-last-name-fields\/","title":{"rendered":"Divide Name Field into Separate First and Last Name Fields"},"content":{"rendered":"\n<p class=\"has-theme-palette-8-background-color has-background\"><strong>Note: <\/strong>This workaround is valid for Tickets only and not for RSVPs. <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/enabling-attendee-information-for-tickets\/\">Individual Attendee Collection<\/a> (IAC) should also be set to <em>Allowed <\/em>or <em>Required<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"How to Separate Your Name Field into Last Name and First Name\" width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/9Mo9_XI58qo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>By default, the attendee registration module has a single field to collect the full name, which isn&#8217;t always the desired behavior, as separate fields for first and last names are often needed. Here&#8217;s how this can be achieved:<\/p>\n\n\n\n<p>1. Create a new <strong>Text<\/strong> type attendee information field labeled <strong>Last Name<\/strong>,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"799\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/RT3V6Jfu9l-1024x799.png\" alt=\"\" class=\"wp-image-1959848\" style=\"width:1096px;height:auto\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/RT3V6Jfu9l-1024x799.png 1024w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/RT3V6Jfu9l-300x234.png 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/RT3V6Jfu9l-768x599.png 768w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/RT3V6Jfu9l.png 1271w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>2. Add the following snippet to your site to rename the <strong>Name<\/strong> field to <strong>First Name<\/strong>,<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( &#039;tribe_tickets_plus_attendee_registration_iac_fields&#039;, function ( $fields ) { \n\n$fields&#x5B;&#039;name&#039;]&#x5B;&#039;label&#039;] = &#039;First Name&#039;; \n\nreturn $fields; \n} );\n<\/pre><\/div>\n\n\n<p>This is what we have so far,<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1016\" height=\"863\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/lJkDri8Ehp.png\" alt=\"\" class=\"wp-image-1959849\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/lJkDri8Ehp.png 1016w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/lJkDri8Ehp-300x255.png 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/lJkDri8Ehp-768x652.png 768w\" sizes=\"auto, (max-width: 1016px) 100vw, 1016px\" \/><\/figure>\n\n\n\n<p>It&#8217;s not quite right as the newly added Last Name field needs to be placed right after First Name.<\/p>\n\n\n\n<p>3. Add the following snippet to your site to reorder the fields,<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( &#039;event_tickets_plus_meta_fields_by_ticket&#039;, function ( $fields ) {\n\n\t$emailIndex = array_search( &#039;tribe-tickets-plus-iac-email&#039;, array_column( $fields, &#039;slug&#039; ) );\n\t$nameIndex  = array_search( &#039;tribe-tickets-plus-iac-name&#039;, array_column( $fields, &#039;slug&#039; ) );\n\n\tif ( $emailIndex !== false &amp;&amp; $nameIndex !== false ) {\n\t\t$lastNameIndex = array_search( &#039;last-name&#039;, array_column( $fields, &#039;slug&#039; ) );\n\t\tif ( $lastNameIndex !== false ) {\n\t\t\t$lastNameField = $fields&#x5B; $lastNameIndex ];\n\t\t\tunset( $fields&#x5B; $lastNameIndex ] );\n\t\t\tarray_splice( $fields, $emailIndex, 0, array( $lastNameField ) );\n\t\t}\n\t}\n\n\treturn $fields;\n}, 20 );\n<\/pre><\/div>\n\n\n<p>The fields should now be in the correct order,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"873\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/M5cHInm1LM-1024x873.png\" alt=\"\" class=\"wp-image-1959850\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/M5cHInm1LM-1024x873.png 1024w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/M5cHInm1LM-300x256.png 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/M5cHInm1LM-768x655.png 768w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/M5cHInm1LM.png 1031w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>4. At the backend, the Last Name isn&#8217;t automatically displayed conveniently; however, this can be solved with, you guessed it, a PHP snippet,<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( &#039;manage_tribe_events_page_tickets-attendees_columns&#039;, &#039;add_last_name_column&#039; );\nadd_filter( &#039;tribe_events_tickets_attendees_table_column&#039;, &#039;populate_last_name_column&#039;, 10, 3 );\n\nfunction add_last_name_column( $columns ) {\n\t$new_columns = &#x5B;];\n\tforeach ( $columns as $key =&gt; $title ) {\n\t\t$new_columns&#x5B; $key ] = $title;\n\t\tif ( $key === &#039;primary_info&#039; ) {\n\t\t\t$new_columns&#x5B;&#039;last_name&#039;] = &#039;Last Name&#039;;\n\t\t}\n\t}\n\n\treturn $new_columns;\n}\n\nfunction populate_last_name_column( $value, $item, $column ) {\n\tif ( $column === &#039;last_name&#039; &amp;&amp; ! empty( $item&#x5B;&#039;attendee_meta&#039;]&#x5B;&#039;last-name&#039;] ) ) {\n\t\tif ( is_array( $item&#x5B;&#039;attendee_meta&#039;]&#x5B;&#039;last-name&#039;] ) ) {\n\t\t\treturn ! empty( $item&#x5B;&#039;attendee_meta&#039;]&#x5B;&#039;last-name&#039;]&#x5B;&#039;value&#039;] ) ? $item&#x5B;&#039;attendee_meta&#039;]&#x5B;&#039;last-name&#039;]&#x5B;&#039;value&#039;] : &#039;&#039;;\n\t\t} else {\n\t\t\treturn $item&#x5B;&#039;attendee_meta&#039;]&#x5B;&#039;last-name&#039;];\n\t\t}\n\t}\n\n\treturn $value;\n}\n<\/pre><\/div>\n\n\n<p>Last Name should now be displayed in a dedicated column at the backend, next to the primary info column with First Name and other attendee details,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"246\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/1KIU26W6A1-1024x246.png\" alt=\"\" class=\"wp-image-1959873\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/1KIU26W6A1-1024x246.png 1024w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/1KIU26W6A1-300x72.png 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/1KIU26W6A1-768x185.png 768w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/1KIU26W6A1-1536x369.png 1536w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/04\/1KIU26W6A1.png 1676w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-theme-palette-8-background-color has-background\">While it is possible to add PHP code snippets similar to those provided in this article directly to the functions.php file, using a third-party plugin like <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/best-practices-for-implementing-custom-code-snippets\/\">Code Snippets<\/a> is recommended.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: This workaround is valid for Tickets only and not for RSVPs. Individual Attendee Collection (IAC) should also be set to Allowed or Required. By default, the attendee registration module has a single field to collect the full name, which isn&#8217;t always the desired behavior, as separate fields for first and last names are often&#8230;<\/p>\n","protected":false},"author":59,"featured_media":1955565,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[24,59,79],"tags":[16,20,25,89,106],"stellar-product-taxonomy":[156],"class_list":["post-1959847","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-customizing","category-customizing-resources","category-snippets","tag-attendee-registration","tag-code","tag-customizations","tag-tickets-commerce","tag-woocommerce","stellar-product-taxonomy-event-tickets-plus"],"acf":[],"taxonomy_info":{"category":[{"value":24,"label":"Customizations"},{"value":59,"label":"PHP &amp; Functions"},{"value":79,"label":"Snippets"}],"post_tag":[{"value":16,"label":"Attendee Registration"},{"value":20,"label":"Code"},{"value":25,"label":"Customizations"},{"value":89,"label":"Tickets Commerce"},{"value":106,"label":"WooCommerce"}],"stellar-product-taxonomy":[{"value":156,"label":"Event Tickets Plus"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2023\/02\/social-share-1024x538.png",1024,538,true],"author_info":{"display_name":"Masood","author_link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/author\/masood\/"},"comment_info":0,"category_info":[{"term_id":24,"name":"Customizations","slug":"customizing","term_group":0,"term_taxonomy_id":24,"taxonomy":"category","description":"","parent":0,"count":110,"filter":"raw","term_order":"0","cat_ID":24,"category_count":110,"category_description":"","cat_name":"Customizations","category_nicename":"customizing","category_parent":0},{"term_id":59,"name":"PHP &amp; Functions","slug":"customizing-resources","term_group":0,"term_taxonomy_id":59,"taxonomy":"category","description":"","parent":24,"count":101,"filter":"raw","term_order":"0","cat_ID":59,"category_count":101,"category_description":"","cat_name":"PHP &amp; Functions","category_nicename":"customizing-resources","category_parent":24},{"term_id":79,"name":"Snippets","slug":"snippets","term_group":0,"term_taxonomy_id":79,"taxonomy":"category","description":"","parent":0,"count":136,"filter":"raw","term_order":"0","cat_ID":79,"category_count":136,"category_description":"","cat_name":"Snippets","category_nicename":"snippets","category_parent":0}],"tag_info":[{"term_id":16,"name":"Attendee Registration","slug":"attendee-registration","term_group":0,"term_taxonomy_id":16,"taxonomy":"post_tag","description":"","parent":0,"count":11,"filter":"raw","term_order":"0"},{"term_id":20,"name":"Code","slug":"code","term_group":0,"term_taxonomy_id":20,"taxonomy":"post_tag","description":"","parent":0,"count":33,"filter":"raw","term_order":"0"},{"term_id":25,"name":"Customizations","slug":"customizations","term_group":0,"term_taxonomy_id":25,"taxonomy":"post_tag","description":"","parent":0,"count":177,"filter":"raw","term_order":"0"},{"term_id":89,"name":"Tickets Commerce","slug":"tickets-commerce","term_group":0,"term_taxonomy_id":89,"taxonomy":"post_tag","description":"","parent":26,"count":26,"filter":"raw","term_order":"0"},{"term_id":106,"name":"WooCommerce","slug":"woocommerce","term_group":0,"term_taxonomy_id":106,"taxonomy":"post_tag","description":"","parent":26,"count":40,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1959847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/59"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1959847"}],"version-history":[{"count":9,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1959847\/revisions"}],"predecessor-version":[{"id":1962778,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1959847\/revisions\/1962778"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1959847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1959847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1959847"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1959847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}