Get Package id

This topic contains 3 replies, has 2 voices, and was last updated by  Jeff 8 years, 7 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #217057

    EH
    Expired Member
    Post count: 96

    I really thought I was done with customizing but my work just added one more requirement. They want me to display a message when someone logs in that is they are on the free package that they are free with a link to upgrade and if they are paid display the expire date. I’m having a problem getting the package_id and the expire_date. I’m obviously doing something wrong with these two queries. I was hoping maybe you could point me in the right direction. Here is my function.

    
    
           //Add Message for Directory users Subscribers Only
           add_action ('genesis_before_header', 'geo_badge');
           function geo_badge(){
                if ( is_user_logged_in() && current_user_can( 'subscriber' )) {
                    global $wpdb;
                    $id = get_the_ID();
                    $ispaid = $wpdb->get_var("SELECT package_id FROM wp_geodir_gd_place_detail WHERE post_id = $id ");
                    if ($ispaid == 2 ){
                        $expire = $wpdb->get_var("SELECT expire_date FROM wp_geodir_gd_place_detail WHERE post_id = $id ");
                        echo '<div class="statusbar"><div class="statusbar-wrapper"><div class="site-inner">You are on premium package. Your package will expire on';
                        echo $expire;
                        echo '</div></div></div>';         
                    }
                    else {
                        echo '<div class="statusbar"><div class="statusbar-wrapper"><div class="site-inner">You are on a free package. You can upgrade <a href="">here.</a>';
                        echo '</div></div></div>';
                        
                    }
                }
           }
    #217060

    Jeff
    Buyer
    Post count: 188

    get_the_ID would need to be within “The Loop” or some other query.

    You’ll want to grab all of a user’s listings to figure out which, if any, are on the free packages and then take actions.

    #217676

    EH
    Expired Member
    Post count: 96

    @jeff Thank you. I think I have it working. Posting my hopefully working code incase anyone else can use it.

    
    
           //Add Message for Directory users Subscribers Only
           add_action ('genesis_before_header', 'geo_badge');
           function geo_badge(){
                if ( is_user_logged_in() && current_user_can( 'subscriber' )) {
                    global $current_user;
                    get_currentuserinfo();
    
                    //get all listing from author
                    $args = array(
                        'post_type' => 'gd_place',
                        'author'=> $current_user->ID
                    );
    
                    $the_query = new WP_Query( $args );
    
                    if ( $the_query->have_posts() ) :
    
                        while ( $the_query->have_posts() ) : $the_query->the_post();
                            $postid = get_the_ID ();
                            global $wpdb;
                            $ispaid[] = $wpdb->get_var("SELECT package_id FROM wp_geodir_gd_place_detail WHERE post_id = $postid");
                            $expire = $wpdb->get_var("SELECT expire_date FROM wp_geodir_gd_place_detail WHERE post_id = $postid");
                        endwhile;
                        wp_reset_query();
                    endif;
                    foreach ($ispaid as $pack_id):
                    if ($pack_id == 2) {
                        echo '<div class="statusbar"><div class="statusbar-wrapper"><div class="site-inner">You are on premium package. Your package will expire on ';
                        echo $expire;
                        echo '</div></div></div>';  
                        break;
                    }
                    endforeach;
                    if ($pack_id != 2 ){
                        echo '<div class="statusbar"><div class="statusbar-wrapper"><div class="site-inner">You are on a free package. You can upgrade <a href="/upgrade-listing-premium">here.</a>';
                        echo '</div></div></div>';
                    }
               }
           }
    #217685

    Jeff
    Buyer
    Post count: 188

    Glad you got it sorted!

Viewing 4 posts - 1 through 4 (of 4 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount