Blocks ::: block_coupon
Maintained by Sebsoft Plugins, Rogier van Dongen
The Sebsoft Coupon Plugin offers you the possibility to create coupons for various levels of course access. Using a coupon code, users will be enrolled into courses that are attached to the coupon.
Latest release:
561 sites
84 fans


The Sebsoft Coupon Plugin offers you the possibility to create coupons for various levels

of course access. Using a coupon code, users will be enrolled into courses that are attached to the coupon. That way, you can use the coupon system as voucher or vouchering system for your course(s).

There are a few different ways of generating coupons:

- Course level: this means one or more course(s) need to be selected for which the coupon is valid.

  Once the coupon code is entered by a user, he or she will be enroled in every course the coupon

  is attached to.

  A nice extra feature is, when groups are configured for a certain course, you can configure which

  course group the coupon is for. When a user claims the coupon, he or she will be added to that specific

  group in the course. This makes it possible to separate coupon users from regular users.

  You could also make specific course groups every time you generate a batch of new coupons, so there's

  some way of matching a batch of coupons to a group of users. The possibilities are numerous.

- Cohort level: this means one or more cohort(s) need to be selected for which the coupon is valid.

  Once the coupon code is entered by a user, he or she will be added as a cohort member for every

  cohort the coupon is attached to.

  NOTE: When generating cohort level coupons, there is a possibility to "connect" extra courses to

  a given cohort. One MUST know that upon doing this, the courses will at that point be added to

  the cohort enrolment sync. Without knowing this little fact, it could be "unexpected" behavior,

  even though it's a logical step.

Furthermore, coupons can be generated on two "access" levels:

- Personalized. The base of this, is either a CSV is uploaded, or a CSV is given directly in a textbox.

  The needed user information for every coupon to be generated will be the user's name, email address

  and gender.

  These coupons will then be generated and sent off to the appropriate users using a background task.

- Bulk: The base of this is simple: you generate a certain amount of access coupons, which will then

  be emailed to the pre-configured recipient or (if allowed) to an emailaddress that can be freely entered.


  Wherever possible, please use PNG images.

  Also, whenever possible, do NOT use images that have an alpha channel.

  This will MASSIVELY slow down processing time, due to internal conversion of images by TCPDF.

  On our tests, for a 300 DPI image on A4 format (2480 x 3508 pixels) with an alpha channel,

  rendering a single PDF took around 25 seconds. Taking the alpha channel out of the image,

  rendering a single PDF was reduced to around 3 seconds.

  This means the PNG images should _always_ be stored as 24-bit true colour images.

  _Do not use 32-bit_ (true colour + transparency)!

  Furthermore, whenever possible, have the coupon generator create a single PDF with all

  coupons (this is only applicable when generating coupons in "bulk" mode). The process of

  generating coupons has been optimized to only "use" the image 1 time when creating any amount

  of coupons in a single PDF. If you choose the option to create a seperate PDF for every coupon,

  the image will have to be rendered for each and every PDF.

  This has 2 major downfalls:

  1. Every PDF will roughly have a slightly bigger size than the image size (in our tests, 350 - 400 kB per PDF)

  2. Every PDF takes the full amount of time to render.

  Effectively, this means the following (using fictitious sizes):

  10 coupons, single PDF -> result is around 400 kB, rendering takes around 3-4 seconds.

  10 coupons, seperate PDFs -> result is around 4 MB, rendering takes around 35-40 seconds.


- Copy the coupon folder to your blocks directory.

- Go to the moodle admin pages (you will probably be confronted with it anyway) and install the plugin

- Configure the main settings for the plugin.

- We're set up for usage!


There are only two pages you can add the coupon block on. This is the site's frontpage

or the user dashboard (my) page. The main reason for this is because the block is the

"frontend" for users to enter their coupon or voucher code.

Administrators and users with the correct capabilities will also see the links to

the coupon administration pages and the coupon generator page.


There's two main configurations to consider when generating coupons.

For course type coupons, this plugin attempts to enrol a user through use of Moodle's

internal function "enrol_try_internal_enrol".

The Moodle documentation shows it will attempt to enrol you using manual enrolment.

For this reason manual enrolment MUST be enabled for these courses.

For cohort type coupons, a user is made a member of a cohort. That's all there is to it.

Surprise though, if you want to actually make a user have access to a course, you

probably want to configure cohort enrolment for the course.

For those paying attention, creating cohort type coupons thus enables a simple

way of enrolling users into multiple courses at once just by configuring the right

cohort enrolments in multiple courses.

That's still not to say course coupons can't be used in a similar way (using meta courses).


Screenshot #0
Screenshot #1
Screenshot #2
Screenshot #3
Screenshot #4
Screenshot #5
Screenshot #6
Screenshot #7
Screenshot #8


