Created
July 28, 2021 21:14
-
-
Save BrianHenryIE/9fee343c35eadfa2720f018201cf12d5 to your computer and use it in GitHub Desktop.
Fix WooCommerce Product Bundles to appear as individual items in Print Invoices & Packing Lists' packing lists.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @see https://woocommerce.com/products/print-invoices-packing-lists/ | |
* @see https://woocommerce.com/products/product-bundles/ | |
*/ | |
$show_bundled_items_individually_in_packing_lists = function( string $type, \WC_PIP_Document $document, \WC_Order $order ) { | |
if ( 'packing-list' !== $type ) { | |
return; | |
} | |
// Nothing to do. | |
if( !class_exists(\WC_PB_PIP_Compatibility::class )) { | |
return; | |
} | |
/** | |
* @see \WC_PIP_Document::get_table_row_order_item_data() | |
*/ | |
$hide_product_bundle_items = function( bool $visible, \WC_Order_Item_Product $item, string $type ) { | |
$product = $item->get_product(); | |
if ( $product instanceof \WC_Product_Bundle ) { | |
return false; | |
} | |
return $visible; | |
}; | |
add_filter( 'wc_pip_order_item_visible', $hide_product_bundle_items, 10, 3 ); | |
/** | |
* Remove the hooks added by WooCommerce Product Bundles. | |
* | |
* @see \WC_PB_PIP_Compatibility::init() | |
*/ | |
remove_action( 'wc_pip_before_body', array( \WC_PB_PIP_Compatibility::class, 'before_body' ), 10 ); | |
remove_action( 'wc_pip_after_body', array( \WC_PB_PIP_Compatibility::class, 'after_body' ), 10 ); | |
remove_filter( 'wc_pip_order_items_count', array( \WC_PB_PIP_Compatibility::class, 'items_count' ), 1000 ); | |
remove_filter( 'wc_pip_document_table_row_item_data', array( \WC_PB_PIP_Compatibility::class, 'row_item_data' ), 10 ); | |
remove_filter( 'wc_pip_document_table_rows', array( \WC_PB_PIP_Compatibility::class, 'table_rows' ), 52 ); | |
remove_filter( 'wc_pip_document_table_product_class', array( \WC_PB_PIP_Compatibility::class, 'bundled_item_class' ), 10 ); | |
remove_filter( 'wc_pip_order_item_name', array( \WC_PB_PIP_Compatibility::class, 'bundled_item_name' ), 10 ); | |
remove_action( 'wc_pip_order_item_meta_end', array( \WC_PB_PIP_Compatibility::class, 'add_assembled_order_item_meta' ), 10 ); | |
remove_filter( 'wc_pip_packing-list_hide_virtual_item', array( \WC_PB_PIP_Compatibility::class, 'hide_item' ), 10 ); | |
remove_filter( 'wc_pip_packing-list_list_group_item_as_uncategorized', array( \WC_PB_PIP_Compatibility::class, 'group_bundled_items_as_uncategorized' ), 10 ); | |
remove_action( 'wc_pip_styles', array( \WC_PB_PIP_Compatibility::class, 'add_styles' ) ); | |
}; | |
/** | |
* @see woocommerce-pip/templates/pip/head.php | |
*/ | |
add_action( 'wc_pip_head', $show_bundled_items_individually_in_packing_lists, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment