• 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)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi @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

    (@dansperfect)

    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 a11n

    (@luminus)

    Automattic Happiness Engineer

    Hi @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

    (@jdembowski)

    Forum Moderator and Brute Squad

    @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.