Forum Replies Created
-
AuthorPosts
-
Jayson
ParticipantI solved it this way:
// add all tickets to a ticket category and add events category to tickets on creation
add_filter( ‘wootickets_after_save_ticket’, ‘tribe_add_category_to_woocommerce_tickets’ );
function tribe_add_category_to_woocommerce_tickets( $ticket_id ) {//add full name requirement on save
global $wpdb;
$meta_enabled=1;
//Copy this string from phpmyAdmin after saving the default string. It’s in the post_meta table
$metaval= ‘a:1:{i:0;a:5:{s:4:”type”;s:4:”text”;s:8:”required”;s:2:”on”;s:5:”label”;s:9:”Full name”;s:4:”slug”;s:9:”full-name”;s:5:”extra”;a:0:{}}}’;delete_post_meta($ticket_id, ‘_tribe_tickets_meta_enabled’);
//replace “tpp_” with your wordpress database prefix
$wpdb->insert(‘tpp_postmeta’, array(
‘post_id’ => $ticket_id,
‘meta_key’ => ‘_tribe_tickets_meta_enabled’,
‘meta_value’ => $meta_enabled
));//ignore if enter already in – need to code
delete_post_meta($ticket_id, ‘_tribe_tickets_meta’);
$wpdb->insert(‘tpp_postmeta’, array(
‘post_id’ => $ticket_id,
‘meta_key’ => ‘_tribe_tickets_meta’,
‘meta_value’ => $metaval
));}
Jayson
ParticipantYou are right that the generic action of “save_post” needs to be implemented as well. I’m a bit stuck on how to find all of the ticket ids associated with an event:
//on event post save, add categories to all tickets function updated_ticket_product_cat( $post_id ) { //get categories $terms = get_the_terms($post_id, 'tribe_events_cat'); //Get ticket id $ticket_id="????????????????"; //add categories to tickets $count = count($terms); if ( $count > 0 ){ foreach ( $terms as $term ) { wp_set_object_terms( $ticket_id , $term->slug, 'product_cat', true ); } } } add_action( 'save_post', 'updated_ticket_product_cat' );Jayson
ParticipantHi Geoff
I got this one working. It might be worth including a simliar functionality in the plugin as it makes sense to me and helps with other woo reporting.
// add all tickets to a ticket category and then add the event category to the ticket product add_filter( 'wootickets_after_save_ticket', 'tribe_add_category_to_woocommerce_tickets' ); function tribe_add_category_to_woocommerce_tickets( $ticket_id ) { wp_set_object_terms( $ticket_id , 'Ticket', 'product_cat', true ); $event_REAL_id= get_post_meta( $ticket_id, '_tribe_wooticket_for_event', true ); $terms = get_the_terms($event_REAL_id, 'tribe_events_cat'); $count = count($terms); if ( $count > 0 ){ foreach ( $terms as $term ) { wp_set_object_terms( $ticket_id , $term->slug, 'product_cat', true ); } } }Jayson
ParticipantHi Geof
When an event ticket is created I want the related woocommerce product to be in a matching category. This code tries to do it twice:
1. Add product to a ‘ticket’ category – working
2. Add the events categories to the woocommerce product – not working
For example, if the event is in the ‘workshop’ event category we want the related ticket product to be in the ‘workshop’ product category.Does this make sense?
This code needs to find the event category array. I’m not sure where to find it
Thanks
Dan -
AuthorPosts
