• Resolved Stonehenge Creations

    (@duisterdenhaag)


    I would like newly created invoices to automatically use the ‘next_invoice_number’ in its title and slug. I can do this with the filter ‘wp_insert_post_data’, but I am having trouble fetching the sliced_get_next_invoice_number.

    A simple $_POST[‘_sliced_invoice_number’] (=the id of the side metabox) doesn’t do the trick.

    Any suggestions are highly appreciated. ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    == SOLVED ==

    By digging into the original Sliced Invoices code, I have found how the _next_invoice_number was being called. I copied that and here is the result:

    
    // Modify the invoice title & slug on "publish" or "update"
    function modify_sliced_invoice_title($data, $postarr) {
        $post = get_post();
        if( $post->post_type === 'sliced_invoice') {
            if( $post->post_status !== 'publish' ) {
                $option = get_option( 'sliced_invoices' );
                $number = $option['number'];
            }
    	else {
    	    $number = get_post_meta( get_the_ID(), '_sliced_invoice_number', true);
    	}
    	$title 	= 'Invoice ' .$number;
    	$slug 	= 'invoice-' .$number;
    
    	if( $post->post_title === $title ) {
    	    $data['post_title'] = $data['post_title'];
    	    $data['post_name']  = $data['post_name'];
    	}
    	else {
    	    $data['post_title'] = $title;
    	    $data['post_name'] = sanitize_title($slug);
    	}
        }
        return $data;
    }
    add_filter( 'wp_insert_post_data', 'modify_sliced_invoice_title', '99', 2 );
    

    Now all all invoices wil be automatically named “Invoice [number]” and their slug is “invoice-[number]”, no matter how they were created (front- or back-end). It even checks for this if you update an existing invoice. ??

    Plugin Support Andrea Whitmer

    (@nutsandboltsmedia)

    Hi Patrick,

    Thanks for updating! We were looking into this for you but you were too fast for us.:)

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    Hi Andrea,

    Yes, I had just finished testing it and immediately updated this thread. ??

    Where does that code go?

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    You can put it in your functions.php or make a simple plugin out of it.

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    I am currently creating a plugin that will automatically create a new invoice when the visitor fills out a caldera form. ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Auto-create title/slug from invoice number?’ is closed to new replies.