I'm trying to get the Woocommerce product name by ID using PHP. Here's what I've tried so far but so far, no dice.
require_once('../wp-load.php');
var_dump(wc_get_product('284') );
var_dump(get_the_title('284') );
Have also just tried this:
$product = wc_get_product(284);
var_dump($product->get_title() );
All attempts product no output.
Here's the code I'm using to get the IDs in the first place:
function getProdIds($userId){
$prodResults = [];
$subscriptions = wcs_get_users_subscriptions( $userId );
foreach ($subscriptions as $subKey => $sub){
$subscription = wc_get_order($subKey);
foreach( $subscription->get_items() as $item_id => $product_subscription ){
// Get the name
$prodResults[] = $product_subscription->get_product_id();
}
}
return $prodResults;
}