Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliaamosova/d2aae739f1dd1531493435fb29fd9c67 to your computer and use it in GitHub Desktop.
Save juliaamosova/d2aae739f1dd1531493435fb29fd9c67 to your computer and use it in GitHub Desktop.
Display shipping cost next to the Flat Rate which is set to be Free
/**
* Open `\wp-content\plugins\woocommerce\includes\wc-cart-functions.php`
* Search for `wc_cart_totals_shipping_method_label function`
* Replace it with the following function
**/
function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->get_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 apply_filters( 'woocommerce_cart_shipping_method_full_label', $label, $method );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment