Skip to content

Instantly share code, notes, and snippets.

@dennisnissle
Created May 7, 2024 10:29
Show Gist options
  • Save dennisnissle/d059c3225db4ea0ae4b6292e649e3cc2 to your computer and use it in GitHub Desktop.
Save dennisnissle/d059c3225db4ea0ae4b6292e649e3cc2 to your computer and use it in GitHub Desktop.
Display WooCommerce Appointments data for invoice items by using [document_item_reference data="woocommerce_appointments"]
<?php
add_filter( 'storeabill_shortcode_get_document_item_reference_data', function( $result, $atts, $reference, $shortcodes ) {
if ( 'woocommerce_appointments' === $atts['data'] && class_exists( 'WC_Appointment_Data_Store' ) ) {
$item = $reference->get_object();
if ( is_a( $item, 'WC_Order_Item_Product' ) ) {
$appointment_ids = WC_Appointment_Data_Store::get_appointment_ids_from_order_and_item_id( $item->get_order_id(), $item->get_id() );
foreach ( $appointment_ids as $appointment_id ) {
$appointment = get_wc_appointment( $appointment_id );
// Don't proceed if ID is not of a valid appointment.
if ( ! is_a( $appointment, 'WC_Appointment' ) ) {
continue;
}
ob_start();
wc_appointments_get_summary_list( $appointment );
$result = ob_get_clean();
}
}
}
return $result;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment