You are here

function commerce_usps_commerce_shipping_service_info in Commerce USPS 7

Same name and namespace in other branches
  1. 7.2 commerce_usps.module \commerce_usps_commerce_shipping_service_info()

Implements hook_commerce_shipping_service_info().

File

./commerce_usps.module, line 44
Defines the USPS shipping method and services for Drupal Commerce.

Code

function commerce_usps_commerce_shipping_service_info() {
  $services = array();
  $available = commerce_usps_service_list();
  $enabled = variable_get('commerce_usps_services', array());

  // Add enabled USPS services.
  foreach ($enabled as $service) {
    if ($service) {
      $machine_name = preg_replace('/[^a-z0-9_]+/', '_', drupal_strtolower($service));
      $services[$machine_name] = array(
        'title' => t($service),
        'description' => t('USPS @service service', array(
          '@service' => $available[$service],
        )),
        'display_title' => t($available[$service]),
        'shipping_method' => 'usps',
        'price_component' => 'shipping',
        'callbacks' => array(
          'rate' => 'commerce_usps_rate',
        ),
      );
    }
  }
  return $services;
}