• Resolved glupo91pos

    (@glupo91pos)


    HI, I’m using free version of WooCommerce PDF Invoices & Packing Slips.
    I set up invoice pdf for attaching invoice only on “customer comleted order” email.
    I want that invoice number is assigned only for orders that are in a completed status.
    I used this snippet I found on this forum:

    add_filter( ‘wpo_wcpdf_listing_actions’, ‘wpo_wcpdf_disable_invoice’, 20, 2 );
    add_filter( ‘wpo_wcpdf_myaccount_actions’, ‘wpo_wcpdf_disable_invoice’, 20, 2 );
    add_filter( ‘wpo_wcpdf_meta_box_actions’, ‘wpo_wcpdf_disable_invoice’, 20, 2 );
    function wpo_wcpdf_disable_invoice ( $actions, $order ) {
    // make sure $order is the actual order object
    $order = wc_get_order( $order );

    // set allowed order statuses (slugs, so ‘on-hold’ instead of ‘On Hold’)
    $allowed_statuses = array( ‘completed’ );

    // remove button/link status not allowed
    if ( !in_array($order->get_status(), $allowed_statuses) ) {
    unset( $actions[‘invoice’] );
    }

    return $actions;
    }
    It hides the button for generate invoice pdf, so I can avoid that someone assign invoice number on “payment waiting” order, but if I select all orders and use bulk action to export invoice pdf it assigns an invoice number even to incomplete orders.
    Can I use some filter to export invoice pdf only for completed orders?
    Moreover, if I open order detail admin page, I also see the “set invoice number and date” button.
    How can I hide this button?
    I have installed only woocomerce and WooCommerce PDF Invoices & Packing Slips.
    Can you help me?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! That’s a great question!

    Here’s a snippet that prevents invoices from being created for non-completed orders even with the bulk export:

    
    add_filter( 'wpo_wcpdf_process_order_ids', 'wpo_wcpdf_limit_bulk_export_completed', 10, 2 );
    function wpo_wcpdf_limit_bulk_export_completed( $order_ids, $document_type ) {
    	foreach ($order_ids as $key => $order_id) {
    		$order = wc_get_order( $order_id );
    		$allowed_statuses = array( 'completed' );
    
    		if ( !in_array($order->get_status(), $allowed_statuses) ) {
    			unset( $order_ids[$key] );
    		}
    	}
    	return $order_ids;
    }
    

    And to hide the button to set the invoice number/date for non-completed orders:”

    
    add_action( 'add_meta_boxes_shop_order', 'wpo_wcpdf_limit_set_invoice_box', 20, 1 );
    function wpo_wcpdf_limit_set_invoice_box( $post ) {
    	$order = wc_get_order( $post );
    	$allowed_statuses = array( 'completed' );
    
    	if ( !in_array($order->get_status(), $allowed_statuses) ) {
    		remove_meta_box( 'wpo_wcpdf-data-input-box', 'shop_order', 'normal' );
    	}
    }
    

    That should do the trick!

    Hope that helps ??
    Ewout

    Thread Starter glupo91pos

    (@glupo91pos)

    HI! Thanks a lot, I tried your snippet and it works perfectly.

    Plugin Contributor Ewout

    (@pomegranate)

    You’re welcome, very glad to hear that ??

    facfed

    (@facfed)

    Hi,
    could be possibile to prevent invoices from being created for non-completed orders ,but permit to proforma to be create even for non-completed order?
    Thanks

    Plugin Contributor Ewout

    (@pomegranate)

    Hi, @facfed,
    Proforma is a feature of the Professional extension, and www.ads-software.com doesn’t allow us to handle support for non-free features via these forums. If you send us an email with a bit more details at [email protected] we’ll do our best to help!

    Ewout

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Avoid increase of invoice number on incomplete orders’ is closed to new replies.