WooCommerce Lottery

Last updated: 11th Mar 2024.

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.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

** Version 1.1.27 **
- Fix: updating ticket quantity in cart
- Fix: max tickets number setting cannot be 0
- Fix: typos
- Add: lotteries shortcode now with paging and attributes like products WooCommerce shortcode
- Add: winner link in edit lottery leads now to user profile instead refreshing current page

** Version 1.1.26 **
- Fix: showing time left when it was disabled (in widgets)
- Fix: performance
- Fix: fatal error sometimes when Elementor is enabled
	
** Version 1.1.25 **
- Fix: reset stock when enabled "Remove ticket numbers from orders with wrong answer."
- Fix: wrong directory name
- Fix: version numbers

** Version 1.1.24 **
- Fix: decimal separator bug
- Fix: tickets per user limit in frontend
- Fix: tax ignored in display price
- Fix: required fields when publishing lottery
- Fix: wrong message for future lotteries in widget
- Add: do not mix lotteries with regular products disabled by default
	
** Version 1.1.23 **
- Fix: Add class variables for removing hooks
- Fix: Button change price with qty
- Add: Add hook lottery_product_save_data
- Fix: Added failed message with reason for user on single lottery page
- Fix: Changing order status after relist and delete log bug

** Version 1.1.22 **
- Add: extend lottery end date with all previously sold tickets (ticket rollover for failed lotteries)
- Add: delete logs on lottery relist
- Add: lottery failed notification for participants
- Fix: sold individually option problem

** Version 1.1.21 **
- Fix: Updating product lookup table
- Fix: Small bug when cancelling order
- Add: Added WPMU support

** Version 1.1.20 **
- Fix: stock problem with free lotteries
- Add: Added argument for future lotteries to ending_soon_lotteries shortcode [ending_soon_lotteries per_page='12' columns='4' order='asc' future='yes' ]
- Fix: Automatic partial refund
	
** Version 1.1.19 **
- Fix: Future lottery shortcode
- Fix: Dateformat fix for widgets and shortcodes
- Fix: Datetime format taken from WP settings for timestamp in lottery history tab
- Fix: Plain email template lottery_finish.php

** Version 1.1.18 **
- Fix: Adding lotteries to my lotteries field
- Fix: Changed ajax function call for deliting logs
- Add: New action on ajax deleting log 'wc_lottery_delete_participate_entry'
	
** Version 1.1.17 **
- Fix: Max ticket per user bug

** Version 1.1.16 **
- Fix: Removing lottery from users my lotteries list when deleting log in admin
- Fix: Sending emails after lottery is closed bug for manually picked winners
- Fix: Enable login at checkout for lottery with no max ticket per user

** Version 1.1.15 **
- Fix: my_lotteries shortcode problem with relisted lotteries
- Fix: Problem with old meta when duplicating lottery product
- Fix: Critical error on refund for php > 7
- Fix: Refund notice for payment that does not support automatic refund
								
** Version 1.1.14 **
- Fix: Admin relist info in lottery history metabox
- Fix: Price is not set to 0 if price input is left blank
- Add: Redirection to previous page after login
									
** Version 1.1.13 **
- Fix: Added message for nonlogged users on my_lotteries shortcode
- Add: finished_lotteries shortcode
- Fix: Replaced woocommerce_get_page_id with wc_get_page_id
								
** Version 1.1.12 **
- Fix: Translation bug with "You have bought %d tickets for this lottery!" string
- Fix: Shortcode bug when option "Show finished lotteries" is false 
- Fix: lang domain fix
								
** Version 1.1.11 **
- Fix: Relist future lotteries bug
- Fix: plural translation problems in message "you have bought..."
- Add: ability to clear on hold orders that are preventing lottery to end
- Add: Filters woocomerce_lottery_history, woocommerce_lottery_winners, woocommerce_lottery_participants
	
** Version 1.1.10 **
- Fix: WPML compatibility bug
- Fix: Problem when 3rd party plugin removes product object
- Fix: Plural translation problems

** Version 1.1.9 **
- Fix: removed lottery column from WooCommerce orders view
- Fix: bug with multiple winners

** Version 1.1.8 **
- Fix: shortcodes problem when "do not mix" enabled in settings

** Version 1.1.7 **
- Add: Limit ticket by lottery in the quantity selector
- Fix: Change name of js function from countdown to wc_lottery_countdown
- Fix: Countdown format bug
- Fix: Changed admin dashboard widget
- Fix: Php notice in backend WooCommerce email settings
- Fix: Progress bar on firefox
- Add: Compact countdown option
- Fix: Bug with filtering lotteries from shop page
- Fix: Bug with title on lotteries base page

** Version 1.1.6 **
- Fix: Bugs in admin backend filter product on PHP v7.1.x
- Fix: Future lottery not showing once it starts

** Version 1.1.5 **
- Fix: Sending multiple "no luck" emails to same user
- Fix: Stock status not changing after lottery relist

** Version 1.1.4 **
- Add: Added sale price for lottery products
- Fix: Bug not creating log table on activation

** Version 1.1.3 **
- Fix: Filtering lotteries in admin area
- Fix: Featured lotteries shortcode bug
- Fix: Lotteries shortcode bug
- Fix: WooCommerce Recently Viewed lotteries widget bug
- Fix: Virtual and downloadable chackbox bug

** Version 1.1.2 **
- Fix: Featured widget bug
- Fix: Typos
- Fix: Check for minimal PHP and WordPress versions to avoid fatal errors on activating plugin in unsupported environment

** Version 1.1.1 **
- Fix: query problems with WooCommerce >= 3.0.0
- Fix: WPML bug when using secondary language without main language

** Version 1.1 **
- Fix: WooCommerce >= 3.0.0 compatibility
- Fix: Delete entry when order is cancelled
- Fix: Multiple failed emails to same user
+ Add: manual lottery relist feature
+ Add: Added [vendor] tag for sending mail to lottery author/vendor on lottery_fail, lottery_finished -
useful with multivendor plugins like WC Vendors or if you want to send email to lottery author or owner in case of multivendor site

** Version 1.0.8 **
- Fix: Shortcode lotteries_winners not showing winners when item is out of stock

** Version 1.0.7 **
- Fix: Add to cart button text

** Version 1.0.6 **
- Fix: JS bug in frontend

** Version 1.0.5 **
+ Add: Shortcode for displaying lottery winners [lotteries_winners]
- Fix: Issue with wpml language switcher

** Version 1.0.4 **
- Fix: Bug with Wp_Meta_Query

** Version 1.0.3 **
- Fix: Check if user is logged only for lottery products
- Fix: Small language changes
- Fix: Problem with language data

** Version 1.0.2 **
- Fix: Problem with translating counter labels
+ Add: option to instantly finish lottery when maximum number  of tickets was sold

** Version 1.0.1 **
- Fix: Small bugs
+ Add: Refund feature for lotteries that failed due minimum participants limit

** Version 1.0.0 **
- Initial release

Overview and Features

WooCommerce Lottery

WooCommerce Lottery is a extension for popular WooCommerce plugin and extends it with lottery features. We tried to make it easy to use but also to include all lottery features. With this plugin you will get a powerful lottery solution for WordPress which is easily setup and customized.

With WooCommerce Lottery plugin you can setup WordPress lottery website and start lotteries in less than 30 minutes (assuming you have payment processor account ready). WooCommerce Lottery plugin integrates seamlessly with WooCommerce and no special knowledge is needed (same level like for standard WooCommerce usage).

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 - read Elementor tutorial
  • 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 Product Vendors or 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 numbers addon / extension avaliable (additional fee) - check video, check demo and screenshot gallery - purchase it here - features included: ticket number pick (ticket number grouping in tabs) with option to randomly assign numbers without picking each number, instant wins (with CSV import for easy setup lot of instant win numbers), question / answers, manually pick winning number(s) - when you want to use 3rd party lottery drawing option like national lottery numbers, service like https://www.random.org/ or your own random number generator, manually add ticket numbers for user (postal entries)

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.

screenshot

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

screenshot

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:
    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 log tables.

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:

screenshot

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

screenshot

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).

WooCommerce lottery settings without pick number mod addon

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.

screenshot

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.

screenshot

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]

screenshot
screenshot

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.

screenshot

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

Winner(s) is / are picked randomly once lottery is finished or you can manually enter winning numbers in case you have Pick Number Mod addon. Plugin uses mt_rand PHP function to randomly pick winners. PHP function mt_rand() which provides solid randomization for this purpose.

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.

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 randomly winning numbers (or use national lottery numbers or random.org) you will enter numbers in text input field. It is then possible that your lottery could end without winners (if none of participants picked right number(s)).

With Pick Number Mod and question / answers feature enabled winners will be choosen among those with correct answer only. 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" per_page="12" order="desc"]
  • show featured lotteries -[featured_lotteries], [featured_lotteries paginate="true" per_page="12" columns="4" orderby="date" order="desc"]
  • show ending soon lotteries - [ending_soon_lotteries], [ending_soon_lotteries paginate="true" per_page="12" columns="4" order="desc" future="no"]
  • show recent lotteries, lottery_status="active" attribute filters out finished lotteries - [recent_lotteries], [recent_lotteries paginate="true" per_page="12" columns="4" orderby="date" order="desc" lottery_status="active"]
  • show future lotteries - [future_lotteries], [future_lotteries paginate="true" per_page="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" per_page="1" show_buy_it_now="true"]
  • show past / ended lotteries - [finished_lotteries], [finished_lotteries paginate="true" per_page="12" columns="4" order="desc"]

WooCommerce Lottery

wpgenie plugin

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.