Eagle Agency
Eagle Agency

Reputation: 167

WooCommerce: Order status based on Payment methods

On Woocommerce we have the option for BACS payments. Some orders are coming through as "Paid" and some aren't. I can't understand why as they are using the exact same payment method. The two images below will show you this:

Paid: enter image description here Not Paid: enter image description here

We are using a function to automatically change these payments from "On Hold" to "Processing", in case this may have something to do with the issue. The code is below:

add_action( 'woocommerce_thankyou', 'bacs_order_payment_processing_order_status', 10, 1 );

function bacs_order_payment_processing_order_status( $order_id ) {
if ( ! $order_id ) {
    return;
}

// Get an instance of the WC_Order object
$order = new WC_Order( $order_id );

if ( ( get_post_meta($order->id, '_payment_method', true) == 'bacs' || 'cod'  ) && ('on-hold' == $order->status || 'pending' == $order->status) ) {
    $order->update_status('processing');
}

else {
    return;
}
}

// change COD payment method order status from processing to on-hold
add_action('woocommerce_thankyou_cod', 'action_woocommerce_thankyou_cod', 10, 1);
function action_woocommerce_thankyou_cod($order_id)
{
    $order = wc_get_order($order_id);
    $order->update_status('processing');
}

Any help would be massively appreciated!

Upvotes: 2

Views: 3650

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253773

Your code is very outdated, confused with mistakes…

Instead, to change order status for payments like:

  1. Cash on delivery cod use (default status is "processing"):
  1. Cash on Cheque cheque use *(default status is "on-hold"):
  1. bank wire bacs use *(default status is "on-hold"):
  1. For other payment gateways use (default order status is related to each payment gateway and if there are shippable items or not):

Upvotes: 2

Related Questions