In WooCommerce, I would like to put an extra field in wc-order-totals.
add_action( 'woocommerce_admin_order_totals_after_discount', 'vp_add_sub_total', 10, 1);
function vp_add_sub_total( $order_id )
{
$order = wc_get_order( $order_id );
?><tr>
<td class="label">Subtotal-2:</td>
<td width="1%"></td>
<td class="total"><?php echo wc_price($order->get_subtotal($items_total+$shipping_total));?></td>
</tr><?php
}
How can I add the subtotal with shipping?
The values are already calculated previously.
So i need that subtotal-2 to be: 50.00€ + 33.60€
I need to calculate a second subtotal in WooCommerce, so the new field subtotal_2 must be cost of product plus shipping cost.
The following will add a line to admin order totals, adding subtotal to shipping total:
add_action( 'woocommerce_admin_order_totals_after_discount', 'vp_add_sub_total', 10 );
function vp_add_sub_total( $order_id )
{
$order = wc_get_order( $order_id );
?>
<tr>
<td class="label"><?php _e('Subtotal-2')?>:</td>
<td width="1%"></td>
<td class="total"><?php echo wc_price( $order->get_subtotal() + $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) );?></td>
</tr>
<?php
}
Code goes in functions.php file of your child theme (or in aplugin). Tested and works.