wordpress / woocommerce - 自定义字段的总和

时间:2015-12-30 14:03:26

标签: php wordpress woocommerce custom-fields

我在我的woocommerce中添加了一个输入字段(与每个订单相关联)。我可以使用下面的代码完美地显示该字段的每个值:

function MY_COLUMNS_VALUES_FUNCTION( $column ) {
    global $post;
    $order = new WC_Order( $post->ID );
    $items = $order->get_items();

    //start editing, I was saving my fields for the orders as custom post meta
    //if you did the same, follow this code
    if ( $column == 'authors_income' ) {
        foreach ( $items as $item ) {

            echo $item['MY-FIELD-NAME'];

        }
    }

但是如何将该字段的所有值相加并回显/打印呢?

1 个答案:

答案 0 :(得分:1)

只需将当前值添加到变量并在循环后回显结果

<div id="dialogNewRecipient" title="Add Recipient">
    <div class="row">
        <label for="NewFullName">Name:</label>
        <input id="NewFullName" type="text">
    </div>
    <div class="row">
        <div class="form-group">
            <div class="container">
                <label for="NewEmail">Email:</label>
                <input id="NewEmail" type="text">
                <ul class="nav navbar navbar-right">
                    <li class="label"></li>
                    <li class="dropdown" id="emailDropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" id="dropdownMenu2" aria-haspopup="true" aria-expanded="false">@@tax.ny.gov<span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">@@tax.ny.gov</a></li>
                            <li><a href="#">@@scom.tax.ny.gov</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
        </div>
    <div class="row">
        <div class="form-group center-block">
            <button id="SaveRecipient" type="button">Save</button>
            <button id="CancelRecipient" type="button">Cancel</button>
        </div>
    </div>
</div>