Change ‘added to cart’ message for Drupal Commerce

Change ‘added to cart’ message for Drupal Commerce

Drupal commerce comes with a setting to display a message when adding products to your cart. This is formatted like: {product-title} added to your cart.

What if you want to add the quantity or SKU number in that description. Well, here you go with 2 simple functions.

/**
 * Implements hook_rules_action_info_alter().
 */
function mymodule_rules_action_info_alter(&$actions) {
  $actions['commerce_cart_add_to_cart_message']['callbacks']['execute'] = 'mymodule_cart_rules_add_to_cart_message';
}

function mymodule_cart_rules_add_to_cart_message($product) {
  drupal_set_message(t('%title (%sku) added to your cart.', array('%title' => $product->title, '%sku' => $product->sku, '!cart-url' => url('cart'))));
}

That’s it!

Comments are closed.