簡體   English   中英

在“訂單總額”之前在 Woocommerce 管理編輯訂單頁面中添加自定義行

[英]Add a custom row in Woocommerce admin edit order pages before "Order total"

我正在尋找正確的鈎子以在此處插入帶有自定義數據的新行,但我沒有遇到任何正確的答案。

請檢查位置的圖像: 請檢查位置的圖像

請任何幫助將不勝感激。 🙏

使用掛鈎在woocommerce_admin_order_totals_after_tax操作掛鈎中的自定義函數,您將能夠在“訂單總計”行之前顯示自定義行:

add_action('woocommerce_admin_order_totals_after_tax', 'custom_admin_order_totals_after_tax', 10, 1 );
function custom_admin_order_totals_after_tax( $order_id ) {

    // Here set your data and calculations
    $label = __( 'Custom label', 'woocommerce' );
    $value = 'Value';

    // Output
    ?>
        <tr>
            <td class="label"><?php echo $label; ?>:</td>
            <td width="1%"></td>
            <td class="custom-total"><?php echo $value; ?></td>
        </tr>
    <?php
}

此代碼位於活動子主題(或主題)的 function.php 文件或任何插件文件中。

測試和工作......你會得到類似的東西:

在此處輸入圖片說明

或者 …

對於單個字符串文本,請改用它:

add_action('woocommerce_admin_order_totals_after_tax', 'custom_admin_order_totals_after_tax', 10, 1 );
function custom_admin_order_totals_after_tax( $order_id ) {

    // Here set your text
    $text = __( 'This is your custom text', 'woocommerce' );

    // Output
    echo '<tr><td class="label" colspan="3">' . echo $label . '</td></tr>';
}

此代碼位於活動子主題(或主題)的 function.php 文件或任何插件文件中。

測試和工作......你會得到類似的東西:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM