最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Add product categories to receipt

programmeradmin5浏览0评论

I have the following code so far for my receipt:

<?php foreach ($order->get_items() as $item) {
    /* @var $item \WC_Order_item */
    $meta = $item['item_meta'];
    $meta = array_filter($meta, function ($key) {
        return !in_array($key, Order::getHiddenKeys());
    }, ARRAY_FILTER_USE_KEY);
    ?>
    <tbody>
    <tr>
        <td colspan="2"><?= $item['qty']; ?>x <?= $item['name']; ?></td>
        <td
            rowspan="<?= count($meta) + 1; ?>"><?= wc_price($item->get_data()['total'], array('currency' => $order->get_currency())); ?></td>
    </tr>
    <?php $meta = array_map(function ($meta, $key) {
        $result = '<tr>';
        $result .= '<td>' . $key . '</td>';
        $result .= '<td>' . $meta . '</td>';
        $result .= '</tr>';
        return $result;
    }, $meta, array_keys($meta));
    echo implode(PHP_EOL, $meta);
    ?>
    </tbody>

I am looking to add categories to help our chef. At minimum, we would like to add the category after the item name in brackets. But ideally, we would like to split all the items by category along with a category heading, and we would like the categories to display in ascending order to their given tag_id if possible. Confident in editing the HTML just not the PHP.

Any help would be appreciated! Here is what are receipt looks like so far:

发布评论

评论列表(0)

  1. 暂无评论