• Resolved cfooks

    (@cfooks)


    Hello, I am surprised that this is not offered natively with the “Woocommerce Bundle” plugin but I would like to avoid order preparation errors to hide the lines of the parent products on the picking-list and invoices.

    I started a code but it does the opposite of what I want, namely that it hides the child products but leaves the parent product.

    Can you help me?

    add_filter('wpo_wcpdf_order_items_data', 'wpo_wcpdf_remove_bundle', 10, 3);

    function wpo_wcpdf_remove_bundle($items, $order, $document_type) {
    // Types de document où les produits en bundle doivent être supprimés
    $remove_from = ['invoice', 'packing-slip'];

    if (in_array($document_type, $remove_from)) {
    foreach ($items as $item_id => $item) {
    // Vérifiez si l'article est un produit bundle
    if (isset($item['data']) && $item['data'] instanceof WC_Product_Bundle) {
    // Si c'est un produit bundle, supprimez-le
    unset($items[$item_id]);
    }
    }
    }

    return array_values($items); // Réindexez les clés du tableau après la suppression
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor dwpriv

    (@dwpriv)

    We could hide the items with CSS in a code snippet. You’d have to find the CSS handler for the parent item, though. You can use this guide to inspect the HTML of the document for it.

    You can then add this snippet and replace the CSS selector with the one you found when inspecting the HTML

    /**
    * Hide parent bundle item
    */
    /*
    add_action( 'wpo_wcpdf_custom_styles', function( $document_type, $document ) {
    if ( $order = $document->order ) {
    ?>
    .product-bundle {
    display: none;
    }
    <?php
    }
    }, 10 , 2 );
    Plugin Contributor dwpriv

    (@dwpriv)

    Since we haven’t heard from you in a while, I will mark this topic as resolved. Feel free to reopen it if you still need more help, or open another thread if you need help with something else.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.