Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 352 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WooCommerce change order status BACS processing

#1
In WooCommerce any order placed with the BACS (direct bank transfer) is set to **`"on-hold"`**.

How would one go about changing this automatically to processing?

I wan't it to work inside the **`functions.php`**

I have the following code but that doesn't work:

add_filter( 'woocommerce_payment_complete_order_status', 'rfvc_update_order_status', 10, 2 );

function rfvc_update_order_status( $order_status, $order_id ) {
$order = new WC_Order( $order_id );
if ( 'on-hold' == $order_status && 'on-hold' == $order->status ) {
return 'processing';
}
return $order_status;
}

Any help would be great!
Reply

#2
Try changing the code to this:

function rfvc_update_order_status( $order_status, $order_id ) {
$order = new WC_Order( $order_id );
if ( 'on-hold' == $order_status && 'on-hold' == $order->status ) {
$order->update_status('processing', 'order_note');
}
return $order_status;
}

The key change here is this:

$order->update_status('processing', 'order_note');

You can add order note too if you prefer.
Reply

#3
There is a new filter which will allow you to set the status when BACS 'payment' is processed.

/**
* Change the default status when BACS 'payment' is processed.
*
* @see WC_Gateway_BACS::process_payment()
* woocommerce/includes/gateways/bacs/class-wc-gateway-bacs.php:362
* @since Mar 8, 2018
* @link

[To see links please register here]

*
* @filter woocommerce_bacs_process_payment_order_status
* @priority 10
* @args 2
*
* @param string $status Status to filter. Default 'on-hold'.
* @param WC_Order $order
* @return string New status 'processing'.
*/
add_filter( 'woocommerce_bacs_process_payment_order_status', function( $status = 'on_hold', $order = null ) {
return 'processing';
}, 10, 2 );
Reply

#4
**New 2020 update**

WooCommerce version 3.4 has introduced a much better hook than `woocommerce_thankyou` or `woocommerce_thankyou_bacs`, that allows to change the default order status for BACS payment method.

Using this hook will:

- clearly lighten the necessary code,
- avoid "on-hold" notification to the customer when a BACS order is placed.

So use instead the following:
```php
add_filter( 'woocommerce_bacs_process_payment_order_status','filter_bacs_process_payment_order_status_callback', 10, 2 );
function filter_bacs_process_payment_order_status_callback( $status, $order ) {
return 'processing';
}
```
Code goes in functions.php file of the active child theme (or active theme). Tested and works.

------

Original answer:

> **Update** *(added a version for woocommerce 3+ at the end)*

It seems that `woocommerce_payment_complete_order_status` action hook doesn't trigger with BACS payment method.

Based on [this thread][1], `'woocommerce_thankyou'` action hook does the job:

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' ) && ('on-hold' == $order->status || 'pending' == $order->status) ) {
$order->update_status('processing');
} else {
return;
}
}

Code goes in function.php file of your active child theme (or active theme). tested and works.

------

**For woocommerce 3+ versions:**

Here we use the similar composite hook [`woocommerce_thankyou_{$order->get_payment_method()}`][2]:

add_action( 'woocommerce_thankyou_bacs', '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 = wc_get_order( $order_id );

if ( in_array( $order->get_status(), array('on-hold', 'pending') ) ) {
$order->update_status('processing');
} else {
return;
}
}

Code goes in function.php file of your active child theme (or active theme). tested and works.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through