Trying to totally customise the Woocommerce My Account page on a Membership site using Woo Memberships.
I am trying to write a custom block that fetches all the content a user has purchased access to via a membership. Is there a function I can use? I cant see anything in the docs.
Trying to do something like this
$user_id = get_current_user_id();
// Fetch active memberships for the current user
$args = array(
'status' => array( 'active', 'complimentary', 'pending' ),
);
$active_memberships = wc_memberships_get_user_memberships( $user_id, $args );
if ( ! empty( $active_memberships ) ) {
echo '<h3>Unlocked Content</h3>';
echo '<ul>';
foreach ( $active_memberships as $membership ) {
// Get the plan ID for the current membership
$plan_id = $membership->get_plan_id();
// Retrieve content associated with the plan
$content_posts = wc_memberships()->get_plan_content_restricted_posts( $plan_id );
if ( ! empty( $content_posts ) ) {
foreach ( $content_posts as $content_post ) {
// Display the unlocked content to the user
echo '<li><a href="' . get_permalink( $content_post->ID ) . '">' . get_the_title( $content_post->ID ) . '</a></li>';
}
} else {
echo '<li>No content unlocked for this membership.</li>';
}
}
echo '</ul>';
} else {
echo '<p>No active memberships found.</p>';
}
This is the plugin I am using.