Plugin Contributor
kluver
(@kluver)
Hi @diggital2016,
You could add the person count to the item meta with a small code snippet:
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_add_person_count', 10, 3 );
function wpo_wcpdf_add_person_count ( $template_type, $item, $order ) {
if ( $template_type == 'packing-slip' && is_callable( 'WC_Booking_Data_Store::get_booking_ids_from_order_id') ) {
$booking_data = new WC_Booking_Data_Store();
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order->get_id() );
foreach ( $booking_ids as $booking_id ) {
$booking = new WC_Booking( $booking_id );
$product_id = $booking->get_product_id();
if ( $booking->get_order_item_id() == $item['item_id'] ) {
$product = wc_get_product( $product_id );
$person_types = $product->get_person_types();
$person_counts = $booking->get_person_counts();
foreach ( $person_counts as $person_id_count => $person_count ) {
foreach ( $person_types as $person_id_type => $person_type ) {
if ( $person_id_count == $person_id_type ) {
echo sprintf("<span class='booking-variation'>%s - %sx<br></span>", $person_type->get_name(), $person_count );
}
}
}
}
}
}
}
This code snippet should be placed in the functions.php of your child theme. If you have never worked with code snippets or functions.php before please read this: How to use filters
The footer height can be adjusted in the plugin settings (WooCommerce > PDF Invoices > General > Footer height)
Plugin Contributor
kluver
(@kluver)
Hi @diggital2016,
If you want more booking data to show on your documents an even easier solution is to purchase our Premium Templates extension. Just select the ‘Show external plugin data’ option in the Product block in the customizer. This gives you everything you need.
What you don’t want to show you can easily hide with some CSS which you can also add in the customizer.
Hi @kluver,
thanks for your solution! It works great and adds one line below the product title in the left part of the packing slip, but the quantity in the right part is still “1”.
Is it possible to check something like “if ‘has persons’ take this as the quantity number”?
I couldn’t find settings for the footer height, but changed it in the templates’ style.css and this worked great as well.
Plugin Contributor
kluver
(@kluver)
Hi @diggital2016,
My apologies. If you need the quantity replaced with the person count of the booking you can use almost the same code as above but in combination with the wpo_wcpdf_order_item_data filter. Like this:
add_filter( 'wpo_wcpdf_order_item_data', 'wpo_wcpdf_order_item_data', 10, 3 );
function wpo_wcpdf_order_item_data( $data, $order, $template_type ) {
if ( $template_type == 'packing-slip' && is_callable( 'WC_Booking_Data_Store::get_booking_ids_from_order_id') ) {
$booking_person_counts = "";
$booking_data = new WC_Booking_Data_Store();
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order->get_id() );
foreach ( $booking_ids as $booking_id ) {
$booking = new WC_Booking( $booking_id );
$product_id = $booking->get_product_id();
if ( $booking->get_order_item_id() == $data['item_id'] ) {
$product = wc_get_product( $product_id );
$person_types = $product->get_person_types();
$person_counts = $booking->get_person_counts();
foreach ( $person_counts as $person_id_count => $person_count ) {
foreach ( $person_types as $person_id_type => $person_type ) {
if ( $person_id_count == $person_id_type ) {
$booking_person_counts .= sprintf("<span class='booking-variation'>%s - %sx<br></span>", $person_type->get_name(), $person_count );
}
}
}
}
}
$data['quantity'] = !empty($booking_person_counts) ? $booking_person_counts : $data['quantity'];
}
return $data;
}
-
This reply was modified 7 years, 3 months ago by
kluver.
Hi @kluver,
this works great!!!
Thanks a lot, you made my day 🙂