1

I have a problem in WooCommerce when the shipment is 0.00 euros from a certain amount.The question is that the cart page does not appear 0.00 euros or free.

This is solved by entering this code in the php functions file. I saw it in this post.

add_filter( 'woocommerce_cart_shipping_method_full_label', 'add_free_shipping_label', 10, 2 );
function add_free_shipping_label( $label, $method ) {
    if ( $method->cost == 0 ) {
        $label = 'Free shipping'; //not quite elegant hard coded string
    }
    return $label;
}

There is also another option if you want 0.00 Euros to appear. I discovered it in the following article.

function my_custom_show_price_with_free_shipping( $label, $method ) {

    $label = $method->get_label();

    if ( WC()->cart->tax_display_cart == 'excl' ) {
        $label .= ': ' . wc_price( $method->cost );
        if ( $method->get_shipping_tax() > 0 && wc_prices_include_tax() ) {
            $label .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
        }
    } else {
        $label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
        if ( $method->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
            $label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
        }
    }

    return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'my_custom_show_price_with_free_shipping', 10, 2 );

The question is that in the notifications that the client receives via e-mail of his purchase and invoices in the sending part he does not put anything. As much as I have investigated, I have not found anything.

I have searched but I have not found anything. Can you help me with this?

Thank you

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
felix
  • 21
  • 3

1 Answers1

1

For orders, email notifications (and maybe PDF), you will use something like:

add_filter( 'woocommerce_order_shipping_method', 'custom_order_shipping_method_labels', 10, 2 );
function custom_order_shipping_method_labels( $labels, $order ) {
    $total = 0;
    foreach ( $order->get_items('shipping') as $item ) {
        $total += $item->get_total();
    }
    if( $total == 0 ){
        $labels .= ' ' . wc_price( 0 );
    }
    return $labels;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here

Remember that an order can have multiple shipping methods in some cases...

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399