Sebsoft Plugins (Lead maintainer)
Rogier van Dongen
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Tue, Jan 12, 2021, 12:08 AM
    Hi Rogier,
    Is there any way that you can programmatically redeem a coupon without a user having to submit the code?

  • Tue, Jan 12, 2021, 1:00 AM

    @Brendan McNamara,
    If you have the capability to log in as a different account, you can redeem the coupon using his profile. Follow the steps:
    1. Go to the user's profile page
    2. Under the administration category, click on Log in as
    3. Go to the Dashboard page and redeem the coupon code for him.
    4. Log out to exit the user's account.

  • Tue, Jan 12, 2021, 6:45 PM
    Thank you Thodoris, however I really need something that automates redeeming a coupon. If anyone knows a way to do this I'd be grateful.
    Also, does anyone know whether it is possible to create a coupon which will allow access to Moodle between two dates, so a start and end date.
  • Thu, Jan 28, 2021, 5:29 AM
    Cannot see how to implement on moodlecloud. Any help?
  • Tue, Feb 2, 2021, 1:18 AM
    Does the Coupon module provide any type of REST API? It would be great if I could automate the generation of coupons. It would allow a nice integration with other systems we use.
  • Tue, Feb 9, 2021, 10:05 PM
    @Mike There _is_ an API, exposed through Moodle's webservices, that should enable you to get started with your question.
    In any case, if you have more specific questions, please do not hesitate to send me an email (look in the source code for the correct email address).

    @Brendan: automating the redemption of a coupon is not possible as such. One big reason for not allowing this is because the couponcode/vouchercode claimed will be attached/linked to the user that was logged in when redeeming the coupon. Automated redemption would mean that information is missing and, at least at this moment, is not supported by the database model.
    ALso, can you specifiy a little more about that start- and enddate? The normal flow of possibilities at this moment is to have an enrolperiod, but please note this is applicable _from the time of redemptio_ onwards. Specifying a start- and enddate was deliberately not taken into account when first developing this plugin, due to the fact this could mean you're unenrolled from a course within a very short timespan (say; with startdate Dec 01 202 and enddate Jan 15 2020. Now if someone redeems on Jan 14th; they WILL be unenrolled the next day).

    @David: MoodleCloud only provides core plugins and a small subset of extra plugins. There's no option to install your own at all, so Moodlecloud maybe isn't the correct solution if the coupon plugin is critical to your business case. If anything you _could_ ask if they would install the coupon plugin, but I seriously doubt this will be honoured. This is all explicitly stated on the Moodle cloud website, on the frontpage, under "Can I install my own plugins?".
  • Tue, Feb 9, 2021, 10:17 PM
    @Hiro: this really looks like something is wrong with your installation. Also please note some of the actions _require_ a cron job running on the background (or, alternativaly, running it from your browser using /admin/cron.php).
    If you still keep running into issues, take a look at the mailtest plugin (local_mailtest). This could possibly provide some insights as to why email isn't received or sent.
    It's hard to say anything about why emails may or may not be received without extensive extra information or at least take as many steps as possible to exclude all other (core) processes from being erroneous. Then still it can be hard to say anything about any realistic cause.
    The only "other" way that we've been able to tackle _any_ problems at all came from a subsystem that actually logged the communication with the receiving mailserver, but keep in mind this is regarded as an extra communication layer/tier and most likely not applicable to you. _If_ you do not connect to an external SMTP, but rather use the internal sendmail() functionality, you may also be able to get more information from there provided any communication is actually logged. However, once you venture there, keep in mind this is no longer within the scope of the plugin.
  • Wed, Feb 24, 2021, 9:30 PM
    Hi everybody,
    Awesome plugin. Thank you I have used it for years!
    One question regarding coupon generation using APIs: is there any plan to add parameters such as the enrollment period for example? or trigger an email with the default options?
    Thanks a bunch!
  • Thu, Feb 25, 2021, 4:47 PM
    @Hugh: thank you for noticing. The services are quite often "forgotten". Please be aware you can also add issues on the github repository.
    I will take this into account with the next release and added an issue to the github issue tracker smile
  • Thu, Mar 18, 2021, 7:13 PM
    This plugin is really useful and works well. Can you tell me: where does the Coupon code create the cohort sync method(s) when generating cohort coupons? I'm thinking of trying to extend the functionality to that the cohort sync method is created up with a Group name as well.
  • Mon, Mar 22, 2021, 5:03 PM
    Hi Joanne, the cohort sync is created in step/page 2 of the process (see /coupon/classes/controller/generator/cohortcoupon.php around line 175).
    Of course you could always do a pull request on the repository in case you added (relevant) functionality. If you have any more you can contact me in person or through the GIT repository (insert an issue from there).
    Cheers, Rogier
  • Mon, Mar 22, 2021, 6:44 PM
    Thanks very much, Rogier. I'll do a pull request after I've complete my mods so you can see if the added functionality is worth including.
  • Mon, Mar 22, 2021, 10:28 PM
    Hello there, thanks for your cool plug-in. We want to use your plugin for persian/fa language & want to know is there anyway to edit the default texts printing on the coupons pdfs? [specially coupon request pdf since it doesn't have an option to just show the code to user to download it in csv & it's only available in pdf format]

    & also is there a way to fix the issue with printing persian alphabet? It shows ????? in the pdf instead of text.

    Sincere Regards
  • Mon, Mar 29, 2021, 5:06 PM
    Hi Hoda,
    The texts printed on the PDF can be adjusted through the language files (please use the language customisation tool in Moodle).
    So far, we've not tested persian/fa languages, but we are familiar with the challenges (unfortunately it doesnt work "just" out of the box in this case).
    It should be a somewhat simple enough fix, at least to get the characters to print correctly. I'll look into it. You can pass me a personal email if you're willig to help out with testing (find it in de source code or just pass a note through the github repository).
  • Logo Sebsoft
    Tue, Jul 27, 2021, 7:20 PM
    A new version has just been published.
    This contains a number of fixes to how errors are displayed if something went wrong with the QR code or the coupon was already used.
    Furthermore, we've added a new feature which allows you to process signups via Coupon, even if site wide signups are disabled (this feature is disabled by default).

    Cheers! Sebastian
1 2 3 4 5 6 7 8 9 10 11 12
Please login to post comments