• Resolved diggital2016

    (@diggital2016)


    Hi, we use WooCommerce Bookings and these bookable products settings: “Virtual” and “Has Persons”, which means that we use it for creating/adding the amount of a product with Min. and Max. booking options.

    It works fine, but in the booking list it displays always the amount “1” and as an extra our “Has Persons”-note.

    Is there any chance to get this extra information displayed in the packing slip? Now we have to correct any packing slip manually (printed and change the amount).

    Is it possible to extend the footer height? We want to place 4 lines of text and the layout always cuts off the last line.

    Best regards,
    Dirk

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.

    Thread Starter diggital2016

    (@diggital2016)

    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 6 years ago by kluver.
    Thread Starter diggital2016

    (@diggital2016)

    Hi @kluver,

    this works great!!!
    Thanks a lot, you made my day ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Quantity in packing slips’ is closed to new replies.