I am using WooCommerce with two plugins:
- Yith Gift Card and
- WooCommerce Pos.
Yith Gift Card plugin, allows you to sell Gift Card tokens for your store. When someone purchases a gift card the WooCommerce order confirmation has the Gift Code printed on it.
The WooCommerce POS plugin, allows you to print a receipt from a printer. The problem is the coupon code does not display on this printed receipt.
How the coupon code is added to the WooCommerce e-mail
The Yith Gift Card Plugin adds an action via a WooCommerce e-mail hook, here is the code, excerpted from the Yith Plugin php:
class YITH_WooCommerce_Gift_Cards {
...
add_action( 'woocommerce_order_item_meta_start', array(
$this,
'show_gift_card_code',
), 10, 3 );
}
public function show_gift_card_code( $order_item_id, $item, $order ) {
$code = wc_get_order_item_meta( $order_item_id, YWGC_META_GIFT_CARD_NUMBER );
if ( ! empty( $code ) ) {
printf( '<br>' . __( 'Gift card code: %s', 'yith-woocommerce-gift-cards' ), $code );
}
}
This results in the coupon code being displayed on the WooCommerce order e-mail.
I want the same coupon code to appear on the printed POS receipt.
How the printed POS receipt is generated
I've found the file responsible for printing the printed POS receipt. It is here: https://github.com/kilbot/WooCommerce-POS/blob/master/includes/views/print/receipt-html.php
How can I call the show_gift_card_code function from within receipt-html.php? So that it successfully displays the Gift Card Coupon code?
<table class="order-items">
<thead>
<tr>
<th class="product"><?php /* translators: woocommerce */ _e( 'Product', 'woocommerce' ); ?></th>
<th class="qty"><?php _ex( 'Qty', 'Abbreviation of Quantity', 'woocommerce-pos' ); ?></th>
<th class="price"><?php /* translators: woocommerce */ _e( 'Price', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
{{#each line_items}}
<tr>
<td class="product">
{{name}}
[*I WOULD LIKE THE COUPON CODE DISPLAYED HERE*]
{{#with meta}}
<dl class="meta">
{{#each []}}
<dt>{{label}}:</dt>
<dd>{{value}}</dd>
{{/each}}
</dl>
{{/with}}
</td>