Support » Plugin: WooCommerce » Virtual product order auto-mark as completed

  • Hi,

    I’ve been trying to mark the virtual (digital download) orders as ‘completed’ rather than ‘pending’.

    Since the license serial and download links is sent directly to them after the purchase, the pending stage is pretty meaningless for those products.

    To do this, I believe the best option would be modifying the theme’s ‘function.php’ file?

    I have tried, but with no luck yet:

    // Auto Complete all WooCommerce orders
    function custom_woocommerce_auto_complete_order( $order_id ) {
        global $woocommerce;
    
        if ( !$order_id )
            return;
        $order = new WC_Order( $order_id );
        $order->update_status( 'completed' );
    }
    add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );

    or

    function wc_mark_all_orders_as_complete( $order_status, $order_id ) {
    	$order = new WC_Order( $order_id );
    	if ( $order_status == 'processing' && $order->status == 'pending' ) {
    		return 'completed';
    	}
    
    	return $order_status;
    }
    
    add_filter( 'woocommerce_payment_complete_order_status', 'wc_mark_all_orders_as_complete', 10, 2 );

    They however still remain as ‘pending’.

    Details for products I want to update are:
    Simple product with virtual ticked. They have some custom attributes and a custom payment gateway (via another plugin), if that matters.

    https://wordpress.org/plugins/woocommerce/

  • The topic ‘Virtual product order auto-mark as completed’ is closed to new replies.