Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Event Tickets Plus v4.6+: Assign all WooCommerce Tickets to a specific Product Category upon saving (create or update, won't affect old tickets).
<?php
/*
* Event Tickets Plus v4.6+: Assign all WooCommerce Tickets to a specific
* Product Category upon saving (create or update, won't affect old tickets).
*
* !!! YOU NEED TO CHANGE THE CODE TO BE THE PRODUCT CATEGORY ID(S) YOU WANT !!!
*
* @link https://gist.github.com/cliffordp/5bffd372db4ebf14482574ce9bb2479c
*
* @param int Post ID of post the ticket is tied to
* @param Tribe__Tickets__Ticket_Object Ticket that was just saved
* @param array Ticket data
* @param string Commerce engine class
*/
add_action( 'event_tickets_after_save_ticket', 'cliff_all_wootickets_into_a_product_category', 10, 4 );
function cliff_all_wootickets_into_a_product_category( $post_id_attached_to, $ticket, $ticket_raw_data, $commerce_engine_class ) {
// CHANGE THIS TO BE ONE OR MORE PRODUCT CATEGORIES
$taxonomy_term_ids = array( 54 );
if ( 'Tribe__Tickets_Plus__Commerce__WooCommerce__Main' !== $commerce_engine_class ) {
return;
}
wp_set_post_terms( $ticket->ID, $taxonomy_term_ids, 'product_cat', true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment