Allow tickets to show on WooCommerce shop pages

Description

By default, the WooCommerce products that correspond to tickets created with Event Tickets Plus are hidden from displaying in the shop pages. WooCommerce products can be configured to show in the shop pages by editing the product in WooCommerce > Products and changing the "catalog visibility" settings in the product's "publish" panel. This snippet will change the default visibility of ticket products to be "visible" instead of "hidden" when creating or saving a ticket within an event. 

Note: this will only affect tickets when creating a new ticket or saving an existing ticket. For existing tickets, you can either re-save the tickets within the event, or manually change the visibility of the WooCommerce product. 

Usage

Copy the below code into your (child) theme's functions.php file (or wherever you usually put custom code).

Snippet

add_action( 'event_tickets_after_save_ticket', function( $post_id, $ticket ) {
    $product = wc_get_product( $ticket->ID );
    $product->set_catalog_visibility( 'visible' );
    $product->save();
}, 100, 2 );

Plugins

  • Event Tickets Plus

Notes

  • Originally written in July 2019
  • Tested with Event Tickets Plus 4.10.5.1
  • Author: Sky Shabatura

Disclaimer

As with all of our recipes, please note that we share this in the hope it will be useful but without any guarantees or commitments. If you wish to use it, it is your responsibility to test it first of all and adapt it to your needs (or find someone who can do so on your behalf). We are unable to provide further support in relation to this recipe.