You are here

function commerce_discount_get_free_shipping_strategy in Commerce Discount 7

Returns the free shipping strategy for the given discount.

Parameters

CommerceDiscount $discount: A Commerce Discount object with a commerce_free_shipping_strategy field.

Return value

string The discount's free shipping strategy or 'only_selected' if none is set.

1 call to commerce_discount_get_free_shipping_strategy()
commerce_discount_shipping_service in ./commerce_discount.rules.inc
Rules action: Apply shipping discount.

File

./commerce_discount.module, line 1048
Defines the discount and discount offer entities, bundles and functionality.

Code

function commerce_discount_get_free_shipping_strategy($discount) {
  $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
  $strategy = $discount_wrapper->commerce_discount_offer->commerce_free_shipping_strategy
    ->value();

  // If the free shipping strategy is not set, default to 'only_selected'.
  if (empty($strategy)) {
    $strategy = 'only_selected';
  }

  // Note that if the field is set to an unknown value, we still return it. The
  // default action for applying a free shipping discount will pass through
  // unknown discount strategies, so modules that set them are responsible also
  // to evaluate them on behalf of all discounts.
  return $strategy;
}