• Resolved ozviewer

    (@ozviewer)


    Hi I would like to add a static field that contains my bank details for direct payment to my bank. It need not be dependant on the payment method, so I just need a static field. BTW, I have a child theme and Code Snippets. Thanks.

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

    (@dpeyou)

    Hello @ozviewer,

    What method are you using in order to store these bank details? An external plugin? Code?
    We could use the guide here in order to display Custom Fields to display these details.

    Thread Starter ozviewer

    (@ozviewer)

    Hi, thanks for the reply. The details are in the WooCommerce payments settings ‘Direct Bank Transfer’ which appears on the checkout page if the customer has selected that method of payment and confirms the order. However, the PDF invoice that follows does not have the bank details so to ensure the customer has the details handy I wanted to include a static text field with the bank number and a/c number.

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @ozviewer you should be able to use this code snippet in order to display the bank info. This will appear after the order details. ??

    add_action( 'wpo_wcpdf_after_order_details', function( $document_type, $order ) {
    	if ( $order->get_payment_method() == 'bacs' && class_exists( 'WC_Gateway_Bacs' ) ) {
    		$gateway = new WC_Gateway_Bacs();
    		if ( $gateway ) {
    			echo $gateway->thankyou_page( $order->get_id() );
    		}
    	}
    }, 10, 2 );

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

    • This reply was modified 1 year, 4 months ago by Darren Peyou.
    Thread Starter ozviewer

    (@ozviewer)

    Thanks Darren, that works well but it would be ideal with a couple of tweaks.

    Can I add a line or paragraph break before Bank Details? There is text above that which I want to keep separate.

    The Bank Details now also appear on the Packing Slip as well if payment is by Bank deposit. Can I stop that? The current Code Snippet for the Packing Slip is:

    /**
     * WooCommerce PDF Invoices & Packing Slips:
     * Display the PS Comments after the customer notes on the packing slip
     */
    add_action( 'wpo_wcpdf_after_customer_notes', function( $document_type, $order ){
    	if( $document_type == 'packing-slip' && ( $ps_comments = $order->get_meta( 'ps_comments' ) ) ) {
    		echo "<div><h3>PS Comments:</h3><p>{$ps_comments}</p></div>";
    	}	
    }, 10, 2);

    Thanks.

    • This reply was modified 1 year, 4 months ago by ozviewer.
    • This reply was modified 1 year, 4 months ago by ozviewer.
    • This reply was modified 1 year, 4 months ago by ozviewer.
    Plugin Contributor Darren Peyou

    (@dpeyou)

    Hey @ozviewer,

    If you want the details to appear on the invoice only, replace this:

    $document_type == 'packing-slip'

    With this:

    $document_type == 'invoice'

    To add a space, use the “<br>” tag. Insert it to get the content on a new line before the first “echo” statement, like this:

    echo "<br>";

    Thread Starter ozviewer

    (@ozviewer)

    Thanks Darren but your code is not working for the packing slip, it still shows the bank details and now omits the packing slip comments.

    I think I need the code for the invoice to include $document_type == ‘invoice’.

    I have tried to add it myself but I keep getting an error that:

    Unclosed '(' on line 1 does not match '}'.

    For example one of the many, many different ways I have tried is:

    add_action( 'wpo_wcpdf_after_order_details', function( $document_type, $order ) 
    	if ( $document_type == 'invoice' && ( $order->get_payment_method() == 'bacs' && class_exists( 'WC_Gateway_Bacs' ) ) ;
    		$gateway = new WC_Gateway_Bacs();
    		if ( $gateway ) {
    			echo $gateway->thankyou_page( $order->get_id() );
    		}
    	}
    }, 10, 2 );
    Plugin Contributor Darren Peyou

    (@dpeyou)

    @ozviewer,

    In my original code snippet I didn’t put a check for the document type, so my payment method bank details appear on all PDF documents. ??
    I just tested it again and my the bank details appear on my end on the Packing Slip PDF.

    I’m afraid maybe we aren’t yet understanding each other. ??
    > but your code is not working for the packing slip, it still shows the bank details and now omits the packing slip comments.
    I’m not quite sure you want to display ti on the packing slip or not, sorry.

    • This reply was modified 1 year, 4 months ago by Darren Peyou.
    Thread Starter ozviewer

    (@ozviewer)

    @dpeyou

    Hi Darren, thanks for your prompt reply. What I am after is:

    • For the bank details to appear on the invoice if the order is to be paid for by bank deposit;
    • For the bank details not to appear on the Packing Slip at all.

    Thanks.

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @ozviewer,

    Thanks for clarifying ??

    You accidentally introduced typos when you modified the code, on lines 1 and 3. I addressed them here, try this:

    add_action( 'wpo_wcpdf_after_order_details', function( $document_type, $order ) {
    	if ( $document_type == 'invoice' && ( $order->get_payment_method() == 'bacs' && class_exists( 'WC_Gateway_Bacs' ) ) ) {
    		$gateway = new WC_Gateway_Bacs();
    		if ( $gateway ) {
    			echo $gateway->thankyou_page( $order->get_id() );
    		}
    	}
    }, 10, 2 );

    With the code above, my Bank Details appear on the Invoice, but not on the Packing Slip.

    Thread Starter ozviewer

    (@ozviewer)

    @dpeyou

    Bingo! Thanks so much for your patience and expertise. Everything works. I just got a short guide book to PHP so my next task is to try and improve my knowledge.

    • This reply was modified 1 year, 4 months ago by ozviewer.
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Add static field for Bank details’ is closed to new replies.