I need someone to guide me very urgently!
I use WordPress with Woodmart theme and I want automatic orders to be completed.
I installed the codesnippets plugin and copied the following code from the codesnippet website:
But the order that was previously Processing is not completed!
What should I put the payment method where it says “Change the Payment Method” ?
Thanks for your help
Autocompleted WooCommerce order based on the payment method “Moneris Gateway”
add_action('woocommerce_order_status_changed', 'ts_auto_complete_by_payment_method');
function ts_auto_complete_by_payment_method($order_id)
{
if ( ! $order_id ) {
return;
}
global $product;
$order = wc_get_order( $order_id );
if ($order->data['status'] == 'processing') {
$payment_method=$order->get_payment_method();
if ($payment_method!="cod") // Change the Payment Method
{
$order->update_status( 'completed' );
}
}
}
hamid khayam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.