I used "Execute custom PHP code" in my pricing rule.

However I got Notice when I checkout:

Notice: Use of undefined constant testsku - assumed 'testsku' in eval() (line 7 of /var/www/jmu/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code). Notice: Undefined variable: line_item in eval() (line 7 of /var/www/jmu/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code).

I know there must be something wrong with my token replace code:

$line_item_label = token_replace([commerce-line-item:line-item-label],array('commerce_line_item' =>$line_item));

I used "line-item-label" as product sku's machine name

Anyone have any idea about this?

  • Where and how did you use $line_item_label? It seems to me that this variable has the value testsku and that you misused it as a constant somewhere else. Your error also demonstrates that you should avoid using PHP code in a Rule. See drupal.stackexchange.com/a/108447/16550 for example.
    – Jeroen
    Jun 29, 2016 at 16:42

1 Answer 1


At the very beginning, I just saw "$commerce_line_item" can be used in php code, but I wanted to use [commerce-line-item:line-item-label] value which showed in the token place. So I tried to use token_replace to get this value.

Finally, I figure out how to get that value and use it in PHP Code. enter image description here Although it isn't showed in the variable name place, we can still use $commerce_line_item -> line_item_label in the PHP Code. This works for me.

Your Answer

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

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