I have here a code that adds the "Total shipping cost" based on the shipping rate per product
function action_woocommerce_after_shipping_rate( $method, $index ) {
global $woocommerce;
$sub_ed_total = preg_replace('/&.*?;/', '', WC()->cart->get_cart_subtotal());
$ed_total = preg_replace('/&.*?;/', '', WC()->cart->get_cart_total());
$str = preg_replace('/[^0-9.]+/', '', $sub_ed_total);
$str2 = preg_replace('/[^0-9.]+/', '', $ed_total);
$ed_tototal = $str - $str2;
echo '<br>';
echo 'Total shipping: '.get_woocommerce_currency_symbol().number_format((float)abs($ed_tototal), 2, '.', '');
echo '<br>';
echo '<br>';
};
add_action( 'woocommerce_after_shipping_rate', 'action_woocommerce_after_shipping_rate', 10, 2 );
Its working on my checkout page and cart page
and here is the email template after purchase
You see that in the email template the "Total shipping: £17.00" is not showing and I don't know how to make it show up in the email template
Please help as I am having a headache now trying to solve this problem, thanks
add_action( 'woocommerce_email_after_order_table', 'wdm_add_shipping_method_to_order_email', 10, 2 );
function wdm_add_shipping_method_to_order_email( $order, $is_admin_email ) {
echo '<p><h4>Shipping:</h4> ' . $order->get_shipping_method() . '</p>';
}
Using this you can override default text of shipping. May this help. You have to just replace $order->get_shipping_method() to your code.