From 04b19d11994aa83f92fcd96d393673cbaabf3a86 Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Sun, 8 Sep 2024 11:45:57 -0500 Subject: [PATCH] Add documentation to `mt_show_in_cart_fields` filter and add ticket type argument. --- src/mt-cart.php | 13 ++++++++++++- src/mt-fields-api.php | 5 +++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mt-cart.php b/src/mt-cart.php index dc654cc..a2bc4f4 100644 --- a/src/mt-cart.php +++ b/src/mt-cart.php @@ -993,7 +993,18 @@ function mt_generate_cart_table( $cart, $format = 'cart' ) { $hidden = ''; } $total = $total + ( $price * $count ); - $custom = apply_filters( 'mt_show_in_cart_fields', '', $event_id ); + /** + * Show custom fields associated with individual cart items. + * + * @hook mt_show_in_cart_fields + * + * @param {string} $fields HTML output of displayed fields. Default empty. + * @param {int} $event_id The event currently displayed. + * @param {string} $type The current ticket type. + * + * @return {string} + */ + $custom = apply_filters( 'mt_show_in_cart_fields', '', $event_id, $type ); // Translators: (number of tickets) at (price per ticket). $cart_message = sprintf( __( '%1$s at %2$s', 'my-tickets' ), "$count", apply_filters( 'mt_money_format', $price ) ); $output .= " diff --git a/src/mt-fields-api.php b/src/mt-fields-api.php index fd4dcc5..595a914 100644 --- a/src/mt-fields-api.php +++ b/src/mt-fields-api.php @@ -23,7 +23,7 @@ function mt_add_actions() { // Save field data to cookie/user meta for use in cart. add_action( 'mt_add_to_cart_ajax_field_handler', 'mt_handle_custom_field', 10, 2 ); // Display field data in shopping cart. - add_filter( 'mt_show_in_cart_fields', 'mt_show_custom_field', 10, 2 ); + add_filter( 'mt_show_in_cart_fields', 'mt_show_custom_field', 10, 3 ); // Insert submitted data into Payment post meta. add_action( 'mt_save_payment_fields', 'mt_insert_custom_field', 10, 3 ); // Display field data in tickets list. @@ -245,10 +245,11 @@ function mt_handle_custom_field( $saved, $submit ) { * * @param string $content Shopping cart html. * @param int $event_id Event ID. + * @param string $type Ticket type for this line item. * * @return string */ -function mt_show_custom_field( $content, $event_id ) { +function mt_show_custom_field( $content, $event_id, $type ) { $custom_fields = mt_get_custom_fields( 'display' ); $return = ''; foreach ( $custom_fields as $name => $field ) {