1

I have a site on which I sell membership with Pmpro and WooCommerce. Memberships are made as WooCommerce Products.

I am using the following snippet to force membership on my site. But it restricts the user to pmpro pages only till they buy a membership. Since my memberships are sold via woo-commerce, I want to include WooCommerce products to the unrestricted access.

<?php        
/* Redirect user to levels page until he subscribes for a membership */
    add_action( 'template_redirect', 'sq_membership_restrict' );
    function sq_membership_restrict() {
      global $pmpro_pages, $post;
      if ( is_user_logged_in() && ! pmpro_hasMembershipLevel() ) {
        if (isset( $post->ID ) && ! in_array( $post->ID, $pmpro_pages )) {
          wp_redirect( pmpro_url() );
        }
      }
    }

Currently, the WooCommerce Membership product links are also redirected back to the Membership selection Page.

What changes should I make to allow Pmpro pages and WooCommerce Product pages to have unrestricted access?

mujuonly
  • 11,370
  • 5
  • 45
  • 75

0 Answers0