2014-03-12 14 views
5

Wenn ich das folgende in meine functions.php stürzt es meine gesamte Website abstürzt. der Zweck dieser FunktionWooCommerce benutzerdefinierte Funktion für kostenlose Versandetikett

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

dazu ...

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

Wenn ich das ein Wort in der ursprünglichen WooCommerce ändern zu ändern ist/includes/WC-Warenkorb-Funktionen .php es funktioniert perfekt. Ich möchte nicht, dass es mit einem Update überschrieben wird.

/** 
* 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); 
} 

Antwort

8

wenn Sie neueste verwenden Woocommerce dann folgende Filter wird hilfreich sein für Sie.

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; 
} 
1

Sie sollten die Funktion über den Filter neu erstellen. Die Verwendung von str_replace funktioniert nicht bei übersetzten Installationen, es sei denn, jede Sprache wird im Austausch überprüft.

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); 
Verwandte Themen