• I’ve setup my orders virtual and made them mark as complete automatically. now i need a way to delete them from woocommerce orders once its marked complete. i’ve added a code from woocommerce api, but obviously i may have configured it wrong.

    Here’s the code

    add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
    function custom_woocommerce_auto_complete_order( $order_id ) {
        global $woocommerce;
    
        if ( !$order_id )
            return;
        $order = new WC_Order( $order_id );
        $order->update_status( 'completed' );
        // the below part i've added as in the woocommerce api//
        wc_delete_shop_order_transients( $order );
        do_action( 'woocommerce_api_delete_order', $order, $this );
        return $this->delete( $order, 'order',  ( 'false' === $force ) );
    }

  • The topic ‘Automatically remove completed orders (woocommerce)’ is closed to new replies.