Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Virtual Products on Packing Slips

  • Resolved WbDweb

    (@wbdweb)



    Hi Ewout,

    I bought your great WooCommerce PDF Invoices & Packing Slips Professional.
    In the shop where I use this plugin, my cliënt sells ‘simpel products’ that need to be shipped, but ‘virtual products’ as well.
    When a client buys products of both categories, the packing slip also shows the virtual products, although they can’t be shipped. 🙂

    Is there a way to solve this issue?

    Kind regards, Erik

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ewout

    (@pomegranate)

    Hello Erik,
    That’s possible but you need a small code snippet to do that. This code removes downloadable / virtual items from the packing slip:

    
    add_filter( 'wpo_wcpdf_order_items_data', 'wpo_wcpdf_remove_downloadable_ite', 10, 2 );
    function wpo_wcpdf_remove_downloadable_items ( $items_data, $order ) {
        global $wpo_wcpdf;
        if ( $wpo_wcpdf->export->template_type == 'packing-slip' ) {
            foreach ($items_data as $key => $item) {
                // Check if product is downloadable or virtual
                if ( !empty($item['product']) && ( $item['product']->is_downloadable() || $item['product']->is_virtual() ) ) {
                    // if true - remove item from packing slip
                    unset( $items_data[$key] );
                }
            }
        }
        return $items_data;
    }
    

    This code goes into your theme functions – if you haven’t worked with code snippets like that before, follow this guide: How to use filters

    Let me know if you have any other questions!

    Ewout

    Hi Ewout,

    Thanks for your quick response; great!
    I dropped this code in the functions.php-file of my child-team.
    It works, but not only my virtual products disappeared, the non-virtual ‘simpel products’ were gone too.
    I discoverd there’s a small incorrectness in your code (first line):
    wpo_wcpdf_remove_downloadable_items (“ms” was missing).
    After correction is does exactly what I needed.
    Thanks again!

    Kind regards, Erik

    Plugin Author Ewout

    (@pomegranate)

    Hi Erik,
    Thanks for the feedback, I didn’t notice that (not sure how that got left out!).

    For anyone else who wants to do this, use the following code instead:

    
    add_filter( 'wpo_wcpdf_order_items_data', 'wpo_wcpdf_remove_downloadable_items', 10, 2 );
    function wpo_wcpdf_remove_downloadable_items ( $items_data, $order ) {
        global $wpo_wcpdf;
        if ( $wpo_wcpdf->export->template_type == 'packing-slip' ) {
            foreach ($items_data as $key => $item) {
                // Check if product is downloadable or virtual
                if ( !empty($item['product']) && ( $item['product']->is_downloadable() || $item['product']->is_virtual() ) ) {
                    // if true - remove item from packing slip
                    unset( $items_data[$key] );
                }
            }
        }
        return $items_data;
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Virtual Products on Packing Slips’ is closed to new replies.