Recently I ran into a situation where an order had not been marked “paid” even though the customer did actually pay for the order with the payment processor. Something had failed in the communication and the order status was updated to processing but the note indicating the transaction ID was missing and the order wasn’t marked “paid.”
After looking at this for a bit, I realized there’s not an easy way to mark this order “paid” from the admin. You could enable the “Check Payments” gateway and set the order to use it. Then toggle the status to “pending payment” and back to “completed” to mark the order as paid.
I wanted a more targeted way to do this so I created a quick plugin that adds an order action to mark an order “paid.” Here’s the code if you want to give it a try on your own site.
<?php
/**
* Plugin Name: WooCommerce Mark Order as Paid Action
* Description: Adds an order action to manually mark orders as paid
* Author: Bill Robbins
* Version: 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class WC_Mark_Order_Paid {
/**
* Constructor
*/
public function __construct() {
add_filter( 'woocommerce_order_actions', [ $this, 'add_order_action' ], 10, 2 );
add_action( 'woocommerce_order_action_mark_paid', [ $this, 'handle_order_action' ] );
}
/**
* Add mark as paid action to order actions dropdown
*
* @param array $actions Order actions
* @param WC_Order $order Order object
* @return array Modified actions
*/
public function add_order_action( array $actions, WC_Order $order ): array {
if ( ! $order->is_paid() ) {
$actions['mark_paid'] = __( 'Mark as Paid', 'woocommerce' );
}
return $actions;
}
/**
* Handle the mark as paid action
*
* @param WC_Order $order Order object
*/
public function handle_order_action( WC_Order $order ) {
$order->add_order_note( __( 'Order manually marked as paid by admin.', 'woocommerce' ), false, true );
$order->payment_complete();
}
}
// Initialize the plugin
new WC_Mark_Order_Paid();




Leave a Reply