I need to hide the shipping label on my woocommerce cart page but keep it visible on the checkout page.
I have read that I can use is_cart() to target the cart specifically but it has not worked with any code that I have written in functions.php.
Does anyone know how to accomplish this?
-edit-
I have found the following code to put in functions.php:
add_filter('woocommerce_cart_shipping_method_full_label', 'remove_shipping_label', 10, 2);
function remove_shipping_label($label, $method) {
$new_label = preg_replace('/^.+:/', '', $label);
return $new_label;
}
Now I need to combine the code with “if ( is_cart() )” to target the cart page specifically but I haven’t figured out how.
The cart page is loaded by a template in the plugin folder:
To overridethis template you need to copy that file in your theme at:
Now you can do anything with it (leave it empty even) and it will only affect the cart page. The checkout page uses a different template file to generate the shipping fields.
Source: experience + template overriding
This is what I got to work, that is to edit woocommerce shipping details template. Old question I know, and my answer is not 100% related to the question, but searching did not help me too much with this problem,so I thought I’d help anyone still looking……
In the line
$pos=strpos($wherefrom,"checkout");
thecheckout
must be the name (slug) of your checkout page. The section that let’s you choose payment methods is loaded by ajax, so all the ‘is_page’, ‘is_checkout’, etc, return blanks, so I resorted to useing the http_referrer. This is the result of way too many hours on one ‘small’ problem. This code goes in the cart-shipping.php file as described in Yavour’s answer, and must replace the existing code between the existing<ul></ul>
.On Checkout page hide shipping label and display only shipping cost below below code.