• Resolved aiyubpanara

    (@aiyubpanara)


    Hello All,

    First thank for the awesome plugin.

    However, I would like to show the invoice status in PDF, for example, whether the invoice has been paid or not.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @aiyubpanara

    How are you establishing that the Invoice is paid? Using a third party plugin, order status, custom field or something else?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @aiyubpanara,

    The WC_Order class from WooCommerce has a method called is_paid() which you can use to check if the order is paid already.

    By default, the order statuses treated as “paid statuses” are Processing and Completed, therefore, only when the order has reached these order status, the Paid status will be displayed as Paid, otherwise the output will be Unpaid.

    As an example, I used the method mentioned above in the following code snippet to achieve what you want, displaying the Payment Status after the order data:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Shows whether the invoice is paid or not
     */
    add_action( 'wpo_wcpdf_after_order_data', function( $document_type, $order ) {
    	if ( $document_type == 'invoice' ) {
    	?>
    	<tr class="is-paid">
    		<th>Payment Status:</th>
    		<td><?php echo ( $order->is_paid() ) ? 'Paid' : 'Unpaid' ?></td>
    	</tr>
    	<?php
    	}
    }, 10, 2 );

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    More

    (@wilsonmorema)

    This worked like magic for me. But I am stuck on how to change the color of the 2 statuses. Paid in green for example and red to be unpaid, give me an idea please.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @wilsonmorema,

    Try this version which highlight the paid/unpaid text with the colors you mentioned:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Shows whether the invoice is paid or not
     */
    add_action( 'wpo_wcpdf_after_order_data', function( $document_type, $order ) {
    	if ( $document_type == 'invoice' ) {
    		$paid = '<span style="color:green">Paid</span>';
    		$unpaid = '<span style="color:red">Unpaid</span>';
    		?>
    		<tr class="is-paid">
    			<th>Payment Status:</th>
    			<td><?php echo ( $order->is_paid() ) ? $paid : $unpaid ?></td>
    		</tr>
    		<?php
    	}
    }, 10, 2 );
    More

    (@wilsonmorema)

    Thanks @yordansoares..It worked perfect.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m glad to hear that, @wilsonmorema! 🕺

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.