# WooCommerce Lottery

Last updated: 3rd Feb 2026.

Thank you for purchasing our plugin. If you have any questions that are beyond the scope of this help file, please feel free to email via contact form here. Have fun!

## Change Log

#### Warning:

Always backup WordPress database and files before updating to latest version, just in case!

#### Note:

If you override default and use custom templates in your_theme/woocommerce/ you need to make sure that templates are updated with those in plugin_dir/templates/ - otherwise some new features might not show up on the site.

    ** Version 2.2.8  **
    - Fix: WooCommerce email previews
    - Fix: shortcode issues
    - Fix: performance improvement
    - Add: history tab pagination
    - Add: set default number of winners to 1

    ** Version 2.2.7  **
    - Fix: recent_lotteries shortcode added lottery_status="active" attribute

    ** Version 2.2.6  **
    - Fix: my_lotteries shortcode fix
    - Fix: check in remove_lottery_from_user_metafield function

    ** Version 2.2.5  **
    - Fix: datepicker JS naming

    ** Version 2.2.4  **
    - Fix: db optimization (indexing)
    - Add: always use default datepicker JS

    ** Version 2.2.3  **
    - Fix: draw issue when having more prizes than tickets sold
    - Fix: small fix for HPOS compatibility
    - Fix: code cleanup

    ** Version 2.2.2  **
    - Fix: performance improvement, removed obsolete add_post_meta lines

    ** Version 2.2.1  **
    - Fix: fatal error in email templates

    ** Version 2.2.0  **
    - Add: lottery related sort for base page
    - Add: lottery relates sort in customizer for shop page
    - Fix: variables for email actions

    ** Version 2.1.12  **
    - Add: HPOS compatibility
    - Add: scheduled sale price like simple products
    - Add: actions woocommerce_lottery_product_loop_lotteries_winners_header, woocommerce_lottery_product_loop_lotteries_winners_body
    - Fix: code cleanup

    ** Version 2.1.11 **
    - Fix: optimization - reduced number of calls to db
    - Add: optimized function lottery_get_user_display_name_by_id() instead of get_userdata()

    ** Version 2.1.10 **
    - Fix: sleep() check
    - Fix: datetime format for lottery_winners shortcode
    - Fix: warnings

    ** Version 2.1.9 **
    - Add: filter woocommerce_lottery_max_purchase_quantity

    ** Version 2.1.8 **
    - Fix: cache
    - Fix: small bugs

    ** Version 2.1.7 **
    - Fix: Dokan double ticket problem
    - Add: filter woocommerce_lottery_entry_list_perpage
    - Fix: entry list compatibility with Yoast SEO
    - Fix: entry list compatibility with RankMath SEO

    ** Version 2.1.6 **
    - Fix: cache problem

    ** Version 2.1.5 **
    - Fix: duplicate queries
    - Fix: JS quantity bug
    - Add: login at later stage of checkout

    ** Version 2.1.4 **
    - Fix: lottery stuck if there is on hold order for lottery
    - Fix: template bug with future lotteries
    - Fix: show additional custom content in email notifications
    - Fix: caching and future lotteries

    ** Version 2.1.3 **
    - Fix: translations
    - Fix: lottery winners shortcode problem
    - Add: lottery winners shortcode paging

    ** Version 2.1.2 **
    - Fix: potential performance issue
    - Fix: meta fields caching fix
    - Fix: fatal error

    ** Version 2.1.1 **
    - Fix: potential cache issue

    ** Version 2.1.0 **
    - Add: entry lists
    - Fix: lost password redirect
    - Fix: checkout redirect
    - Fix: stock decimals when cancelling order

    ** Version 2.0.6 **
    - Fix: problem if MySQL auto_increment_increment variable has value bigger than 1
    - Fix: show tickets available above progress bar
    - Fix: performance

    ** Version 2.0.5 **
    - Fix: performance
    - Fix: stock input

    ** Version 2.0.4 **
    - Add: show SKU
    - Add: tickets sold label above progress bar (or tickets available)
    - Fix: don't show future lotteries if this option is enabled in lottery settings

    ** Version 2.0.3 **
    - Fix: participate button tax display issue
    - Fix: sourceMappingURL not found
    - Add: fully tested with PHP8 and WooCommerce 5.0

    ** Version 2.0.2 **
    - Fix: small bug
    - Fix: countdown timer JS issue

    ** Version 2.0.1 **
    - Add: [vendor] tag for email notifications recipients
    - Fix: small bugs

    ** Version 2.0.0 **
    - Add: Elementor support
    - Add: updated POT translation file
    - Fix: lotteries winners shortcode problem

## Overview and Features

### WooCommerce Lottery

WooCommerce Lottery is a lottery / giveaway extension for WooCommerce. We tried to make it easy to use but also to include all features you might need for a giveaway or lottery. With this plugin you will get a powerful lottery solution for WordPress which is easy to setup and customize.

With WooCommerce Lottery plugin you can setup WordPress lottery website or giveaway in less than 30 minutes (assuming you have payment processor ready - for giveaways you don't even need payment processor). WooCommerce Lottery plugin integrates seamlessly with WooCommerce and no special knowledge is needed.

Watch video explainer for WordPress Lottery plugin

Watch video explainer for WordPress Lottery with Pick Number mod plugin

### Overview and Features

- Works with latest WordPress and latest WooCommerce and previous versions
- Seamless integration into WooCommerce via its hooks
- Elementor support from v2.0 - check our Elementor tutorial for WooCommerce Lottery
- You get new type of WooCommerce product type – lottery
- Define number of lottery winners – 1 or more
- Lottery ticket price can be zero, works with TeraWallet / Credit payment gateways
- Winners / users can win single prize or multiple prizes
- Option for refund tickets with single click if lottery has failed
- Option for instantly finish lottery if max number of tickets was sold
- Option for extending lottery end date with all previously sold tickets (ticket rollover for failed lotteries)
- Manually relist lottery and option to delete previous lottery data after relist
- Manually extend lottery end date for failed lotteries (keeps lottery participants)
- Define minimum and maximum number of tickets available
- Define max tickets per user, number of winners and multiple wins per user
- Set start and end time for lottery
- Entry lists (see demo) for lotteries, read entry lists tutorial
- Easily control how you want to display lotteries – along with other items or on separate page
- Widgets with ending soon, future, latest / recent, featured, recently viewed, my lotteries and random lotteries
- Email notifications (with editable templates) for lottery win, fail, finish, no luck, lottery fail for customers, lottery extended
- Lottery product has lottery icon (label) on thumbnail
- Product single page has new tab “Lottery History”
- User has “My lotteries” page where one can see active lotteries and won lotteries – page with shortcode [my_lotteries]
- Lottery filtering in product list (wp-admin)
- Lottery product has icon which describes different lottery status: active, finished, finished and paid, failed (wp-admin)
- Plenty of shortcodes including shortcode to show my lotteries for logged in user
- Make lottery from any type of WooCommerce product – simple, virtual or downloadable products
- Manually delete any ticket via WooCommerce order management – deleting order deletes ticket
- Login at later stage of checkout (guest checkout)
- WPML compatible, translation files
- works with WooCommerce API - read WooCommerce API tutorial
- Enable users to create and submit their lotteries / competitions / lucky draws and you as site owner can charge a fee (via multivendor plugin like Dokan)
- Cronjobs required – if your host does not support 1 minute cronjobs you can use 3rd party cron service like easycron - plugin works with WP cron too
- Pick Ticket Number Addon - extension for Woo Lottery (additional fee) - check video, check demo and screenshot gallery
  Features Included in Addon:
  - ticket number pick (ticket number grouping in tabs)
  - randomly assign ticket numbers
  - instant wins (with CSV import)
  - skill based competitions with question / answers
  - manually pick winning number(s) - for live draws or service like https://www.random.org/
  - manually add ticket numbers for user (postal entries)
  - ticket reservations to prevent duplicate tickets during order process
  - can be customized with bespoke features
  - 🚀 Get It Here

## Installation

Source: https://codex.wordpress.org/Managing_Plugins#Installing_Plugins

You can install plugin via WordPress "Add New" plugin - to do that download zip with plugin only (installable WordPress files), click add new and that's it. In case you do not have permissions to upload to plugins/ directory you will need FTP login info and upload plugin via FTP. Make sure to install WooCommerce before you activate WooCommerce Lottery plugin.

Alternative setup. After downloading WooCommerce lottery plugin, extract plugin zip and upload it to your plugins directory - wp-content/plugins/ folder of your Wordpress installation. Since this is extension for WooCommerce you need to install WooCommerce before activating the plugin. WooCommerce plugin which can be downloaded here.

If you need help installing Wordpress see the link here

#### Note:

Once you installed and activated WooCommerce go to WooCommerce > System Status and make sure that you don't have red colored errors (specially for WP memory limit). Make sure to enable inventory management in WooCommerce!

WooCommerce Lottery plugin uses cronjobs and you have to setup one cronjob:

- every minute: /usr/local/bin/curl --silent http://www.your-domain.com/?lottery-cron=check

Here is screenshot of cronjobs page and setup in DirectAdmin control panel

More details about cronjobs can be found by googling "how to add cronjob in cPanel / DirectAdmin". If you don't know how to add cronjob the best and the easiest way is to email your hosting support to do it for you (purpose of hosting support are tasks like helping you with cronjobs, our support helps you with plugin issues - cronjobs are hosting related task / issue).

Why do we use and suggest real server cronjobs? Plugin will work with WP cron but disadvantage of WP Cron is that it will trigger only when someone visits your website, if there is no site activity for say 3 days, the cron will not be triggered for 3 days but next time you have visit on your website. Real server cronjobs do not depend on website activity and are run in fixed defined intervals as set in cronjob config.

#### Note:

If your hosting company does not support one minute cronjobs we suggest that you move your website to more serious hosting company or use service like EasyCronOur plugin is meant to be used as ecommerce solution which will / should earn money so we suggest you to invest in proper hosting (which at least supports one minute cronjobs).

Why do we use cronjobs? - WordPress cronjob is run on every visit (page load), it's fine for small and not so busy websites. But sometimes you do not have enough hits (visitors) and lottery will be finished when visitor loads page (and cronjob) instead on its end timestamp. User visit which triggers cron will be taking some time to process everything so it is better that cron does that in background than leave user waiting cron tasks to finish. That's why we use real cronjobs - to make sure your lotteries will end on time. Also on busy websites you need to turn off WordPress cron and create cronjob for it to avoid cron being loaded on every hit and generating performance penalty.

#### Install WooCommerce Sample Data:

Source: https://woocommerce.com/document/importing-woocommerce-sample-data/

WooCommerce comes with sample data which you can import, dummy data file is /wp-content/plugins/woocommerce/dummy_data.xml Sample data does not include lottery products, it provides data to populate WooCommerce store with some demo products, ratings, comments, etc. Steps to import demo data to your WordPress WooCommerce site:

1. Go to Tools > Import
2. Select XML dummy content file from /wp-content/plugins/woocommerce/dummy_data.xml
3. Click Upload file and import
4. Assign posts to an exitsting account
5. Check Download and import file attachments
6. Click Submit and wait until WordPress finish downloading attachments and importing content

#### Warning:

Importing dummy data can take some time, specially on slow Internet connections. Be patient and do not close or refresh browser tab until import operation is completed.

## Quick Lottery Setup

Setting up new lottery is easy:

- make sure all steps from Installation are done (WooCommerce installed, plugin enabled, cronjobs set)
- go to Products => Add Products
- add title, description, images, featured image, select category - all things you do when adding regular product
- in Product Data dropdown menu select Lottery
- you will see new tab in left menu named Lottery, see screenshot:
- fill all details (they are self explainable)
- set lottery duration by setting start and end date
- publish product (lottery)

In WooCommerce Settings -> lottery you can set lottery base page where you display a list of all lotteries (archive page). Please see note if you want to set your lottery page as home page. If you have lottery only website there is no need to setup lottery base page, you can use WooCommerce shop page.

When creating new lottery make sure to create it via add new product rather than cloning product or existing lottery. If you clone / copy existing lottery all custom meta will be cloned. That means if lottery has finished, meta field that defines finished lotteries will also be cloned and lottery will always look like it is finished. To create new lottery from existing one use relist feature.

If you need to trash / cancel order please go to edit order, cancel it by changing order status and then trash it. That is proper way to do order cancellation for lotteries, otherwise (if you just trash order) log data can be left in lottery logs.

#### Note:

Make sure that when setting up lottery site your lottery base page is different than your home page. If you need lotteries on home page use shortcodes or widgets to display them on your home page.

## Changes in WooCommerce

After you activate WooCommerce Lottery plugin couple new options will appear:

1. WooCommerce product has new tab in Product data block called Lottery
2. Product list has column with lottery status icons - requires Product Type Column plugin
3. Product list filter has lottery filtering
4. Single product page in wp-admin has new block named "lottery" where you can see lottery history
5. WooCommerce settings - new tab called Lottery
6. WooCommerce settings - Emails - new items: lottery win, lottery fail, lottery finish, lottery no luck email templates
7. New widgets: future lotteries, ending soon lotteries, featured lotteries, latest lotteries, recently viewed lotteries, my lotteries, random lotteries
8. New shortcodes

New WooCommerce product type lottery:

Lottery edit product screenshot (with Pick Number Mod addon for WooCommerce Lottery):

## Plugin Options

Settings are mostly self explainable, please see screenshot below. You can enable or disable showing past and future lotteries, another useful setting is whether to mix regular products with lotteries or just show lotteries on separate page (defined via WC Lottery Base Page dropdown option, see screenshot).

Screenshot above includes available settings for Pick Number Mod addon for WooCommerce Lottery (options listed under title "Lottery pick number and answer" are related to Pick Number Mod addon).

On screenshot below you can see how product list with lotteries looks like. Lottery status icon colors: red - active lottery, orange - finished, red - failed. Column “product type” (with icons) on the products admin screen in WooCommerce was removed in version 3.4.0 and in order to see icons you need to install WooCommerce Product Type Column plugin. See FAQ item no 30.

If lottery has failed, in product / lottery details you will see option to "Refund" or buttons to "Relist" or "Extend" lottery. "Refund" enables you to refund all tickets to participants if your lottery rules require that and your payment gateway supports refunds. "Extend" allows extension of end date keeping all current participants (and their orders) while "Relist" resets lottery and it starts with 0 participants. Only failed lotteries can be extended (or refunded) while all finished lotteries can be relisted. See FAQ item no 32.

Once lottery is finished you can view winners on single lottery page or in wp-admin edit product page. Below are screenshots.Beside that you can create my lotteries page for users where you can use this shortcode: show user's lotteries (active lotteries in which user participates and list of user's won lotteries) -[my_lotteries]

In lottery details block with lottery history entries enables you to view and delete ticket orders, export them to CSV or Excel and view history prior relisting. Check screenshot below. Failed lotteries can be relisted (restarted - meaning participants will be lost) or extended (end date will be changed) keeping all current participants.

## Winner Picking - How WooCommerce Lottery chooses winners

### How WooCommerce Lottery chooses winner without Pick Number Addon - when there are no ticket numbers?

After successful order and payment we log user’s ID to a lottery log - if user purchased 10 entries for a lottery then lottery log will have 10 rows of user ID along with order ID and timestamp. So more tickets user purchase more entries are there in lottery log.

Once lottery ends, we create list of user IDs from that lottery log, more entries user purchased more chances user will have due to list being filled with more of user IDs. Then random function chooses one or more user IDs which are in fact winning IDs. We then send won notification to those users.

### How does Lottery plugin pick winners (or winning numbers if you use Pick Number addon)?

Winner(s) are picked randomly once lottery is finished or you can manually enter winning number(s) on edit lottery page. Plugin uses mt_rand PHP function to randomly pick winners. PHP function mt_rand() is used (provides solid randomization for this purpose).

#### Warning - number of sold tickets:

If you use WooCommerce Lottery (also with Pick Number Mod addon) and for example you have setup lottery with max 100 tickets and min 50 tickets, then if you sell 55 tickets winner(s) will be choosen between those 55 tickets not all 100 tickets.

