I Am new in working with CartThrob and EE2. How i can assign {exp:cartthrob:cart_total} value to a php variable.Please let me know how to do that.

Thanks in advance.

  • Can you give some details on what you're attempting to do? It's rare that there is a need to use PHP within template code and there is possibly a different way to do what you want.
    – foamcow
    Commented Sep 22, 2015 at 12:28

2 Answers 2


As with what @foamcow said, this is generally a bad idea, especially if you're new to PHP or ExpressionEngine in general. I'm providing you an example, but I highly recommend against going this route. You do so at your own risk. Understanding the differences between input and output parsing is huge, and it sounds like you are new to these concepts. Please revise your question and expand on what you are trying to accomplish, and we can probably give you a safer answer.

For the template in question, set it's PHP parsing to Output.


Then, in your template code, you can use this code to grab that value:

// grab cart_total, cast to int
$my_php_var = (int) "{exp:cartthrob:cart_total}";

// what **are** you trying to do, anyways? let's add 10
$my_php_var += 10;

echo $my_php_var

Again, we highly recommend not going this route.


You would need to enable PHP parsing for the template where you are using the variable. The parsing can be done on "input" or "output" and you will need to choose a setting depending on what you are trying to do.

Be aware that enabling PHP within template code can be a security risk and there is often a "better" way to do things by means of creating a custom plugin or extension. This keeps the PHP away from your template code.

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.