• Resolved astral4ik

    (@astral4ik)


    Hello. i found it in documentation.

    add_action( ‘wpo_wcpdf_before_document’, function( $document_type, $order ) {
    ?>
    <div class=”watermark-wrapper”><span class=”watermark”>Watermark</span></div>
    <?php
    }, 10, 2 );

    but is it possible to do:

    1. add IF order status ON-HOLD it print ONHOLD, if order status set to PROCESSEING it prints PROCESSING

    2. OR add watrmark by shipping method. If it set to LOCALPICKUP it prints lockal picup,

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @astral4ik,

    1. Yes, this code snippet will print either Processing or On hold on your PDFs:

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_add_status_to_pdf', 10, 2 );
    function wpo_wcpdf_add_status_to_pdf( $template_type, $order ) {
    	if ( ! empty($order) ) {
            $status = wc_get_order_status_name( $order->get_status() );
            if ( $status === "On hold" || $status === "Processing" ) {
    			?>
    			<tr class="order-status">
    				<th>Order status: </th>
    				<td><?php echo wc_get_order_status_name( $order->get_status() ); ?></td>
    			</tr>
    			<?php
    		}
    	}
    }

    For the watermark, it is more complex but you can use the structure above & check for the shipping methods (an order can have over 1) using $order->get_shipping_methods(). Then only return the watermark HTML if local_pickup is amongst the shipping methods.

    Thread Starter astral4ik

    (@astral4ik)

    @dpeyou Thanks, it works with order status,
    but with shipping method it doesnt work
    Could you write right snippet here for me?

    Thnks

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @astral4ik,

    Sorry for the late reply!

    As my colleague Darren said: you could have more than one shipping methods in your order (although this is not very common).

    That said, if you only have a shipping method in your store, you can get it with this:

    if ( $order->get_shipping_method() == 'Local Pickup' ) {
    	// Your code goes here!
    }

    However, if you have several shipping methods, it’s a good practice to use a loop for the check, like this:

    foreach ( $order->get_shipping_methods() as $shipping_method ) {
    	if ( $shipping_method['method_id'] == 'local_pickup' ) {
    		// Your code goes here!
    	}
    }

    Hope it helps!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘watermark’ is closed to new replies.