WordPress.org

Forums

WooCommerce - excelling eCommerce
Virtual product order auto-mark as completed (1 post)

  1. 3Lancer
    Member
    Posted 10 months ago #

    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/

Reply

You must log in to post.

About this Plugin

About this Topic