Use a user meta entry to store the information that this user has received the coupon already. Then check this user meta before you print the button:
Plugin code:
function coupon_button()
{
$post_id = get_the_ID();
$user_id = get_current_user_id();
$coupons_received = (array) get_user_meta( $user_id, 'coupons_received', true );
if ( in_array( $post_id, $coupons_received ) )
return '';
return get_submit_button( 'Get Coupon', '' );
}
function update_coupon_status()
{
$user_id = get_current_user_id();
$coupons_received = (array) get_user_meta( $user_id, 'coupons_received', true );
$coupons_received[] = get_the_ID();
update_user_meta( $user_id, 'coupons_received', $coupons_received );
}
Template code:
print coupon_button();
And when you show the coupon, use the update function:
update_coupon_status();
Related Posts:
- limit selection of custom taxonomies to one?
- jQuery UI in Admin (Best Practice?)
- Getting a div content of a post in wordpress?
- Debug whats going on inside a function called from AJAX
- How to save the checked boxes?
- Timepicker-addon doesn’t show – Datepicker works fine?
- Query Custom Post Types & category_name?
- Custom post type with file upload – need to “set as field” instead of “send to editor”
- different template for first and second level custom post page
- Filter categories of posts with checkboxes
- window.send_to_editor and jQuery .attr() conflicts with multiple custom upload image meta boxes
- Open div inside a custom post-type with Fancybox
- Getting the URL of the parent page
- Custom post type – use ajax to display sub pages
- Load Next Posts With AJAX not working with custom post type
- Dynamically output a class to an anchor tag depending on what tag is chosen
- Why won’t this jQuery code work?
- Custom Post Type Slick Slider “$ is not a function”
- WordPress notification if new post published
- passing values from functions.php to template
- How to Query in WordPress which shows Alphabetic Posts?
- Revert to previous dropdown options after change
- Creating a Tabbed Widget
- How can I implement jQuery plugin correctly with my CPT?
- Masonry Append WordPress posts with singleMode
- Displaying information from custom field on custom post type
- I can’t connect my custom jquery to wp admin
- Weird issue where form field loses focus to previous form field even with JS disabled
- Display custom-post type based on the Title matching the current selected value
- jQuery UI & Admin (Calendar)
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- How to submit the date with ajax?
- How can I create a button that when clicked populates a div with a list of foods that are checked as a certain type of ACF?
- how to display new private message to users?
- load wordpress events into full calendar jquery
- CPT not entering jQuery ready state
- Filterable portfolio in WordPress using jQuery isotope
- Collect custom post in a calendar
- Submitting custom post from frontend,jQuery ajax, and custom validation – can’t find proper place to insert wp_insert_post()
- jQuery tab_title already in use
- Toggle a metabox based on a selection
- Loops running into each other
- Add text to metabox input text field from Thickbox
- Add a class to a menu item depending on a body class
- How do loop categories post from according in WordPress? is it impossible to solve this problem?
- Query all posts where a meta key does not exist
- How to Add Custom Taxonomy To Woocommerce Plugin
- Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error
- Render a different post/template from within the template_include action?
- Can you have two CPTs with the same permalink structure?
- Custom templates for posts like for pages: page-{id} vs single-{id}
- Alphabetical sorting of custom post type – one letter per page
- Post Via Email to a Custom Post Type
- Quickest way to get last or oldest post date – WP Query
- Adding class to featured image
- How to redirect wp-admin/index.php to a custom post type?
- get_post_meta is returning image id
- How many Custom Post Types to register?
- Custom Post type is being ignored in query
- Query custom post type by category slug
- Insert & order custom post types in/as submenu
- How to bulk copy custom fields between custom posts?
- Search / Filter posts on Title/Content OR Tags
- map_meta_cap woes
- WordPress combined with a basic MYSQL table [closed]
- How to get post type and month/year before while loop for date.php file
- School & class blogs: Categorize with categories or custom posts?
- How can I group posts by months and years?
- Displaying a div from an assigned meta_value when on a page
- Custom query – get_the_terms not work
- Programmatically change post visibility on save_post action return a 500
- How to select a template for a custom post type?
- Proceed to the next video of the custom post type but remain on the same post
- How to show the current category of an article with CPT UI
- How to show custom field on specific custom post type posts only when filled
- duplicate comment section functionality and call it something else for custom post types
- Custom Post type registering as page post type
- Custom Posts and Posts – next_post_link and previous_post_link not working together
- Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
- Display a random customposttype2 excerpt in single-custompostype1.php that shares same taxonomy
- display two images in theme header.php file
- Checking for custom field in admin pages
- Best way to fix bad count on All | Mine | Published
- Cannot manage to display my CPT in Recent Posts widget
- DIVI Theme customizer changes not applied on existing pages and designs are not shown on the front
- How to sort by multiple values in a nested WP_Query
- Apply a custom Template to a Custom Post Type from within a plugin
- Different Configuration for the_excerpt()
- Loading a stylesheet on a specific page [duplicate]
- How do I block/redirect ‘?post_type=cpt_name’ urls?
- Simple renaming my custom post type set with a plugin doesn’t work?
- can’t see categories in appearance-menu-categories
- Meta-Box to add multiple items one at a time and on publish save all
- Values inside a custom field to determine which category posts to display
- CPT, Custom User Role and problem with user manager
- Display results from two Custom Post Types in page template
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- register_term_meta not working
- show posts under custom post type with same autj
- Delete old thumbnail when updating new