Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active February 6, 2022 13:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/5bffd372db4ebf14482574ce9bb2479c to your computer and use it in GitHub Desktop.
Save cliffordp/5bffd372db4ebf14482574ce9bb2479c to your computer and use it in GitHub Desktop.
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 This snippet.
* @link https://gist.github.com/cliffordp/63abddea69b60f616c1aec1c6bdfc299 Another snippet you might be interested in.
*
* @param int $post_id_attached_to Post ID of post the ticket is tied to
* @param Tribe__Tickets__Ticket_Object $ticket Ticket that was just saved
* @param array $ticket_raw_data Ticket data
* @param string $commerce_engine_class 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