Skip to content

Commit 4e76c92

Browse files
committed
Fix charge capture for WC 2.1+
Order status was being changed back to on-hold due to `woocommerce_process_shop_order_meta` not existing in 2.1+. Also fixed stock being incorrectly reduced for a charge capture, as the stock is reduced when the charge is authorized.
1 parent dd6d97a commit 4e76c92

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

woocommerce/payment-gateway/class-sv-wc-payment-gateway-direct.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,19 @@ public function do_credit_card_capture( $order ) {
697697
$order->add_order_note( $message );
698698

699699
// complete the order. since this results in an update to the post object we need to unhook the save_post action, otherwise we can get boomeranged and change the status back to on-hold
700-
remove_action( 'woocommerce_process_shop_order_meta', 'woocommerce_process_shop_order_meta', 10, 2 );
700+
if ( SV_WC_Plugin_Compatibility::is_wc_version_gte_2_1() ) {
701+
702+
// WC 2.1+
703+
remove_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2 );
704+
} else {
705+
706+
// WC 2.0
707+
remove_action( 'woocommerce_process_shop_order_meta', 'woocommerce_process_shop_order_meta', 10, 2 );
708+
}
709+
710+
// prevent stock from being reduced when payment is completed as this is done when the charge was authorized
711+
add_filter( 'woocommerce_payment_complete_reduce_order_stock', '__return_false', 100 );
712+
701713
$order->payment_complete();
702714

703715
// add the standard capture data to the order

0 commit comments

Comments
 (0)