• Resolved Megunticook

    (@megunticook)


    Hi,

    Working on another Woo puzzle here. Orders consisting of downloadable products are being automatically set to “complete” status by Woo. Even though they’ve been paid for, these orders need to stay in “processing” status until they are manually closed by one of the staff. How do I do this?

    After Googling and experimenting I have a block of code which I think ought to work but when I test the orders are still marked as “complete.” Any ideas on how to get this right?

    Thank you.

    /*prevent any orders from autocompleteing*/
    add_filter( 'woocommerce_payment_complete_order_status', 'stop_autocomplete_virtual_orders', 10, 2 );
    function stop_autocomplete_virtual_orders( $order_status, $order_id ) {
    	
    	$order = wc_get_order( $order_id );
    	if ('processing' == $order_status && ('on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status)) {
    	
    		$virtual_order = '';
    		if ( count( $order->get_items() ) > 0 ) {
    			foreach ( $order->get_items() as $item ) {
    				if ( 'line_item' == $item['type'] ) {
    					$_product = $order->get_product_from_item( $item );
    					if ( ! $_product->is_virtual() ) {
    						$virtual_order = false;
    						break;
    					} else {
    						$virtual_order = true;
    					}
    				}
    			}
    		}
    		if ( $virtual_order ) {
    			return 'processing';
    		}
    	}
    	return $order_status;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Mike M. a11n

    (@mikedmoore)

    Automattic Happiness Engineer

    Hi there,

    Downloadable products shouldn’t be automatically completed. Do you have virtual checked on the product as well? If so, try unchecking virtual.

    Thread Starter Megunticook

    (@megunticook)

    If I uncheck virtual then it shows shipping options, which I don’t want in the case of downloads. The products come in 2 variations: 1 is download only, 1 is download plus they get hard copy mailed to them. So the first variation, download only, it shouldn’t display any shipping options.

    Thread Starter Megunticook

    (@megunticook)

    Well I may have solved this. Probably not the most graceful solution but it works.

    Do you see any potential issues or unintentional consequences from this approach?

    Basically our books person wants to manually change the status to complete on every order that comes in, even the downloads, so the auto complete interferes with her system.

    /*prevent any orders from autocompleting*/
    /*
     */
    add_action( 'woocommerce_thankyou', 'stop_auto_complete_order' );
    function stop_auto_complete_order( $order_id ) { 
        if ( ! $order_id ) {
            return;
        }
    
        $order = wc_get_order( $order_id );
        $order->update_status( 'processing' );
    }
    Plugin Support Mike M. a11n

    (@mikedmoore)

    Automattic Happiness Engineer

    Hey there,

    That should work, and given your intention of manually completing orders, I can forsee any problems with this. Good work 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘disable automatic order completion for downloable products’ is closed to new replies.