Skip to content

Commit 9b177f2

Browse files
committed
Fix #150
1 parent 74304f6 commit 9b177f2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

woocommerce-delivery-notes/includes/wcdn-template-functions.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,28 @@ function wcdn_print_extra_fields( $item ) {
640640
}
641641

642642
}
643+
644+
/**
645+
* Function to show the correct quantity on the frontend when Composite/Bundle products are there.
646+
*
647+
* @param int $count Total Quantity.
648+
* @param string $type Item Type.
649+
* @param WC_Order $order Order object.
650+
*/
651+
function wcdn_order_item_count( $count, $type, $order ) {
652+
global $wp;
653+
// Check that print button is been clicked or not.
654+
if ( ! empty( $wp->query_vars['print-order'] ) ) {
655+
if ( in_array( 'woocommerce-composite-products/woocommerce-composite-products.php', apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ), true ) || in_array( 'woocommerce-product-bundles/woocommerce-product-bundles.php', apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ), true ) ) {
656+
if ( function_exists( 'is_account_page' ) && is_account_page() ) {
657+
$count = 0;
658+
foreach ( $order->get_items() as $item ) {
659+
$count += $item->get_quantity();
660+
}
661+
}
662+
}
663+
}
664+
return $count;
665+
}
666+
add_filter( 'woocommerce_get_item_count', 'wcdn_order_item_count', 20, 3 );
643667
?>

0 commit comments

Comments
 (0)