Plugin Author
bfl
(@bfl)
You can use the following snippet:
add_action( 'admin_enqueue_scripts', function ( $hook ) {
if ( $hook === 'woocommerce_page_wc-orders' ) {
?>
<script>
function confirmManualPayment( event ) {
event.preventDefault();
if (
( event.type === 'keypress' && event.keyCode === 13 && event.target?.matches( '#charge *' ) ) ||
( event.type === 'click' && event.target?.id === 'charge-btn' )
) {
if ( jQuery( '#_transaction_id' ).val() ) {
if ( ! confirm( 'There is already a payment on this order. Would you like to proceed?' ) ) {
event.stopPropagation();
}
}
}
}
document.addEventListener( 'keypress', confirmManualPayment, true );
document.addEventListener( 'click', confirmManualPayment, true );
</script>
<?php
}
} );
This will only work if the customer paid using a payment method that fills out the WooCommerce Transaction ID field (which you can see when editing Billing fields on the order screen). It determines whether a payment has been made by checking if that field is filled out. If you use other payment methods that don’t use that field, you’ll need to determine whether the order has been paid by some other check. Gateways like Stripe use that field.
Also, this snippet depends on some internal implementation details of WooCommerce and Woo MP, so it may need to be updated if either plugin changes something relevant.
Thanks for the reply @bfl , in looking at the code, if they have been on that page and the payment came through while they were sitting on the page, will this retrieve the transaction id from the database or are you expecting it to be in the current page? My concern is that we might have a race condition if they don’t refresh the page and the data in the current order on the page isn’t loaded.
Let me know what you think or if you think this covers that scenario.
Plugin Author
bfl
(@bfl)
That snippet does not cover that scenario. It would be more complicated to cover that.