I need to get the current user id to lookup customer information, in order to pass it to an api call to process a payment. I have tried:
$user = wp_get_current_user();
echo ( isset( $user->ID ) ? (int) $user->ID : 0 );
and:
$userid = get_current_user_id();
echo $userid;
But when I run the php file, the process stops at the first line and does not display anything after it. I dont get an error or nothing, just a blank screen. I have been searching for solution for 2 weeks. All results says that these codes should work, but does not for me. I have also added the require('to user.php') and doe not work.
I even enter this php code into Dreamweaver, and "wp_get_current_user" or "get_current_user_id" does not turn blue like other function calls do, but get_current_user() does turn blue, but this is the websites owners user not the current user. Please help if you can, much appreciated. Thanks Here is my code:
<?php
echo "here";
/**
* Lookup the customer information.
*
* @since 1.0.0
*
* @return void
*/
echo "is";
function lookup_customer_information() {
$current_user = wp_get_current_user();
if ( ! is_object( $current_user ) || ! isset( $current_user->ID ) ) {
echo $current_user;
return;
}
echo "the";
echo "code";
// do your business logic here.
}
?>
<?php $userinfo = lookup_customer_information();
echo $userinfo;
?>