I have got the correct new cost displaying but the calculations of the total cost still be made with the old cost of the method.
I need the new cost be the actual cost for calculations in the cart and check out
add_filter( 'woocommerce_cart_shipping_method_full_label', 'custom_shipping_method_full_label', 10, 2 );
function custom_shipping_method_full_label( $label, $method ) {
if ( !in_array( $method->get_method_id(), array( 'free_shipping', 'local_pickup' ), true ) && 0 < $method->cost ) {
$label = $method->get_label(); // Get shipping label without cost
$new_cost = $method->cost - get_total_subsidies( WC()->cart->get_cart() );
if ( $new_cost > 0 ) {
$method->cost = $new_cost;
$label .= ': ' . wc_price( $new_cost );
} else {
$method->cost = 0;
$label .= ': ' .' <span class="free-cost">' . __('Free!', 'woocommerce').'</span>';
}
}
return $label;
}
New contributor
Eduardo Relax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.