I am searching for the correct hook to insert a new row with custom data here, but I didn't come across any correct answer.
Please check the image for the position:
Please any help will be appreciated. 🙏
Join Stack Overflow to learn, share knowledge, and build your career.
I am searching for the correct hook to insert a new row with custom data here, but I didn't come across any correct answer.
Please check the image for the position:
Please any help will be appreciated. 🙏
Using a custom function hooked in woocommerce_admin_order_totals_after_tax
action hook, you will be able to display a custom row just before the "Order total" row:
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
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works… You will get something like:
OR …
For a single string text use this instead:
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>';
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works… You will get something like: