arie_cristianD

integrate frontend submit with wcs

Nov 4th, 2026
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1.  
  2. /**
  3.  * Allow frontend submissions while a Simple Subscription is valid.
  4.  * Existing Post Package access remains available when no subscription qualifies.
  5.  */
  6. function jnews_frontend_submit_simple_subscription_access( $allowed ) {
  7.     if ( ! get_theme_mod( 'jnews_frontend_submit_enable_woocommerce', false ) || ! is_user_logged_in() || ! function_exists( 'wcs_get_users_subscriptions' ) ) {
  8.         return $allowed;
  9.     }
  10.  
  11.     foreach ( wcs_get_users_subscriptions( get_current_user_id() ) as $subscription ) {
  12.         if ( ! $subscription->has_status( array( 'active', 'pending-cancel' ) ) ) {
  13.             continue;
  14.         }
  15.  
  16.         $end_time = $subscription->get_time( 'end' );
  17.         if ( $end_time && $end_time <= time() ) {
  18.             continue;
  19.         }
  20.  
  21.         foreach ( $subscription->get_items() as $item ) {
  22.             $product = $item->get_product();
  23.             if ( $product && $product->is_type( 'subscription' ) ) {
  24.                 return true;
  25.             }
  26.         }
  27.     }
  28.  
  29.     return $allowed;
  30. }
  31. add_filter( 'jnews_frontend_submit_user_subscription', 'jnews_frontend_submit_simple_subscription_access' );
  32.  
Advertisement
Add Comment
Please, Sign In to add comment