Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Allow frontend submissions while a Simple Subscription is valid.
- * Existing Post Package access remains available when no subscription qualifies.
- */
- function jnews_frontend_submit_simple_subscription_access( $allowed ) {
- if ( ! get_theme_mod( 'jnews_frontend_submit_enable_woocommerce', false ) || ! is_user_logged_in() || ! function_exists( 'wcs_get_users_subscriptions' ) ) {
- return $allowed;
- }
- foreach ( wcs_get_users_subscriptions( get_current_user_id() ) as $subscription ) {
- if ( ! $subscription->has_status( array( 'active', 'pending-cancel' ) ) ) {
- continue;
- }
- $end_time = $subscription->get_time( 'end' );
- if ( $end_time && $end_time <= time() ) {
- continue;
- }
- foreach ( $subscription->get_items() as $item ) {
- $product = $item->get_product();
- if ( $product && $product->is_type( 'subscription' ) ) {
- return true;
- }
- }
- }
- return $allowed;
- }
- add_filter( 'jnews_frontend_submit_user_subscription', 'jnews_frontend_submit_simple_subscription_access' );
Advertisement
Add Comment
Please, Sign In to add comment