• 10
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Update 2 - 2019: Use WooCommerce: Auto complete paid orders (updated thread)

So the right hook to use is woocommerce_payment_complete_order_status filter returning complete


Update 1: Compatibility with WooCommerce version 3+

I have changed the answer

Based on: WooCommerce - Auto Complete paid virtual Orders (depending on Payment methods), you will be able to handle also all payment methods in conditionals:

// => not a filter (an action hook)
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_paid_order', 10, 1 );
function custom_woocommerce_auto_complete_paid_order( $order_id ) {
    if ( ! $order_id )
        return;

    $order = new WC_Order( $order_id );

    // No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
    if ( get_post_meta($order_id, '_payment_method', true) == 'bacs' || get_post_meta($order_id, '_payment_method', true) == 'cod' || get_post_meta($order_id, '_payment_method', true) == 'cheque' ) {
        return;
     }
    // "completed" updated status for paid "processing" Orders (with all others payment methods)
    elseif ( $order->has_status( 'processing' ) ) {
        $order->update_status( 'completed' );
    }
    else {
        return;
    }
}
  • 11
Reply Report
      • 1
    • Thank you, but I don't really need to check the payment method, I got only one. But I had a new problem. I would like to change an order status not after accessing to the thank you page, but at the moment when the status is changed to 'processing'. Sometimes it happens that customer don't come back to my store, after the payment is accepted. Do u have any clue?

The function woocommerce_thankyou is an action. You're required to use add_action function to hook into it. I would recommend changing the priority to 20 so that other plugins/code changes may be applied before update_order_status.

add_action( 'woocommerce_thankyou', 'update_order_status', 20);
  • 4
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions