{"id":1962293,"date":"2024-08-04T11:36:45","date_gmt":"2024-08-04T15:36:45","guid":{"rendered":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/?p=1962293"},"modified":"2025-05-28T02:38:11","modified_gmt":"2025-05-28T06:38:11","slug":"auto-assign-featured-image-to-woocommerce-ticket-product","status":"publish","type":"post","link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/auto-assign-featured-image-to-woocommerce-ticket-product\/","title":{"rendered":"Auto-Assign Featured Image to WooCommerce Ticket Product"},"content":{"rendered":"\n<p>When using <a href=\"https:\/\/theeventscalendar.com\/products\/wordpress-event-tickets\/\">Event Tickets Plus<\/a> with <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/getting-started-with-woocommerce-and-event-tickets-plus\/\">WooCommerce<\/a> as the payment gateway, each ticket created becomes a WooCommerce product listed in the WooCommerce shop and is referred to as <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/ticket-products-event-tickets-plus-integration-with-woocommerce\/\" target=\"_blank\" rel=\"noreferrer noopener\">Ticket Product<\/a>. However, by default, no featured image is assigned to the ticket product. As a result, the fallback thumbnail will be used in the shop and the cart.<\/p>\n\n\n<style>.kb-image1962293_016803-1c11.kb-image-is-ratio-size, .kb-image1962293_016803-1c11 .kb-image-is-ratio-size{max-width:768px;width:100%;}.wp-block-kadence-column > .kt-inside-inner-col > .kb-image1962293_016803-1c11.kb-image-is-ratio-size, .wp-block-kadence-column > .kt-inside-inner-col > .kb-image1962293_016803-1c11 .kb-image-is-ratio-size{align-self:unset;}.kb-image1962293_016803-1c11 figure{max-width:768px;}.kb-image1962293_016803-1c11 .image-is-svg, .kb-image1962293_016803-1c11 .image-is-svg img{width:100%;}.kb-image1962293_016803-1c11 .kb-image-has-overlay:after{opacity:0.3;}<\/style>\n<div class=\"wp-block-kadence-image kb-image1962293_016803-1c11\"><figure class=\"aligncenter size-medium_large\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"418\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/FjTQXjufrm-768x418.png\" alt=\"Ticket product without featured image\" class=\"kb-img wp-image-1962656\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/FjTQXjufrm-768x418.png 768w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/FjTQXjufrm-300x163.png 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/FjTQXjufrm-1024x557.png 1024w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/FjTQXjufrm-1536x836.png 1536w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/FjTQXjufrm.png 1920w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure><\/div>\n\n\n\n<p>As tickets are frequently associated with events, it is desirable for the featured image of an event to be automatically assigned to a WooCommerce product created for the event&#8217;s tickets. This can be accomplished by adding the following PHP snippet to the site.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/chikaibeneme\/176fed6163451db6795665460a7e3e6d.js\"><\/script>\n\n\n\n<p>Add the code snippet to the <em>functions.php<\/em> file of your theme, or use your preferred method for integrating snippets into your WordPress site, such as the free <a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" target=\"_blank\" rel=\"noreferrer noopener\">Code Snippets<\/a> plugin.<\/p>\n\n\n\n<p>By automatically assigning the event&#8217;s featured image to WooCommerce ticket products, time is saved by eliminating the need for a site editor to assign featured images to all created tickets manually.<\/p>\n\n\n<style>.kb-image1962293_f06d95-9612.kb-image-is-ratio-size, .kb-image1962293_f06d95-9612 .kb-image-is-ratio-size{max-width:3000px;width:100%;}.wp-block-kadence-column > .kt-inside-inner-col > .kb-image1962293_f06d95-9612.kb-image-is-ratio-size, .wp-block-kadence-column > .kt-inside-inner-col > .kb-image1962293_f06d95-9612 .kb-image-is-ratio-size{align-self:unset;}.kb-image1962293_f06d95-9612 figure{max-width:3000px;}.kb-image1962293_f06d95-9612 .image-is-svg, .kb-image1962293_f06d95-9612 .image-is-svg img{width:100%;}.kb-image1962293_f06d95-9612 .kb-image-has-overlay:after{opacity:0.3;}<\/style>\n<div class=\"wp-block-kadence-image kb-image1962293_f06d95-9612\"><figure class=\"aligncenter size-medium_large\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"378\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/j8GkYJ7o5u-768x378.png\" alt=\"Ticket product with featured image\" class=\"kb-img wp-image-1962660\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/j8GkYJ7o5u-768x378.png 768w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/j8GkYJ7o5u-300x148.png 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/j8GkYJ7o5u-1024x504.png 1024w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/j8GkYJ7o5u-1536x756.png 1536w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/08\/j8GkYJ7o5u.png 1920w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-optional-embed-a-script-via-gist-not-recommended-for-production\"><strong>Optional: Embed a Script via Gist (Not Recommended for Production)<br><\/strong><\/h3>\n\n\n\n<p>If you prefer using a Gist embed (e.g., for demo purposes), you can paste the following snippet into your theme\u2019s footer or header:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nfunction ticket_featured_image_custom() {\n    ?&gt;\n        &lt;script src=&quot;https:\/\/gist.github.com\/chikaibeneme\/176fed6163451db6795665460a7e3e6d.js&quot;&gt;&lt;\/script&gt;\n    &lt;?php\n}\nadd_action(&#039;wp_head&#039;, &#039;ticket_featured_image_custom&#039;);\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u26a0\ufe0f <strong>Note:<\/strong> This method loads an external script and is not recommended for production use due to performance and security considerations<\/p>\n<\/blockquote>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Notes<\/h4>\n\n\n\n<p>Originally written in April 2024. Updated in May 2025.<\/p>\n\n\n\n<p>Tested with:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The Events Calendar<\/strong> 6.13.1<\/li>\n\n\n\n<li><strong>Event Tickets<\/strong> 5.23.1<\/li>\n<\/ul>\n\n\n\n<p><strong>Author:<\/strong> Chika Ibeneme<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When using Event Tickets Plus with WooCommerce as the payment gateway, each ticket created becomes a WooCommerce product listed in the WooCommerce shop and is referred to as Ticket Product. However, by default, no featured image is assigned to the ticket product. As a result, the fallback thumbnail will be used in the shop and&#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,88],"tags":[20,25,58,212,106],"stellar-product-taxonomy":[156],"class_list":["post-1962293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-customizing","category-customizing-resources","category-snippets","category-tickets","tag-code","tag-customizations","tag-php","tag-snippets","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"},{"value":88,"label":"Ticketing"}],"post_tag":[{"value":20,"label":"Code"},{"value":25,"label":"Customizations"},{"value":58,"label":"PHP"},{"value":212,"label":"snippets"},{"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},{"term_id":88,"name":"Ticketing","slug":"tickets","term_group":0,"term_taxonomy_id":88,"taxonomy":"category","description":"","parent":61,"count":83,"filter":"raw","term_order":"0","cat_ID":88,"category_count":83,"category_description":"","cat_name":"Ticketing","category_nicename":"tickets","category_parent":61}],"tag_info":[{"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":58,"name":"PHP","slug":"php","term_group":0,"term_taxonomy_id":58,"taxonomy":"post_tag","description":"","parent":20,"count":128,"filter":"raw","term_order":"0"},{"term_id":212,"name":"snippets","slug":"snippets","term_group":0,"term_taxonomy_id":212,"taxonomy":"post_tag","description":"","parent":0,"count":17,"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\/1962293","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=1962293"}],"version-history":[{"count":10,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1962293\/revisions"}],"predecessor-version":[{"id":1965487,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1962293\/revisions\/1965487"}],"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=1962293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1962293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1962293"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1962293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}