• Resolved ilfungo

    (@ilfungo)


    Hi I really am struggling with this “simple” feature. I sell courses and so after a payment the user should be able to enroll withouth any other requirement.
    I set the product as a virtual, but the order status will not be complete after payment.
    I try two different plugins, not working.
    Also I try some different codes like this

    add_action( 'woocommerce_payment_complete_order_status', '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' );
    }

    or this one

    add_action( 'woocommerce_thankyou', 'wc_auto_complete_paid_order', 20, 1 );
    function wc_auto_complete_paid_order( $order_id ) {
        if ( ! $order_id )
            return;
    
        // Get an instance of the WC_Product object
        $order = wc_get_order( $order_id );
    
        // No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
        if ( in_array( $order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '' ) ) ) {
            return;
        } 
        // For paid Orders with all others payment methods (paid order status "processing")
        elseif( $order->has_status('processing') ) {
            $order->update_status( 'completed' );
        }
    }
    with variations to get the order id
    global $order;
    $order_id = $order->get_order_number();
    $order = new WC_Order($post->ID);
    //to escape # from order id 
    $order_id = trim(str_replace('#', '', $order->get_order_number()));

    but is never working.
    Just installed 2 days ago and so everithing is at it very last version.
    Any suggestion?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Missy a11n

    (@m155y5)

    Automattic Happiness Engineer

    Hi @ilfungo

    You can just check the “downloadable” checkbox as well and it will autocomplete those orders. You don’t have to actually add a downloadable file.

    Alternatively, we do have documentation with a snippet that will autocomplete ALL WooCommerce orders here.

    Thread Starter ilfungo

    (@ilfungo)

    I try the snippet, it’s not working. I try to check “downloadable” and it’s not working. I also uninstall moowoodle. But it’s still not working. However the product is virtual, downloadable and at the same time I can see the order is payed and inside the order I have the paypal transaction number.

    • This reply was modified 4 years, 4 months ago by ilfungo.
    Plugin Support Missy a11n

    (@m155y5)

    Automattic Happiness Engineer

    @ilfungo – To be clear, did you test this on a new order? It will not apply to previous orders.

    Thread Starter ilfungo

    (@ilfungo)

    Hi I tested many many times oviously always on new orders.

    Plugin Support Missy a11n

    (@m155y5)

    Automattic Happiness Engineer

    Hi @ilfungo

    It should be working, so it’s possible that another of your plugins or your theme may be conflicting with WooCommerce. You can read more about plugin and theme conflicts in our Self-Service Guide.

    Here’s how you can figure out which one may be causing the problem:

    Before you start

    • First, please make sure you have a good backup in place of your full site and database. Most hosting companies have this included in the subscription, but you could also consider using a service like Jetpack. If something goes wrong, it’s nice to know that you can restore your site.
    • Second, I would suggest to install a plugin called Health Check & Troubleshooting. This is a plugin developed by the WordPress community and it allows you to disable plugins without effecting your current site visitors.

    How to test for conflicts
    In order to test for conflicts using Health Check & Troubleshooting:

    1. Go to Tools > Site Health > Troubleshooting.
    2. Select Enable Troubleshooting Mode. This will disable all your plugins and set your theme to a default one.
    3. Go to Plugins. There you can enable WooCommerce by selecting Enable While Troubleshooting.
    4. Try to reproduce the problem. If the problem is resolved, it’s clearly a conflict. Now we need to figure out which plugin is causing this conflict.
    5. If you can’t reproduce the problem with only WooCommerce enabled, go ahead and re-enable the other plugins one by one. Test after each one until the problem occurs again – this will tell you which plugin is conflicting.
    6. If you are unable to reproduce the problem with the rest of your plugins enabled it could be your theme causing the conflict. To test for this, please enable your original theme at your WordPress Dashboard in the Troubleshooting Mode section at the top (it will look similar to this: https://d.pr/i/bbvkLY). In the Troubleshooting window, you’ll be able to see a dropdown with available themes. Choose the one you normally use. Try reproducing the problem you’re experiencing. If you can reproduce it, your theme is the source of the conflict.

    Once you’ve done that, please check out How to test for plugin and theme conflicts and follow the steps there. Please let us know how that goes.

    Thread Starter ilfungo

    (@ilfungo)

    Thanks a lotfor your answer. It really is strange, but nothing changed. I did as you say, I also try with the theme (free woocommerce boutique, and so should be compatible) and try to change the theme with twentytwenty. I try without plugins. Nothing changes. Any time one one new order. The only error wich occurs is a cUrl 28, but once the order is payd, payment visible on the order, the state changes to pending I can’t see why it shouldn’t change to complete…
    And checked again that the product is virtual and downloadable and it is, no extracode in function.php. Can’t understand what’s going on. Everithing else is working well.

    Plugin Support Missy a11n

    (@m155y5)

    Automattic Happiness Engineer

    Hi @ilfungo

    Are you running the latest version of WooCommerce? You might try reinstalling the WooCommerce plugin (after backing up your site) in case something has gone awry with the core files.

    Plugin Support Damianne P (a11n)

    (@drwpcom)

    Hi @ilfungo. We haven’t heard from you in a while so I’m going to go ahead and mark this thread as resolved. If you still need help with this issue or have any other questions about the WooCommerce plugin, please start a new thread.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘woocommerce virtual order auto complete after payment’ is closed to new replies.