我正在尝试验证WooCommerce订阅,我需要用户ID来执行此操作,但它会从$ current_user-> ID继续返回0。
<?php
include('../wp-load.php');
$current_user = wp_get_current_user();
$SubCheck = WC_Subscriptions_Manager::user_has_subscription( $current_user->ID, 9, 'active' );
?>
答案 0 :(得分:2)
你的......
global $current_user;
$current_user = wp_get_current_user();
$current_user->ID
答案 1 :(得分:2)
尝试这种方式,为什么$ current_user-&gt; ID
<?php $user_ID = get_current_user_id(); ?>
Returns (int)
The user's ID, if there is a current user; otherwise 0.
请参阅:http://codex.wordpress.org/Function_Reference/get_current_user_id
修改强>
<?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;
?>
或强>
<?php
global $current_user;
$current_user = wp_get_current_user();
$current_user->ID
?>