You are here

function commerce_shipping_method_get_title in Commerce Shipping 7.2

Returns the human readable title of any or all shipping methods.

Parameters

string $name: The machine-name of the shipping method whose title should be returned. If left NULL, an array of all titles will be returned.

string $title_type: The type of title to return: 'title' or 'display_title'.

Return value

array|string|bool Either an array of all shipping method titles keyed by the machine-name or a string containing the human readable title for the specified method. If a method is specified that does not exist, this function returns FALSE.

3 calls to commerce_shipping_method_get_title()
commerce_shipping_method_options_list in ./commerce_shipping.module
Prepares commerce_shipping_method_get_title().
commerce_shipping_service_get_title in ./commerce_shipping.module
Returns the human readable title of any or all shipping services.
commerce_shipping_ui_overview in includes/commerce_shipping_ui.admin.inc
Displays all shipping methods or services defined for a method in a table.
1 string reference to 'commerce_shipping_method_get_title'
commerce_shipping_ui_menu in ./commerce_shipping_ui.module
Implements hook_menu().

File

./commerce_shipping.module, line 275
Defines a system for calculating shipping costs associated with an order.

Code

function commerce_shipping_method_get_title($name = NULL, $title_type = 'title') {
  $shipping_methods = commerce_shipping_methods();

  // Return a method title if specified and it exists.
  if (!empty($name)) {
    if (isset($shipping_methods[$name])) {
      return $shipping_methods[$name][$title_type];
    }
    else {

      // Return FALSE if it does not exist.
      return FALSE;
    }
  }

  // Otherwise turn the array values into the method title only.
  $shipping_method_titles = array();
  foreach ((array) $shipping_methods as $key => $value) {
    $shipping_method_titles[$key] = $value[$title_type];
  }
  return $shipping_method_titles;
}