2

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' );
?>

2 Answers 2

3

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 
?>
Sign up to request clarification or add additional context in comments.

Comments

2

thy this...

global $current_user;
$current_user = wp_get_current_user();
$current_user->ID 

1 Comment

more explanation would make this a better answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.