在 "Order total" 之前在 Woocommerce 管理员编辑订单页面中添加自定义行
Add a custom row in Woocommerce admin edit order pages before "Order total"
我正在寻找正确的挂钩以在此处插入带有自定义数据的新行,但我没有找到任何正确答案。
请查看职位图片:
如有任何帮助,我们将不胜感激。
使用挂钩在 woocommerce_admin_order_totals_after_tax
操作挂钩中的自定义函数,您将能够在 "Order total" 行之前显示自定义行:
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 文件或任何插件文件中。
已经过测试并可以正常工作……您会得到类似以下内容:
我正在寻找正确的挂钩以在此处插入带有自定义数据的新行,但我没有找到任何正确答案。
请查看职位图片:
如有任何帮助,我们将不胜感激。
使用挂钩在 woocommerce_admin_order_totals_after_tax
操作挂钩中的自定义函数,您将能够在 "Order total" 行之前显示自定义行:
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 文件或任何插件文件中。
已经过测试并可以正常工作……您会得到类似以下内容: