2
votes

I am making a simple e-commerce website using WooCommerce plugin on Wordpress. I am using Paypal as my payment gateway. When user is purchasing product from my store and give payment successfully, WooCommerce should automatically change order status from 'pending' to 'completed', but it is not changing order status.

How can I achieve this?

1
till the time paypal does not approves your order, and you get a succesfull payment message that is not possible - Nehal
and if then also, you want it to be done search for payment option in your directory, there you can set hardcoded - Nehal
So, Do I have to change order status manually? - Mohammad Tasneem Faizyab

1 Answers

3
votes

This is a snippet code (that you can find in wooCommerce docs):

/**
 * Auto Complete all WooCommerce orders.
 */
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order');
function custom_woocommerce_auto_complete_order( $order_id ) {
    if ( ! $order_id ) {
        return;
    }

    $order = wc_get_order( $order_id );
    $order->update_status( 'completed' );
}

But this snippet does not work for "BACS", "Pay on delivery" and "Cheque" payment methods. It's ok for Paypal and Credit Card gateways payment methods.

There is also a wordpress (woocommerce) free plugin working with all payment methods except some others Credit Card gateways payment methods:

Auto complete paid Orders (depending on Payment methods)

WooThemes - WooCommerce Autocomplete Orders

Regards