0

More detailed: I'd like to use the the number of items which were bought by somebody and multiplicate it with a number, to show how much water somebody saved.

    function random_message(){
    
    $count = 0;
    foreach ( $order->get_items() as $items ) {
        // Count + 1
        $count++;
    }
$mes = array('Message 12', 'Message 13', 'Message 14');
$multiplier = 7950;
shuffle($mes);
echo 'you saved ' . $count * $multiplier . 'l water';
//echo 'With this order ' . $mes[0];
}
add_shortcode( 'random_message', 'random_message' );

I wrote this code to my functions.php inside of my child-theme. At the moment I get an error: Screenshot

  • 1
    "an error" is too vague. Please include the complete error message, so we can help you. – fuxia Sep 7 at 19:29
  • You're getting a PHP error: Call to a member function get_items() on null. That sounds like you're using something along the lines of $some_class->get_items() somewhere, but $some_class isn't initialized. Here's an answer on a similar question. – Pat J Sep 8 at 13:53
  • Also: rather than posting a screenshot of the error, please edit your question and paste it in as text (feel free to remove any sensitive info like directory paths, etc). This will make it easier for people having a similar problem to search for answers, and also make it easier for us to try to answer your question. – Pat J Sep 8 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.