Skip to content

Instantly share code, notes, and snippets.

@kilbot
Created October 23, 2018 17:25
Show Gist options
  • Save kilbot/5c5cb298034e60781d147780e73cf305 to your computer and use it in GitHub Desktop.
Save kilbot/5c5cb298034e60781d147780e73cf305 to your computer and use it in GitHub Desktop.
Adding a gift card code to the WooCommerce POS receipt template
<?php
// this goes in your theme functions.php file
function my_custom_wc_rest_shop_order_object($response)
{
if (function_exists('is_pos') && is_pos()) {
$data = $response->get_data();
if (is_array($data['line_items'])) : foreach ($data['line_items'] as &$line_item) :
if ($code = wc_get_order_item_meta($line_item['id'], '_ywgc_gift_card_number')) {
$line_item['meta_data'][] = new WC_Meta_Data(array(
'id' => '',
'key' => 'Gift Card',
'value' => $code,
));
}
endforeach; endif;
$response->set_data($data);
}
return $response;
}
add_filter('woocommerce_rest_prepare_shop_order_object', 'my_custom_wc_rest_shop_order_object');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment