Title: Problems with PHP code
Last modified: February 6, 2019

---

# Problems with PHP code

 *  [dansperfect](https://wordpress.org/support/users/dansperfect/)
 * (@dansperfect)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/problems-with-php-code-2/)
 * Ok so I’m having some trouble with some php code. I mean it works fine when it’s
   in a template overide file directly. But if I try to add it to my functions.php
   with with an add_action and custom function it null’s out. I don’t understand
   what’s going on but maybe someone can help me here.
 * So below is the specific line of code I’m having trouble with. If place directly
   in to woocommerce order-details.php template file or email-order-details.php 
   it works perfectly fine but one used in functions.php with an add_action it nulls
   out.
    `$totalVal = preg_replace('/[^0-9.]/u', '', html_entity_decode($total['
   value']));`

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [con](https://wordpress.org/support/users/conschneider/)
 * (@conschneider)
 * Engineer
 * [7 years, 4 months ago](https://wordpress.org/support/topic/problems-with-php-code-2/#post-11083512)
 * Hi [@dansperfect](https://wordpress.org/support/users/dansperfect/),
 * > If place directly in to woocommerce order-details.php template file or email-
   > order-details.php it works perfectly fine but one used in functions.php with
   > an add_action it nulls out.
 * Sounds like you have a scope problem or output problem. Could you post your entire
   hooked function, your expectations and intention. That way we might be able to
   come with something.
 *  Thread Starter [dansperfect](https://wordpress.org/support/users/dansperfect/)
 * (@dansperfect)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/problems-with-php-code-2/#post-11089067)
 * Sorry for the delay on this but this is the full code.
 * $totalVal = preg_replace(‘/[^0-9.]/u’, ”, html_entity_decode($total[‘value’]));
   
   if ($totalVal > 0 && $totalVal <= 99.99 ){ echo ‘For Spending $’ . $totalVal .‘
   My Text 1!’;
 *  } elseif ($totalVal >= 100 && $totalVal <=149.99 ){
    echo ‘For Spending $’ .
   $totalVal . ‘ My Text 2’ ;
 *  } elseif ($totalVal >= 150){
    echo ‘For Spending $’ . $totalVal . ‘My Text 3’;
 *  } else {
    echo ‘Error! Please notify site administration about this error!’;
   var_dump($totalVal); }
 *  [Luminus Alabi](https://wordpress.org/support/users/luminus/)
 * (@luminus)
 * Automattic Happiness Engineer
 * [7 years, 4 months ago](https://wordpress.org/support/topic/problems-with-php-code-2/#post-11173767)
 * Hi [@dansperfect](https://wordpress.org/support/users/dansperfect/),
 * You definitely have a scope issue here. There’s no pointer to where to obtain
   the `$total` array from.
 * Your `functions.php` file has no idea where it is supposed to be looking for 
   it as it isn’t a local variable.
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [7 years, 4 months ago](https://wordpress.org/support/topic/problems-with-php-code-2/#post-11174840)
 * [@dansperfect](https://wordpress.org/support/users/dansperfect/) I’ve archived
   your reply. Insulting people has a short life here and I’m closing this topic
   as you pushed it too far with your personal attack.
 * If there is a repeat of that, your account will be banned.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Problems with PHP code’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/problems-with-php-code-2/#post-11174840)
 * Status: not resolved