K
K
Kirill Makarov2018-09-11 01:27:50
WordPress
Kirill Makarov, 2018-09-11 01:27:50

Code to automatically convert the status "pending payment" to the status "completed" for an order in a store on the woocomerce platform?

hello, can you please help
, it is necessary that when the status of the order is "pending payment" the system itself transfers it to the status "completed"
I insert this code into functions.php

function wc_mark_all_orders_as_complete( $order_status, $order_id ) { 
$order = wc_get_order( $order_id ); 
if ( $order_status == 'processing' && in_array( $order->get_status(), array( 'on-hold', 'pending', 'failed' ) ) ) { 
return 'completed'; 
} 
return $order_status; 
} 
add_filter( 'woocommerce_payment_complete_order_status', 'wc_mark_all_orders_as_complete', 10, 2 );

but it still does not translate into the status completed automatically, could you tell me why, I will be very, very grateful to you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mofsy, 2018-09-19
@Mofsy

I don't know where you got your code from, but it's fundamentally wrong.

function wc_mark_all_orders_as_complete( $order_id ) { 
    $order = wc_get_order( $order_id ); 
    $order->payment_complete();
} 
add_action( 'woocommerce_order_status_pending', 'wc_mark_all_orders_as_complete' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question