• Resolved LoicTheAztec

    (@lomars)


    Hello,

    Normally woocommerce should autocomplete orders for virtual products. but it doesn’t and this is a real problem, even a BUG like.

    So at this point you can find 2 helpful things:
    1) 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.

    2) A plugin : WooCommerce Autocomplete Orders
    This plugin works for all payment methods, but not for other Credit Card gateways payment methods.

    My question (could be the solution) :
    Using (as a base) the wooCommerce snippet in point 1:
    How can i implement conditional code based on payment methods, i mean something like : if the payment methods aren’t “BACS”, “Pay on delivery” and “Cheque” then apply updated status “completed” for paid orders (concerning virtual products).
    I am not a wooCommerce mega expert coder, so i haven’t find yet how to target payment methods in woocommerce orders.

    Some help will be very nice.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Thread Starter LoicTheAztec

    (@lomars)

    Finally i have find a working solution, based on the wooCommerce snippet code.

    Here is the modificated working code:

    /**
     * AUTO COMPLETE PAID ORDERS IN WOOCOMMERCE
     */
    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;
        }
    
        // (need those two for "get_post_meta()" function).
        global $woocommerce;
        $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 Orders with all others payment methods
        else {
        	$order->update_status( 'completed' );
        }
    }

    I have tested many times, it works for me…

    I you have any suggestion, go on.

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Auto Complete virtual Orders depending on Payment methods’ is closed to new replies.