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 TicketTagged: expire_date, package_id
-
AuthorPosts
-
June 27, 2016 at 8:32 pm #217057
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>'; } } }
June 27, 2016 at 8:41 pm #217060get_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.
June 28, 2016 at 7:27 pm #217676@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>'; } } }
June 28, 2016 at 7:34 pm #217685Glad you got it sorted!
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket