Reputation: 2522
I'm trying to validate WooCommerce subscriptions and I need the userid to do it but it keeps returning 0 from $current_user->ID.
<?php
include('../wp-load.php');
$current_user = wp_get_current_user();
$SubCheck = WC_Subscriptions_Manager::user_has_subscription( $current_user->ID, 9, 'active' );
?>
Upvotes: 2
Views: 2050
Reputation: 38502
Try this way,why $current_user->ID
<?php $user_ID = get_current_user_id(); ?>
Returns (int)
The user's ID, if there is a current user; otherwise 0.
SEE:http://codex.wordpress.org/Function_Reference/get_current_user_id
EDIT:
<?php
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
// Not logged in.
} else {
// Logged in.
}
?>
EDIT2:
<?php global $current_user;
get_currentuserinfo();
echo 'User ID: ' . $current_user->ID;
?>
OR
<?php
global $current_user;
$current_user = wp_get_current_user();
$current_user->ID
?>
Upvotes: 3
Reputation: 106
thy this...
global $current_user;
$current_user = wp_get_current_user();
$current_user->ID
Upvotes: 2