1

I installed Commerce Billy.

How can I display the payment method on my bill?

<?php

/**
 * @file
 * Template for invoiced orders.
 */

?>
<?php
//The code to get payment type

$order_id = $content['commerce_customer_billing']['#object']->order_id;

$payment_method = '';
$order = commerce_order_load($order_id);
$r = explode('|', $order->data['payment_method']);

if (count($r) > 1){
  $rule = rules_config_load($r[1]);
  $payment_method = $rule->label;
}
?>
<div class="invoice-invoiced">
  <div class="header">
    <img src="<?php print $content['invoice_logo']['#value']; ?>"/>
    <div class="invoice-header">
        <p><?php print render($content['invoice_header']); ?></p>
    </div>
  </div>

  <hr/>

  <div class="customer-billing"><?php print render($content['commerce_customer_billing']); ?></div>
  <div class="customer-shipping"><?php print render($content['commerce_customer_shipping']); ?></div>
  <h1 class="credit-memo"><?php print render($content['invoice_title']); ?></h1>
  <div class="invoice-header-date"><?php print render($content['invoice_header_date']); ?></div>
  <div class="order-id"><?php print render($content['order_id']); ?></div>


  <?php print($payment_method); // Use this PHP Code where you want to print the payment type, you can style it any way, adding div, span, whatever you want ?>     


  <div class="line-items">
    <div class="line-items-view"><?php print render($content['commerce_line_items']); ?></div>
    <div class="order-total"><?php print render($content['commerce_order_total']); ?></div>
  </div>
  <div class="invoice-text"><?php print render($content['invoice_text']); ?></div>

  <div class="invoice-footer"><?php print render($content['invoice_footer']); ?></div>
</div>

Here are the contents of my file "commerce_order--commerce_order--pdf.tpl.php". Where do I put the code ?

1

You can use code below to get the payment method of an order by passing order id to the function. The order id on Commerce billy template file can be easily found in this variable $content['commerce_customer_billing']['#object']->order_id and some other variables as well:

$order_id = $content['commerce_customer_billing']['#object']->order_id;

$payment_method = '';
$order = commerce_order_load($order_id);
$r = explode('|', $order->data['payment_method']);

if (count($r) > 1){
  $rule = rules_config_load($r[1]);
  $payment_method = $rule->label;
}

After using this function, you can print the payment method on your bill by printing $payment_method variable.

  • thank you, but I'm not very good in code. Where to put this code? – user60884 May 4 '16 at 8:29
  • You need to put it into "commerce_order--commerce_order--pdf.tpl.php" file which you will find under under your commerce billy module at path "commerce_billy/modules/commerce_billy_pdf/templates". If you are a bit technical, then instead of making changes here, you may override this template in your theme folder, it need to copy this file to your theme folder and do some configuration through UI. If you are not so technical that make changes to current file. – Dev May 4 '16 at 8:39
  • 1
    @user60884 : if you're 'not very good in code", then you should include that in your actual question somehow. E.g. by adding something like "I do not want to write any custom code". – Pierre.Vriens May 4 '16 at 9:52
  • @drupaler : I updated my question. So I copy the "commerce_order--commerce_order--pdf.tpl.php" file in the templates folder of my theme, can you give me more details ? – user60884 May 5 '16 at 12:28
  • I have updated the code in the question, please check – Dev May 6 '16 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.