Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Check if Credit Card

  • Resolved zpaparidis

    (@zpaparidis)


    Hello,
    first of all, thanks for your awesome plugin. I am trying to insert a footer within the invoice.php template file using a conditional. I want this footer to be visible only if a payment has been done with a credit card. For the credit card payments we use the braintree credit card system.
    What I did was write this code

    $payment_method = method_exists($order, 'get_payment_method') ? $order->get_payment_method() : $order->payment_method;
        if ($payment_method == 'credit_card') { ?>

    The problem must be within the if statement… I tried also with
    if ($payment_method == 'braintree_credit_card')
    but without any success. What should I use for this equal statement ? I found online that if I wanted to control for BACS payment, the conditional would be
    if ($payment_method == 'bacs')
    I need something similar for credit cards if possible.. Many many thanks in advance

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Ewout

    (@pomegranate)

    Hi! WooCommerce has actually made it more difficult to check this since 3.4 🙁 (until 3.4 you could simply go to WooCommerce > Settings > Checkout and it would be printed in the Gateway ID column).

    Alas, that’s not possible anymore with 3.4, but you can still check the URL. Go to WooCommerce > Settings > Payments, click on your payment gateway, then take the part of the URL after where it says &section= (depending on your browser, this may be hidden until you click the URL bar).

    Let us know what you find!

    Thank you for your reply
    Yes, I found the ids you are talking about… However, writing the if statement like that `$payment_method = method_exists($order, ‘get_payment_method’) ? $order->get_payment_method() : $order->payment_method;
    if ($payment_method == ‘braintree_credit_card’) { ?>`
    It doesn’t succeed…
    If I write it like that

    $payment_method = method_exists($order, 'get_payment_method') ? $order->get_payment_method() : $order->payment_method;
        if ($payment_method != 'braintree_credit_card') { ?>

    so, instead of == I use !=, then the content that I need to appear conditionally appears… This happens also if I use as a condition other payment gateways such as paypal…
    And I make sure that I am viewing the appropriate invoices :), so if I test against simple paypal I have opened the invoice of an order that has been paid with paypal and so on :S. I know the solution is nearby but it is really depressing that it doesn’t work yet :(.

    Plugin Author Ewout

    (@pomegranate)

    what do you see if you do

    
    echo $payment_method;
    

    instead of the if statement? You will want to try this for the various gateways.

    Perhaps it also helps if you share a more complete bit, to give some context. You could copy it to https://pastebin.com and share a link here.

    Hm, that was a good suggestion, to try the echo…
    It didn’t echo anything, therefore the variable remains empty….
    Here is my pastebin https://pastebin.com/xzqV6PdE , the code in question is between the lines 130 and 139. The <div id =”footer”> part doesn’t matter much for the moment, as even if I insert a random text to be displayed after the if statement, it doesn’t appear..

    I finally figured it out. The code in question (the if statement) has been modified with this snippet

    <?php 
    $method_of_payment = $this->get_payment_method();
        if ($method_of_payment == 'Credit Card') { ?>
    
    <?php if ( $wpo_wcpdf->get_footer() ): ?>
    <div id="footer">
    	<?php $wpo_wcpdf->footer(); ?>
    </div><!-- #letter-footer -->
    <?php endif; ?>
    <?php } ?>

    So one uses the name of the payment method as it appears in the invoice… it is usable for other payment methods as well…
    Thank you very very much for your support anyway, I appreciate it.

    Plugin Author Ewout

    (@pomegranate)

    This explains a lot.. Your template is still in the legacy format, using the $wpo_wcpdf variable. Only in the 2.0 format you can use the $order variable directly. With the older version you have to use $wpo_wcpdf->export->order instead.

    I highly recommend updating your template so that you can disable legacy mode in the Status tab too – this will improve performance and give you more options 🙂

    Of course, if it works, it works – it’s just good housekeeping to do so

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Check if Credit Card’ is closed to new replies.