Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Last active July 29, 2026 09:38
Show Gist options
  • Select an option

  • Save webtoffee-git/c87c8822848bb3cedc2c5dfbaf829f73 to your computer and use it in GitHub Desktop.

Select an option

Save webtoffee-git/c87c8822848bb3cedc2c5dfbaf829f73 to your computer and use it in GitHub Desktop.
Code to correct line total in withdrawal dashboard - By WebToffee
<?php //Do not add this line of code
function wt_dashboard_item_withdrawal_total( $total, $line_item, $order, $request ) {
if ( ! $request instanceof Wbte_Ewb_Request || ! $line_item instanceof WC_Order_Item_Product ) {
return $total;
}
$ordered_qty = (int) $line_item->get_quantity();
if ( $ordered_qty < 1 ) {
return $total;
}
$line_item_id = (int) $line_item->get_id();
$withdrawal_qty = 0;
foreach ( $request->get_items() as $item ) {
$item_line_id = isset( $item['line_item_id'] ) ? absint( $item['line_item_id'] ) : 0;
if ( $item_line_id !== $line_item_id ) {
continue;
}
if ( isset( $item['withdrawal_qty'] ) ) {
$withdrawal_qty = absint( $item['withdrawal_qty'] );
} elseif ( isset( $item['qty'] ) ) {
$withdrawal_qty = absint( $item['qty'] ); // items_json stores withdrawal qty here.
} elseif ( isset( $item['quantity'] ) ) {
$withdrawal_qty = absint( $item['quantity'] );
}
break;
}
if ( $withdrawal_qty < 1 ) {
return $total;
}
$unit_price = (float) $total / $ordered_qty;
$withdrawal_total = $unit_price * $withdrawal_qty;
return wc_format_decimal( $withdrawal_total, '' );
}
add_filter( 'wbte_ewb_dashboard_item_line_total', 'wt_dashboard_item_withdrawal_total', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment