How can I extend Commerce Discount to apply discount on custom price field? I have products with 2 prices, the Commerce default one commerce_price, and a custom field field_price_with_flight. In some cases, depending on the node display term value of a taxonomy,  I need to calculate and display the discount prices onto the custom price instead of default Commerce price.

If it can be achieved with rules, I'd appreciate a detailed answer because I'm not very comfortable with the use of rules, especially commerce ones.

How could I achieve that ?

EDIT :

I need to make it possible through discount module UI. I'll try to expose why with the business model below.

The site sells travels. Anytime, depending on sales, the owner decides to create new discounts, with parameters such as:


Limited time
A different discount value usually fixed amount but could be % sometimes
Applied on a selection of travels, choosed across discount UI whether per product or per category, with the help of Commerce Discount Product Category


The flexibility of Commerce Discount  does the job most of the time. 
I could setup rules for one case, but this is just impossible to teach the site owner and sellers how to setup discount rules for each new one.

Now whenever you create a discount like that, The module creates a dedicated rule. Basic one exported below.

The challenge is that by default it will apply on commerce_price. I need to extend Discount module so that :


Or it detects the travel type has a field_price_with_flight value 
Or we tell the module it is that case with a checkbox in the discount form for instance 


and applies then the discount to field_price_with_flight.

Or, last, if possible, create a global rule that will overwrite each discount rule whenever necessary?

Basic rule created by discount

{ "commerce_discount_rule_discount_discount_example" : {
    "LABEL" : "Discount example",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-1",
    "OWNER" : "rules",
    "TAGS" : [ "Commerce Discount", "R\u00e9duction par produit" ],
    "REQUIRES" : [
      "commerce_discount",
      "commerce_discount_date",
      "commerce_product_reference"
    ],
    "ON" : { "commerce_product_calculate_sell_price" : [] },
    "IF" : [
      { "commerce_discount_compatibility_check" : {
          "commerce_order" : [ "commerce-line-item:order" ],
          "commerce_discount" : "discount_discount_example"
        }
      },
      { "commerce_discount_date_condition" : { "commerce_discount" : "discount_discount_example" } },
      { "commerce_product_contains_products" : { "sku" : "VE1201#2556#09-05-2016" } }
    ],
    "DO" : [
      { "commerce_discount_fixed_amount" : {
          "entity" : [ "commerce_line_item" ],
          "commerce_discount" : "discount_discount_example"
        }
      }
    ]
  }
}
All you need is Rules :)

You can start with next steps:


Visit Product pricing rules page: /admin/commerce/config/product-pricing
Click + Add a pricing rule
Enter Name. E.g. "Custom discount calculation"
Click "Save"


After that you can program logic of "some cases, depending on the node display term value of a taxonomy" via rules. If you provide more details I can explain steps more precise.

From this point you should only add conditions and actions. There is a good module rules_conditional which allows you to add conditions in any place of your rule.

Some hints on Rules:

When you want to do some actions and check with field values, you have to check if the field exists first (that's a tricky part of rules).

E.g. if you want to check the value of the field_price_with_flight, you have to add 2 conditions before:


Entity has field: Entity commerce-line-item, Field: commerce_product
Entity has field: Entity commerce-line-item:commerce-product, Field: field_price_with_flight.


After these 2 actions you can do things with the field.

P.S. An alternative way for checking fields is to check the bundle of the entity.

If you need to do some price calculations you can use actions:


Data > Add variavle
Data > Calculate a value


Once you have finished your calculations, you can apply your price. Check the `Commerce line item' actions for unit price. You can multiply, divide, set unit price.

That is basically it. In this case you do not need the discount module.

Advanced

If you need some very custom calculations you can code a custom action for price calculation. There is a lot of examples if you try to search it. E.g. How To Create A Custom Rules Action

Useful links, videos:


Product Pricing Rules (with screencasts) - a very detailed explanation of using pricing rules with steps, videos, examples.
Drupal Commerce Basic Discount on Vimeo
Drupal Commerce Complex Pricing Rules