Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active September 15, 2019 15:05
Show Gist options
  • Save jrick1229/c16f82a4facf29f8f77d8bf0ff2d186d to your computer and use it in GitHub Desktop.
Save jrick1229/c16f82a4facf29f8f77d8bf0ff2d186d to your computer and use it in GitHub Desktop.
Check if a subscription is active by displaying an admin notice. (for testing only)
<?php
function wcs_is_sub_active_notice() {
$sub_id = 445;
if ( wcs_get_subscription( $sub_id ) ) {
if ( wcs_get_subscription( $sub_id )->get_status() == 'active' ) {
$class = 'notice notice-error';
$message = __( '445 is ACTIVE', 'sample-text-domain' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
} else {
$class = 'notice notice-error';
$message = __( '445 is NOT-ACTIVE', 'sample-text-domain' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
} else {
$class = 'notice notice-error';
$message = __( 'NULL', 'sample-text-domain' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
}
add_action( 'admin_notices', 'wcs_is_sub_active_notice' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment