• Resolved tigmewp

    (@tigmewp)


    Good day

    I have followed your documentation step by step but for some reason the order status does not change automatically to “Completed” once payment has been successful.

    It is a variable product with the “Donation Product” checkbox ticked. The “Enabled” and “Virtual” checkboxes are both ticked on each of the variations.

    When the status didn’t automatically change as per your documentation, I installed the plugin “Autocomplete WooCommerce Orders” by QuadLayers, but it also does not work. Not even when the “All orders” option is selected.

    Before the plugin, two code snippets also did not work.

    It is critical that the order status is changed to “Completed” automatically otherwise the leaderboard does not update until each donation is manually set to “Completed”.

    What am I missing?

    Any advice would help.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jonas

    (@flinnn)

    Hi there,

    this error is likely due to your payment gateway or another plugin.
    You could try using this code that updates all processing orders to completed once per hour.

    // Function to update all processing orders to completed status
    function update_processing_orders_status() {
        $processing_orders = wc_get_orders( array(
            'status' => 'processing',
            'limit'  => -1, // Get all orders with processing status
        ) );
    
        foreach ( $processing_orders as $order ) {
            $order->update_status( 'completed' );
        }
    }
    add_action( 'update_processing_orders_event', 'update_processing_orders_status' );
    
    // Function to activate the scheduled event
    function activate_orders_update_schedule() {
        // Check if the event is not already scheduled
        if ( ! wp_next_scheduled( 'update_processing_orders_event' ) ) {
            // Schedule the event to run update_processing_orders_status function hourly
            wp_schedule_event( time(), 'hourly', 'update_processing_orders_event' );
        }
    }
    add_action( 'init', 'activate_orders_update_schedule' );
    
    // Function to deactivate the scheduled event
    function deactivate_orders_update_schedule() {
        $timestamp = wp_next_scheduled( 'update_processing_orders_event' );
        wp_unschedule_event( $timestamp, 'update_processing_orders_event' );
    }
    // Register the deactivate_orders_update_schedule function to run on plugin deactivation
    register_deactivation_hook( __FILE__, 'deactivate_orders_update_schedule' );

    Best
    Jonas

    Thread Starter tigmewp

    (@tigmewp)

    Good day Jonas

    Thank you for following up and the code snippet provided.

    We use the Yoco payment gateway on the website and I also wondered if this could have been the reason.

    I was fortunate to find another snippet that change the status of all new donations to “Completed” the moment the payment has been completed successfully. All is now working as expected.

    Thank you for a great plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Order status does not automatically change to “Completed”’ is closed to new replies.