• Resolved Olaf Lederer

    (@finalwebsites)


    Hi,

    I found this action in some other forum post and like to use it with packing slip.
    Two questions:
    Is it possible to use the order id inside my custom function?
    And how to decide which doc type is used?

    add_action( 'wpo_wcpdf_created_manually', 'change_to_working_status');
    function change_to_working_status() {
    	global $order_id;
        if ( ! $order_id )
            return;
    
        $order = wc_get_order( $order_id );
        if( $order->has_status( 'processing' ) ) {
            $order->update_status( 'working' );
        }
    }
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @finalwebsites,

    The wpo_wcpdf_document_created_manually hook is better for handling single documents, however wpo_wcpdf_init_document is perhaps a better “catch-all”.

    wpo_wcpdf_document_created_manually is intended to be used for copying the PDF file contents rather than to apply modifications to the order.
    See: https://github.com/wpovernight/woocommerce-pdf-invoices-packing-slips/blob/b80fc5f9bca714439494a6de89846b60123219f9/includes/class-wcpdf-main.php#L357

    Could you give this code a try instead?

    add_action( 'wpo_wcpdf_init_document', function( $document ) {
    	if (empty($document->order)) {
    		return;
    	}
    	if ( $document->get_type() == 'packing-slip' && $document->order->has_status( 'processing' ) ) {
    		$document->order->update_status( 'working', "Oorder status updated after printing ".$document->get_title() );
    	}
    }, 10, 1 );
    Plugin Contributor Darren Peyou

    (@dpeyou)

    Hey @finalwebsites,

    I made a mistake, in my 1st parapgraph I meant to say:

    This is a better hook: wpo_wcpdf_document_created_manually
    For handling single documents, wpo_wcpdf_init_document is maybe a better “catch-all”. ??

    And in my 2nd paragraph:
    wpo_wcpdf_created_manually is intended to be used for copying the PDF file contents rather than to apply modifications to the order.

    • This reply was modified 3 years, 8 months ago by Darren Peyou. Reason: Correcting mistakes with the function names
    Thread Starter Olaf Lederer

    (@finalwebsites)

    Hi @dpeyou,

    thanks for your quick response and your example.
    I don’t need that function for single docs. My customer want to use it for the batch function. Is it for the purpose the same function (hook)?

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @finalwebsites,

    I apologize, I had to rectify my answer again as I was mixing up the names of the functions, please see above for the rectification & the associated comment (written in small text).

    Regardless, the code snippet I shared above should fulfill your needs. ??
    Were you able to give it a try?

    Thread Starter Olaf Lederer

    (@finalwebsites)

    @dpeyou,
    I will test it tomorrow morning as the first thing I will do.
    Thanks again!

    Thread Starter Olaf Lederer

    (@finalwebsites)

    @dpeyou, it works thank you!

    I need a new order status when printing packing slip (Ready to shipment). I tried code above but it doesn’t work. I’m using WooCommerce PDF Invoices & Packing Slips. Can you help me?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @hypostatic,

    Please create a new topic with your question to keep the forum organized and avoid annoying the thread starter with notification not related with their question.

    I’ll answer there ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Changing Order status after creating a packing slip’ is closed to new replies.