Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Last active January 25, 2019 15:00
Show Gist options
  • Save remcotolsma/9a92385e8436f4367f42de7ec893daa2 to your computer and use it in GitHub Desktop.
Save remcotolsma/9a92385e8436f4367f42de7ec893daa2 to your computer and use it in GitHub Desktop.
WordPress query to retrieve active Pronamic Pay subscriptions for current user.
<?php
/**
* WordPress query to retrieve active Pronamic Pay subscriptions for current user.
*
* @link https://github.com/ApiGen/ApiGen
* @link https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query
* @link https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
*/
global $pronamic_subscription;
if ( ! is_user_logged_in() ) {
return;
}
$query = new WP_Query( array(
'post_type' => 'pronamic_pay_subscr',
'post_author' => get_current_user_id(),
'post_status' => 'subscr_active',
'nopaging' => true,
) );
if ( $query->have_posts() ) : ?>
<table>
<thead>
<tr>
<th scope="col">
<?php esc_html_e( 'ID', 'text-domain' ); ?>
</th>
<th scope="col">
<?php esc_html_e( 'Title', 'text-domain' ); ?>
</th>
<th scope="col">
<?php esc_html_e( 'Activation Date', 'text-domain' ); ?>
</th>
<th scope="col">
<?php esc_html_e( 'Expiration Date', 'text-domain' ); ?>
</th>
</tr>
</thead>
<tbody>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<tr>
<td>
<?php echo esc_html( get_the_ID() ); ?>
</td>
<td>
<?php echo esc_html( get_the_title() ); ?>
</td>
<td>
<?php
if ( is_callable( $pronamic_subscription, 'get_activation_date' ) ) {
echo esc_html( $pronamic_subscription->get_activation_date()->format_i18n() );
}
?>
</td>
<td>
<?php
if ( is_callable( $pronamic_subscription, 'get_expiration_date' ) ) {
echo esc_html( $pronamic_subscription->get_expiration_date()->format_i18n() );
}
?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment