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"?
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' );
}
}
}
When using WC Moneris Payment Gateway in WooCommerce the payment ID defined for Moneris Payment Gateway is simply: moneris
.
This can be found on includes/class-wpheka-gateway-moneris.php plugin file (line 30): $this->id = 'moneris';
Now, based on How to autocomplete paid orders in WooCommerce? answer code, Here is the right way to autocomplete orders Paid through Moneris Payment Gateway:
add_filter( 'woocommerce_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3 );
function wc_auto_complete_paid_order( $status, $order_id, $order ) {
if ( $order->get_payment_method() === 'moneris' ) {
$status = 'completed';
}
return $status;
}
Code goes on functions.php file of your child theme (or in a plugin). It should work.