#### Warning - manual winner picking:

With Pick Number Mod addon you can get also different behaviour with enabled checkbox option called "Manual winner picking", meaning that when lottery ends and after you generate winning numbers (for example via national lottery numbers or random.org service) you will enter numbers in text input field. It is then possible that your lottery could end without winners (if none of participants picked winning numbers).

#### Warning - wrong answers:

With Pick Number Mod and question / answers feature enabled winners will be choosen among those with correct answer only (can be disabled). In case you are manually entering winning numbers you will need to be sure that winning number has correct answer - this can be seen in lottery history table block (which you can export to Excel or CSV for easier management).

## Shortcodes

Here is a list of all available plugin shortcodes. Some shortcodes accept optional orderby and order attributes. Shortcode [lotteries] implements paging and attributes like [products] shortcode in WooCommerce - see list of all available options here. Other shortcodes do not implement those attributes.

- show lottery winners - `[lotteries_winners], [lotteries_winners paginate="true" limit="12" order="desc"]`
- show featured lotteries -`[featured_lotteries], [featured_lotteries paginate="true" limit="12" columns="4" orderby="date" order="desc"]`
- show ending soon lotteries - `[ending_soon_lotteries], [ending_soon_lotteries paginate="true" limit="12" columns="4" order="desc" future="no" lottery_status="active"]`
- show recent lotteries, lottery_status="active" attribute filters out finished lotteries - `[recent_lotteries], [recent_lotteries paginate="true" limit="12" columns="4" orderby="date" order="desc" lottery_status="active"]`
- show future lotteries - `[future_lotteries], [future_lotteries paginate="true" limit="12" columns="4" orderby="date" order="desc"]`
- show lotteries (with specific product ID) - `[lotteries ids="1,2,3,4,5"]` this shortcode supports attributes (pagination and sort) similar to WooCommerce [product] shortcode complete list of options is here
- show user's lotteries (active lotteries in which user participates and list of user's won lotteries) - `[my_lotteries], [my_lotteries paginate="true" limit="5"]`
- show past / ended lotteries - `[finished_lotteries], [finished_lotteries paginate="true" limit="12" columns="4" order="desc"]`
- shortcode for lucky dip with quantity example (Pick Number Mod addon only) - `[lottery_lucky_dip_buton qty="5" label="buy 5 tickets"]`
- shortcode to display all instant wins (Pick Number Mod addon only) - `[lottery_all_instant_wins paginate="true" limit="5" orderby="title"]`
- shortcode to display all instant winners (Pick Number Mod addon only) - `[lottery_all_instant_winners limit="5"]`
- shortcode to display all instant winners tab (Pick Number Mod addon only), if you use this shortcode you can disable instant wins TAB in Woo Settings > Lottery settings - `[lottery_instant_winners_tab]`

Reference for each shortcode we have can be found in public\class-wc-lottery-shortcodes.php and public\class-wc-shortcode-lotteries.php

### WooCommerce Lottery

#### Love this plugin?

This plugin is created by wpgenie. Check out our Envato profile where you can support us by purchasing our plugins, give us feedback and post your ideas and feature requests, ask for support and rate our items. Check out our free stuff.
We do WordPress developing, plugins for WordPress & WooCommerce, eCommerce sites based on WooCommerce, WordPress performance optimization and managed WordPress hosting.

View Demo Buy Plugin Optipress
@ Facebook @ Twitter @ YouTube @ Pastebin