Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce custom function for Free Shipping Label

When i put the following into to my functions.php it crashes my entire site. the purpose of this function is to change

elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( '**Free**', 'woocommerce' ) . ')';

to this...

elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( '**To Be Calculated**', 'woocommerce' ) . ')';

When i change the one word in the original woocommerce/includes/wc-cart-functions.php it works perfectly. I don't want it to be overwritten with an update.

/**
* Get a shipping methods full label including price
* @param  object $method
* @return string
*/
function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->label;

if ( $method->cost > 0 ) {
    if ( WC()->cart->tax_display_cart == 'excl' ) {
        $label .= ': ' . wc_price( $method->cost );
        if ( $method->get_shipping_tax() > 0 && WC()->cart->prices_include_tax ) {
            $label .= ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>';
        }
    } else {
        $label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
        if ( $method->get_shipping_tax() > 0 && ! WC()->cart->prices_include_tax ) {
            $label .= ' <small>' . WC()->countries->inc_tax_or_vat() . '</small>';
        }
    }
} elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( 'To Be Calculated', 'woocommerce' ) . ')';
}

return apply_filters( 'woocommerce_cart_shipping_method_full_label', $label, $method );
}
like image 684
user3410993 Avatar asked Mar 12 '14 13:03

user3410993


People also ask

How do I exclude shipping from free shipping in WooCommerce?

Navigate to a WooCommerce Product and open the Shipping tab. Check (or uncheck) the “Exclude Free Shipping” checkbox.


2 Answers

if you are using latest woo commerce then following filter will be helpful to you.

add_filter( 'woocommerce_cart_shipping_method_full_label', 'remove_local_pickup_free_label', 10, 2 );
function remove_local_pickup_free_label($full_label, $method){
    $full_label = str_replace("(Free)","(TBD)",$full_label);
return $full_label;
}
like image 187
Bhavesh Avatar answered Sep 20 '22 19:09

Bhavesh


You should rebuild the function through the filter. Using str_replace will not work on translated installs, unless each language is checked in the replacement.

function ua_woocommerce_cart_shipping_method_full_label( $label, $method ) {
$label = $method->label;

if ( $method->cost > 0 ) {
    if ( WC()->cart->tax_display_cart == 'excl' ) {
        $label .= ': ' . wc_price( $method->cost );
        if ( $method->get_shipping_tax() > 0 && WC()->cart->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()->cart->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', 'ua_woocommerce_cart_shipping_method_full_label', 10, 2 );
like image 45
Jonas Lundman Avatar answered Sep 20 '22 19:09

Jonas Lundman