How to invoice Woocommerce customer the remainder balance amount for additional items to an already paid order
Right now it sends customer a new updated invoice with additional items added to his order an is asking the customer to pay for the full amount + the new Italy’s again.
When my customers place and pay for an order in Woocommerce. The payment is captured and authorized
The Order is “in processing” stage
If customer wants to add more items to the order he already paid for I change the the order to “on hold”. The add the items the customer wants to add. Then I recalculate total amount. Then change the order to “pending payment” then send customer the invoice.
But the invoice shows the complete order amount.
How do send the new invoice that shows the paid amount and the pending amount due
$50 is Customer original order
$20 is additional items added to the order
$70 is New total
Revised invoice would show All items (old and new)
$70 is new total amount -$50 paid amount $20 balance due
Customer would pay $20
How to invoice Woocommerce customer the remainder balance amount for additional items to an already paid order
Right now it sends customer a new updated invoice with additional items added to his order an is asking the customer to pay for the full amount + the new Italy’s again.
When my customers place and pay for an order in Woocommerce. The payment is captured and authorized
The Order is “in processing” stage
If customer wants to add more items to the order he already paid for I change the the order to “on hold”. The add the items the customer wants to add. Then I recalculate total amount. Then change the order to “pending payment” then send customer the invoice.
But the invoice shows the complete order amount.
How do send the new invoice that shows the paid amount and the pending amount due
$50 is Customer original order
$20 is additional items added to the order
$70 is New total
Revised invoice would show All items (old and new)
$70 is new total amount -$50 paid amount $20 balance due
Customer would pay $20
Share Improve this question asked Jul 6, 2019 at 6:09 oscaroscar 231 silver badge6 bronze badges1 Answer
Reset to default 0I think you can detect order status change and store the current order total to be used as negative fee so that it can be deducted from order total before calculating total.
To make it less confusing the code should be something like this:
add_action('woocommerce_order_status_changed', 'add_credit_fee_if_editing', 10,3);
function add_credit_fee_if_editing($order_id, $old_status, $new_status) {
$order = wc_get_order( $order_id );
$order_total = $order->get_total();
if($old_status == 'processing' && $new_status == 'on-hold') {//I am not sure about the 'on-hold' status's slug so verify that for yourself.
$order->update_meta_data( '_creditable_amount', $order_total );
}
if($old_status == 'on-hold' && $new_status == 'processing') {//I am not sure about the 'on-hold' status's slug so verify that for yourself.
$order_credit = $order->get_meta('_creditable_amount', true);
if($order_total > $order_credit) {
$credit = -1 * $order_credit;
$order->add_fee('Credit', $credit);
$order->calculate_totals();
$order->update_meta_data( '_creditable_amount', 0);
}
}
}
I think that this should work.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745341518a4623348.html
评论列表(0条)