i have a simple WordPress site with WooCommerce, and i would like to get logged user id and/or mail.
i'm pretty new to WP and PHP, so i guess i'm missing something elementry.
this is the main PHP Code:
<?php
//Needed?
require_once ABSPATH . '/wp-content/plugins/woocommerce/includes/class-wc-customer.php';
class MyClass
{
protected $wp;
public function initialize()
{
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// Put your plugin code here
global $woocommerce;
$cust = $woocommerce->customer;
echo '<div id="UserDiv" >';
echo var_dump($cust); //returns NULL
echo $cust->ID; //returns nothing
echo $cust->user_email; //returns nothing
echo '</div>';
}
}
}
?>
also tried:
$user_id = get_current_user_id();
$user = new WP_User(get_current_user_id());
and it didn't work either...
Thanks!