function commerce_shipping_service_get_title in Commerce Shipping 7.2
Returns the human readable title of any or all shipping services.
Parameters
string $name: The machine-name of the shipping service 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 service titles keyed by the machine-name or a string containing the human readable title for the specified service. If a service is specified that does not exist, this function returns FALSE.
3 calls to commerce_shipping_service_get_title()
- commerce_shipping_line_item_populate in ./
commerce_shipping.module - Populates a shipping line item with the specified values.
- commerce_shipping_line_item_title in ./
commerce_shipping.module - Returns the title of a shipping line item's related shipping service.
- commerce_shipping_service_options_list in ./
commerce_shipping.module - Wraps commerce_shipping_service_get_title() for the Entity module.
1 string reference to 'commerce_shipping_service_get_title'
- commerce_shipping_ui_menu in ./
commerce_shipping_ui.module - Implements hook_menu().
File
- ./
commerce_shipping.module, line 424 - Defines a system for calculating shipping costs associated with an order.
Code
function commerce_shipping_service_get_title($name = NULL, $title_type = 'title') {
$shipping_services = commerce_shipping_services();
// Return a service title if specified and it exists.
if (!empty($name)) {
if (isset($shipping_services[$name])) {
return $shipping_services[$name][$title_type];
}
else {
// Return FALSE if it does not exist.
return FALSE;
}
}
// Otherwise turn the array values into the service title only.
$shipping_service_titles = array();
foreach ((array) $shipping_services as $key => $value) {
$method_title = commerce_shipping_method_get_title($value['shipping_method']);
// Since Views needs a flat array and services must be unique, return a
// flat array.
$shipping_service_titles[$key] = $value[$title_type] . ' (' . $method_title . ')';
}
// Sort the title groups by method title.
ksort($shipping_service_titles);
return $shipping_service_titles;
}