// Setup WooCommerce Memberships shortcode // Source: https://www.skyverge.com/blog/create-memberships-section-shortcode-woocommerce-memberships/ function sv_wc_memberships_my_memberships_shortcode() { // bail if Memberships isn't active or we're in the admin if ( ! function_exists( 'wc_memberships' ) || is_admin() ) { return; } // buffer contents ob_start(); ?><div class="woocommerce"><?php wc_memberships()->get_frontend_instance()->get_member_area_instance()->my_account_memberships(); ?></div><?php // output buffered content echo ob_get_clean(); } add_shortcode( 'wcm_my_memberships', 'sv_wc_memberships_my_memberships_shortcode' ); // Setup New My Account nav item // by https://businessbloomer.com/woocommerce-add-new-tab-account-page/ - Thanks! // 1. Register new endpoint to use for My Account page // IMPORTANT: Resave Permalinks or it will give 404 error function cswm_add_membership_endpoint() { add_rewrite_endpoint( 'my-memberships', EP_ROOT | EP_PAGES ); } add_action( 'init', 'cswm_add_membership_endpoint' ); // ------------------ // 2. Add new query var function cswm_membership_query_vars( $vars ) { $vars[] = 'my-memberships'; return $vars; } add_filter( 'query_vars', 'cswm_membership_query_vars', 0 ); // ------------------ // 3. Insert the new endpoint into the My Account menu function cswm_add_membership_link_my_account( $items ) { $items['my-memberships'] = 'Memberships'; return $items; } add_filter( 'woocommerce_account_menu_items', 'cswm_add_membership_link_my_account' ); // ------------------ // 4. Add content to the new endpoint function cswm_membership_content() { //echo '<h3>WooCommerce Memberships</h3><p>View your active WooCommerce Memberships</p>'; echo do_shortcode( ' ' ); } add_action( 'woocommerce_account_my-memberships_endpoint', 'cswm_membership_content' ); /** * Remove the "My Memberships" table from my account dashboard * Source: https://gist.github.com/stuartduff/52eee6de3493d56aea63f2df693870c5 */ function sv_remove_my_memberships_table() { if ( function_exists( 'wc_memberships' ) && !is_admin() ) { remove_action( 'woocommerce_before_my_account', array( wc_memberships()->get_frontend_instance()->get_member_area_instance(), 'my_account_memberships' ) ); } } add_action( 'init', 'sv_remove_my_memberships_table' );
Add WooCommerce Memberships to My Account
In