Membership Subscription Plans and E-Newsletter

I know that ENewsletter integrates with Membership on the Access Level; but what about Subscription Plan level? Can we send newsletters just to specific Subscription Plans? (there are several subscriptions in one access level).

  • Vinod Dalvi

    Hi @ncdesignz ,

    Thank you for your question.

    Currently the newsletter plugin doesn't provide functionality to send enewsletters to Subscription Plan levels.

    I will move this over to the features & feedback section. This way it can be considered for future development, and we can also see what other community members think about the feature request.

    In the meanwhile to achieve it change the newsletter plugin code as following.

    Newsletter plugin file:
    \e-newsletter\email-newsletter-files\class.functions.php

    Before updating code from line number 606 to 616 :

    if($membership && function_exists('membership_db_prefix')) {
                $prefix = membership_db_prefix($wpdb, 'membership_levels');
                $membership_levels = $wpdb->get_results("SELECT * FROM {$prefix} WHERE level_active = 1", "ARRAY_A");
                foreach ($membership_levels as $membership_level) {
                    $count = $this->get_members_of_membership($membership_level, 1);
                    if($count) {
                        $targets['membership_levels']['name'] = __( 'Membership Plugin Levels', 'email-newsletter' );
                        $targets['membership_levels'][] = '<label><input type="checkbox" name="target[membership_levels][]" value="'.$membership_level['id'].'"> '.$membership_level['level_title'].' ('.$count.')</input></label>';
                    }
                }
            }

    After updating code from line number 606 to 616 :

    if($membership && function_exists('membership_db_prefix')) {
                $prefix = membership_db_prefix($wpdb, 'subscriptions');
                $membership_sub_levels = $wpdb->get_results("SELECT * FROM {$prefix} WHERE sub_active = 1", "ARRAY_A");
                foreach ($membership_sub_levels as $membership_sub_level) {
                    $count = $this->get_members_of_membership($membership_sub_level, 1);
                    if($count) {
                        $targets['membership_sub_levels']['name'] = __( 'Membership Plugin Subscription Levels', 'email-newsletter' );
                        $targets['membership_sub_levels'][] = '<label><input type="checkbox" name="target[membership_sub_levels][]" value="'.$membership_sub_level['id'].'"> '.$membership_sub_level['level_title'].' ('.$count.')</input></label>';
                    }
                }
            }

    Newsletter plugin file:
    \e-newsletter\email-newsletter-files\class.functions.php

    Before updating code from line number 289 to 301 :

    /**
         * Get all members of membership
         **/
        function get_members_of_membership( $level_id, $count = 0 ) {
            global $wpdb;
    
            if(!function_exists('membership_db_prefix'))
                return false;
    
            $table = membership_db_prefix($wpdb, 'membership_relationships');
            $arg['inner_join'] = "{$table} MR ON A.wp_user_id = MR.user_id";
            $arg['where'] = $wpdb->prepare('MR.level_id = %d AND A.unsubscribe_code != ""', $level_id);
            $members = $this->get_members( $arg, $count, 0);
    
            return $members;
        }

    After updating code from line number 289 to 301 :

    /**
         * Get all members of membership
         **/
        function get_members_of_membership( $sub_level_id, $count = 0 ) {
            global $wpdb;
    
            if(!function_exists('membership_db_prefix'))
                return false;
    
            $table = membership_db_prefix($wpdb, 'membership_relationships');
            $arg['inner_join'] = "{$table} MR ON A.wp_user_id = MR.user_id";
            $arg['where'] = $wpdb->prepare('MR.sub_id = %d AND A.unsubscribe_code != ""', $sub_level_id);
            $members = $this->get_members( $arg, $count, 0);
    
            return $members;
        }

    Newsletter plugin file:
    e-newsletter/e-newsletter.php

    Before updating code from line number 1422 to 1429 :

    //Get ids for Membership levels being subscribed eNewsletter members
                if ( isset( $_REQUEST["target"]["membership_levels"] ) && is_array($_REQUEST["target"]["membership_levels"]) )
                    foreach ( $_REQUEST["target"]["membership_levels"] as $membership_level ) {
                        $members = $this->get_members_of_membership($membership_level);
                        foreach ( $members as $member ) {
                            $members_id[] = $member['member_id'];
                        }
                    }

    After updating code from line number 1422 to 1429 :

    //Get ids for Membership subscription levels being subscribed eNewsletter members
                if ( isset( $_REQUEST["target"]["membership_sub_levels"] ) && is_array($_REQUEST["target"]["membership_sub_levels"]) )
                    foreach ( $_REQUEST["target"]["membership_sub_levels"] as $membership_sub_level ) {
                        $members = $this->get_members_of_membership($membership_sub_level);
                        foreach ( $members as $member ) {
                            $members_id[] = $member['member_id'];
                        }
                    }

    Cheers,
    Vinod Dalvi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.