Original question:
I want to add a script to an order on checkout completion or even better with the rule 'when an order is first paid in full'. But I don't know how or where exactly.

Why I need it: we want to use an external affiliate partner programme for PPS (pay per sale). So when a customer is coming from site A to our shop and orders somthing, the owner of site A gets a certain percentage of the sale. In order for that to work, I need to add a script to the checkout. Or better add the script when the order is paid in full. I use tokens for the UID, order number and total amount in the script I got from the external affiliate partner.

The script looks like this:

<script type="text/javascript" src="https://track.adcocktail.com/tracking_sale.php?t=s&kid=xxxx&lv=0&bestid=[commerce-order:order-number]&wert=[commerce-order:commerce_order_total]&beschreibung=[commerce-order:mail-username]"></script>

I tried adding it by a rule "add a variable" (on checkout completion) but that doesn't do anything. When I add the script to the order as a text field in the checkout, I can't use the tokens (they aren't recognized) and the script is run every time I do something to that order so it appears more than once in the affiliate overview.

Does someone know how I can make this script work ?

(I hope my question is clear. If not, just ask.)

  • Drupal Commerce Kickstart 7.x-2.25
  • Drupal 7.38


I don't need to activate the script on checkout completion, but 30 days after the order is paid in full. So after the 30 days the customer legally has to return goods. And that's not so easily done as adding the script on checkout completion.

Does anyone has an idea on how to make a rule for it ?

1 Answer 1


I would add the script by implementing hook_commerce_checkout_complete in a custom module. You also have access to the order in the function.

function MYMODULE_commerce_checkout_complete($order) {
    array('type' => 'external')

You need to debug the variable $order to find the values you stated, [commerce-order:order-number] etc.

  • Thanks. But I found and easier way to add the script on checkout complete. Really simple: checkout settings > Completion message. I added the script to the completion message and that works. Commented Jul 29, 2015 at 18:00
  • This is actually not a correct answer. The documentation page says: Interaction with the user should instead occur through checkout panes on the checkout completion page.
    – aross
    Commented Sep 14, 2015 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.