You are here

function commerce_stock_tokens in Commerce Stock 7.2

Implements hook_tokens().

File

./commerce_stock.module, line 320
Commerce Stock module.

Code

function commerce_stock_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'commerce-product' && !empty($data['commerce-product'])) {
    $product = entity_metadata_wrapper('commerce_product', $data['commerce-product']);
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'user-quantity-ordered':
          $replacements[$original] = commerce_stock_check_cart_product_level($product->product_id
            ->value());
          break;
      }
    }
  }
  return $replacements;
}