Drupal Commerce: Determine currently selected product variation (or default delta)

Today I'd like to provide you with a little commerce.module snippet to determine the currently selected product variation (using commerce_product_reference.module) of a product display with several variations.

I had to search hard for it so here's the code for you:

  1. // Determine the currently selected product or default product for this product display
  2. $node_wrapper = entity_metadata_wrapper('node', $product_display_node);
  3.     $products = $node_wrapper->field_produkt->value();
  4.     $current_product = commerce_product_reference_default_product($products);