Shopping Cart show text if shipping option cost is zero

The aim was to replace the shipping cost for any shipping option that has a value of $0.00 with some text, in this case “To be determined. We’ll get back to you”.

This filter must be used within the shipping options loop in the shopping cart page before the shipping options are printed so immediately after:

while (wpsc_have_shipping_quotes()) : wpsc_the_shipping_quote();

add the following:

   $numeric = false;
    if(wpsc_shipping_quote_value(true) == 0){
    //set numeric parameter to echo string
    $numeric = true;
    //shipping price filter
    function shipping_to_be_determined(){
              	return "To be determined, we'll get back to you";
     add_filter('wpsc_shipping_quote_value', 'shipping_to_be_determined');

This does the following:

  • Sets the $numeric flag to false which is the default. This makes the output numeric and passes it through the currency function to display the cost
  • Tests for the current shipping quote having a value of 0
  • If true sets the $numeric flag to true so we can add a string as the output without it being passed through the currency function
  • Filters the shipping quote value to add the text required

Finally we need to add the $numeric flag to the function that echos the shipping value so it returns the value as a string instead of a currency value.

<label for='<?php echo wpsc_shipping_quote_html_id(); ?>'><?php echo wpsc_shipping_quote_value($numeric); ?></label>