• Resolved addictivemerch

    (@addictivemerch)


    We use WPC Product Bundles to offer bundles of products to our customers. We currently hide the “Parent” bundle item from our packing slips as it serves no other purpose than to group these up for the customer. The packing team don’t require them.

    However the packing list still has the entire parent bundle name ahead of the bundled product name, as shown in this example.

    https://gyazo.com/b9fb973f6b612ece88b1b0a28c6fd45d

    How would we go about removing all of the red part (the bundle name and missing unicode ‘→’ symbol)? I’ve tried editing the PDF template but with the text all being encoded in ASCII, it’s difficult to simply split after the ‘→’ symbol.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Have you tried the settings in the WPC plugin? You can hide the bundle name, which will result in the output you want. It’s a general setting though, so it will also change the appearance of the bundle in the shopping cart and other elements.

    In the compatibility tab you can adjust some more settings: you can hide the bundle or the bundled products. Unfortunately you cannot make different choices for the invoice and packing slip.

    I will probably dig into this, as I want only the bundle name on the invoice and only the bundled products on the packing slip. I guess it won’t be that hard to write some custom code using the existing choices.

    • This reply was modified 2 years, 11 months ago by elmersw.

    I’m almost there thanks to all contributors on various websites (including the support forums of WPC and WP Overnight). I’m working on the invoice first. The packing slip will be a piece of cake as soon as I got this working. I might need a little help with the last pieces. I got stuck with empty rows in the PDF…

    /**
     * Remove bundled items from invoice
     */
    add_filter( 'wpo_wcpdf_order_item_data', 'sw_modify_pdf_invoice', 10, 3 );
    function sw_modify_pdf_invoice( $items, $order, $document_type )
    {
    	if ($document_type == 'invoice') { // you can select 'invoice',  'packing-slip' or any other document type
    		foreach ( $items as $item_id => $item ) {
    
    			$bundled_product = wc_get_order_item_meta( $items['item_id'], '_woosb_parent_id', true );
    			if ( ! empty( $bundled_product ) ) {
    				// hide bundled products
    				unset ($items);
            		}
     		}
        	}
        return $items;
    };
    Plugin Contributor Ewout

    (@pomegranate)

    @elmersw to unset the row entirely, you can use the wpo_wcpdf_order_items_data filter instead of wpo_wcpdf_order_item_data (the latter is only meant to modify a single rows data and doesn’t allow you to remove rows).

    I think this should do the trick (but I can’t test this on my end, so please confirm):

    
    add_filter( 'wpo_wcpdf_order_items_data', 'sw_modify_pdf_invoice', 10, 3 );
    function sw_modify_pdf_invoice( $items, $order, $document_type )
    {
    	$remove_from = [ 'invoice', 'packing-slip' ];  // you can select 'invoice', 'packing-slip' or any other document type
    	if ( in_array( $document_type, $remove_from ) ) {
    		foreach ( $items as $item_id => $item ) {
    			$bundled_product = wc_get_order_item_meta( $item_id, '_woosb_parent_id', true );
    			if ( ! empty( $bundled_product ) ) {
    				// remove bundled products
    				unset( $items[$item_id] );
            	}
     		}
        }
        return $items;
    };
    

    Thanks a lot Ewout. After a good night sleep, it was already clear to me that the $items variable does not contain all items. Now I know why ??

    I have used the code you supplied and it works.

    Thread Starter addictivemerch

    (@addictivemerch)

    Thanks @elmersw, I was overlooking the “Hide bundle name before bundled products” toggle within the WPC settings. Who would have known it was so simple!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WPC Product Bundles – Hide parent/bundle item from child item names’ is closed to new replies.