Home › Toolset Professional Support › [Resolved] Offline Coupon Creator
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Tagged: Setting up custom fields, Types plugin
Related documentation:
This topic contains 10 replies, has 2 voices.
Last updated by Raja Mohammed 3 years, 11 months ago.
Assisted by: Raja Mohammed.
I have a need that I want to know how I can do it with toolset.
I'll tell you about it below:
Coupon creator per campaign (this is a custom type)
- Type of campaign
- Accepted businesses (category)
- Coupon money
- Expiry date
There must be a coupon panel (this is a view of the coupons)
Here comes the hard part
Once the campaign is launched the user has the possibility to download it (a download coupon button appears) actually creating it.
Once the coupon is created it appears in the list of coupons assigned to the user.
The establishment has to enter a link to verify that this coupon is valid
- Assign the coupon (which is nominal and goes per user) to the establishment, and upload a photo
- The administrator is notified
Could you help me?
Thanks
Hello there,
It seems like You want to relate coupons with the users However i am not clear about a few things
1)
Once the campaign is launched the user has the possibility to download it (a download coupon button appears) actually creating it.
- I am not clear on what context you have mentioned "actually creating it" assuming you are creating unique coupons for each users for the specific campaign, is that correct ?
2) Please clarify about the establishment and how they are connected to the coupons , From what i understand each coupon is related to a user and also to the establishments assuming establishments as businesses
If my understanding of 1 and 2 are correct this can be achieved by creating a custom post type for Coupon that has the custom fields to store the user and establishment values, So once user clicks on download a unique coupon is generated in the Coupons post type with the user filed filled with the details about the downloaded user. You might need some custom coding to add the values based on your conditions.
You might also want to relate Coupons with Campagin in such case you can make use of the One to Many Post relationship where each campaign can have more than one coupons. so it will be easier to query on the coupons based on the campagins as well.
With Coupons as custom post type you can set their validity and once the establishments enter to verify the coupon it can be checked against the coupon. So, start there, and then expand on building and adding custom fields to Coupons post type as required.
I hope this helps better.
Kind regards
Raja
Thanks you for you reply,
When a campaign is launched the user is presented with a button to create the coupon. This is the moment when the coupon has to be created assigned to that user.
Then in that case you should have a separate post type for coupons and associate it with the Campaigns, Which i have explained in my previous reply under the second point https://toolset.com/forums/topic/offline-coupon-creator/#post-1838841
Let me know you need more assistance on how to proceed in this case.
Yes, I would have a campaign that could generate as many coupons as I wanted, and those coupons would be a 1 to 1 relationship with the user.
But can I make the user "generate" the coupon? and have that coupon registered to his "name"? User have a button said generate coupon (when campaign are avaliable)
Basically you need a CPT for Campaign and For Coupons and associate them with one to many post relationship.
User and post type cannot have a 1 to 1 relation ship, You should either save the coupon id to the current user meta or you can store the user id to the coupon meta. this needs to be done using the WordPress functions during the form data submission process, Which i have explained below
- For the Coupon generation you can create a new post type form for the coupon post type with just the submit button and a generic hidden field which takes the current post id of the campaign, we will use this field to associate the coupon with campaign.
the field would be
[cred_generic_field field='campaignid' type='hidden' class='' urlparam=''] { "required":0, "validate_format":0, "default":"[wpv-post-id]" } [/cred_generic_field]
Please note you might need to turn on the expert mode to add this code before the submit button
. Rename the Submit button as Download coupon.
- Use the Coupon generation form that displays only the Download button in the Campaign page
- Once the Coupon button is clicked you can process the form using the form APIs In this case i would prefer cred_save_data hook where i can perform the assocition of coupons with campaign and add the coupon to user data
add_action('cred_save_data', 'my_save_data_action',10,2); function my_save_data_action($post_id, $form_data) { // if a specific form if ($form_data['id']==12) { $campaign_id = intval($_POST['campaignid'); // get the campaign id from the hidden field and use it for post association toolset_connect_posts(['campaign','coupon'],$campaign_id, $post_id ); // Now add the coupon to the user meta using add_user_meta or add the user id to the coupon custom field using add_post_meta // add_user_meta https://developer.wordpress.org/reference/functions/add_user_meta/ // add_post_meta https://developer.wordpress.org/reference/functions/add_post_meta/ } }
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
Great! i will try it.
I have only two more question
this coupon I can create a random number for your identification? since the use is offline.
And finally, how can I create a coupon finder with that random number to indicate that it has been used offline in X commerce?
If you are using Toolset form to generate Coupon Post type then it will automatically create a post id for that coupon it is not a random one but a serialized list of id.
However, You can add a custom field to the coupon post type to store a random identifier and while saving the form data you can also save this custom field value to the coupon as mention in my previous reply add_post_meta to save the custom field in the cred_save_data hook.
I am sure about the last part of the question do you need a search filter to find the coupons based on random numbers ? If that is the case you can create a search view with custom field value so that you can input the details that would return actual coupon
https://toolset.com/documentation/legacy-features/views-plugin/front-page-filters/
However the second part of the question is something needs to be dealt in a separate thread. I would recommend start with the coupons fist and if you need more assistance in adding on more feature please open a new ticket so that it is easy to manage.
\Kind regards
Raja
I'm creating the custom type campaign where the bonuses will go.
CTYPE campaign has to have:
- start date
- end date
- and category of shop type where the vouchers are accepted
- total number of vouchers accepted (I have doubts about how to do this) For example not being able to create more than 1000 vouchers, but in other case this can be change.
Could you help me?
And also, I need to understand this
User and post type cannot have a 1 to 1 relation ship, You should either save the coupon id to the current user meta or you can store the user id to the coupon meta. this needs to be done using the WordPress functions during the form data submission process
I think we need save this information in both, user and coupon.
I generate a random slug to each coupon created and if i put this -slug like tittle of coupon, i need save this title in user fields, and an user in coupon information.
All the fields for the campaign post type can be setup as custom fields and for the total number of vouchers accepted you might need some custom function to hide or show the coupon creation button based on the number of coupons associated with the campaign. Since you can have a post relationship with Campaign and coupons you can use the Post Relationship Api toolset_get_related_posts where you can get the number of coupons associated with a particular campaign and use that to add a conditional for coupon creator, Let me know if you need more clarification on this
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
To save the information about the user to the coupons you can add a custom fields to the coupon post type to add the user infomration and during the coupon generation process where you associate the coupons with camplage you can also add the user id to the coupon custom field also you can add the coupon id to the user meta fields which i have mentioned in my preivous response here
https://toolset.com/forums/topic/offline-coupon-creator/#post-1841751