Snippets for showing coupons only to logged-in users and printing the current user's name on the print template.
These use standard WordPress functions together with Coupon Creator Pro hooks. Add them to a child theme's functions.php or a snippet plugin.
Show coupons only to logged-in users #
The simplest approach is to gate the shortcode output with is_user_logged_in():
add_shortcode( 'members_coupons', function () {
if ( ! is_user_logged_in() ) {
return '<p>Please log in to view coupons.</p>';
}
return do_shortcode( '[coupon_creator_multiple]' );
} );
For finer control, filter the loop query so logged-out visitors get no results. Pro exposes the coupon loop query args:
add_filter( 'cctor_pro_loop_shortcode_query_args', function ( $args ) {
if ( ! is_user_logged_in() ) {
$args['post__in'] = [ 0 ]; // match nothing
}
return $args;
} );
Print the logged-in user's name on the print template #
The print template fires cctor_print_before_coupon (and cctor_action_print_template) before the coupon renders. Hook it and echo the current user's name:
add_action( 'cctor_print_before_coupon', function ( $coupon_id ) {
if ( ! is_user_logged_in() ) {
return;
}
$user = wp_get_current_user();
printf(
'<p class="coupon-holder">%s</p>',
esc_html( sprintf( __( 'Issued to %s', 'coupon-creator-pro' ), $user->display_name ) )
);
} );
To place the name inside the on-page coupon (shortcode view) as well, use cctor_before_coupon or cctor_pro_before_coupon, both of which receive the coupon ID.
See Print Features for other print-template hooks and Pro CSS Reference for styling the output.