Viewing 15 replies - 1 through 15 (of 25 total)
  • You can set all that in settings now.

    Thread Starter tom80550

    (@tom80550)

    unfortunately I can not find

    Thread Starter tom80550

    (@tom80550)

    i want to remove orders instant if is failed

    Why? What if the customer is still in the process of purchasing? You’re going to make them start all over? That’s not a good customer experience at all.

    Thread Starter tom80550

    (@tom80550)

    my payment module and mercanet (module of my bank)

    I use woocommerce with a reservation system for places in a boat, if an order is not paid, the places remains blocked.

    I need to delete the commands failed to be able to unlock the places to lock

    I just need to do:
    if order = failed -> delete order

    Got it.

    Maybe see if this works for you.
    https://www.ads-software.com/plugins/woo-cancel-abandoned-order/

    If that doesn’t work for you you might want to test this. I’ve set it to delete in one minute.

    add_action( 'woocommerce_order_status_failed', 'the_serafin_woocommerce_auto_delete_order' );
    
    function the_serafin_woocommerce_auto_delete_order( $order_id ) {
        // 5*60 = 300 seconds. Here 1minute = 60 seconds.
        wp_schedule_single_event(tim() + 300, 'the_serafin_main_delete_event', $order_id);
    }
    
    function the_serafin_main_delete_event( $order_id ) {
        global $woocommerce;
        $order = new WC_Order( $order_id );
        $order_status = $order->get_status();
        if ( !$order_id )
            return false;
        if ('cancelled' == $order_status || 'failed' == $order_status ||   'pending' == $order_status ) {
            wp_delete_post($order_id,true);
            return true;
        }
        return false;
    }
    Thread Starter tom80550

    (@tom80550)

    oh thx
    the plugins not work for me i have already test

    on my fuction.php ?

    Yes, on your functions file. Advise not to add thru Editor. Use FTP if at all possible.

    Thread Starter tom80550

    (@tom80550)

    yes
    i go try thx you

    Welcome

    Thread Starter tom80550

    (@tom80550)

    I just added the code in my function.php but the oders remains Failed

    https://i.gyazo.com/8a63d9843451040c85b573114b03dc4d.png

    code :

    https://i.gyazo.com/b2e18808033d76e91c7498b86ceccb98.png

    • This reply was modified 5 years, 10 months ago by tom80550.

    I reviewed latest in wc post data. Maybe I’m missing something. I’ll ask my partner if he has any idea.

    I rewrote it as well

    
    add_action( 'woocommerce_order_status_failed', 'woocommerce_auto_delete_order' );
    
    function woocommerce_auto_delete_order( $order_id ) {
        // 5*60 = 300 seconds. Here 1 minute = 60 seconds.
        wp_schedule_single_event(tim() + 60, 'main_delete_event', $order_id);
    }
    
    function main_delete_event( $order_id ) {
        global $woocommerce;
        $order = new WC_Order( $order_id );
        $order_status = $order->get_status();
        if ( !$order_id )
            return false;
        if ('failed' == $order_status ) {
            wp_delete_post($order_id,true);
            return true;
        }
        return false;
    }
    

    I can’t test on local right now. Sorry. Forgot my demo login creds.

    Sorry forgot to add an action. Hope you didn’t see yet. Now is good.

    Thread Starter tom80550

    (@tom80550)

    thx for your help

    but the orders remain in the list
    ttps://i.gyazo.com/5f6969ee857a9bee17996541017f4fe9.png

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘how to remove failed orders auto’ is closed to new replies.