WooCommerce Lottery

Last updated: 22nd Nov 2018.

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

Note:

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

Overview and Features

  • Seamless integration into WooCommerce via its hooks
  • You get new type of WooCommerce product type - lottery
  • Define number of lottery winners - 1 or more
  • Winners / users can win single prize or multiple prizes
  • Ability to refund tickets with single click if lottery has failed
  • Ability to instantly finish lottery if max number of tickets was sold
  • Define minimal and maximal number of tickets available
  • Define max tickets per user
  • Set start and end time for lottery
  • 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 email templates) for lottery win, fail, finish, no luck
  • 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
  • WPML compatible
  • Pick ticket numbers addon / extension avaliable (for a fee) - check demo and admin screenshot - purchase it here - features included: ticket number pick, 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

Instalation

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

Note:

Make sure to install WooCommerce before you activate WooCommerce Lottery plugin.

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.

screenshot

Alternative setup. After downloading WooCommerce Group Buy 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).

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 EasyCron

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

Install WooCommerce Sample Data:

Source: https://docs.woocommerce.com/document/importing-woocommerce-dummy-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 group buy 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 -> Group Buy you can set group buy base page where your client will have a list of all group buy deals. Please see note if you want to set your group buy page as home page. If you have group buy only website there is no need to setup group buy base page, you can use Woocommerce shop page.

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
  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. Orders list has column with lottery icon to easily see which order is from lottery
  6. WooCommerce settings - new tab called Lottery
  7. WooCommerce settings - Emails - new items: lottery win, lottery fail, lottery finish, lottery no luck email templates
  8. New widgets: future lotteries, ending soon lotteries, featured lotteries, latest lotteries, recently viewed lotteries, my lotteries, random lotteries
  9. New shortcodes

New WooCommerce product type lottery:

screenshot

Plugin Options

Here are settings that you can turn on and off. Settings are self explainable. 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 lotteries Base Page dropdown, see screenshot).

screenshot

On screenshot below you can see how product list with lotteries looks like. Lottery status icon colors: red - active lottery, orange - finished, red - failed.

screenshot

If lottery has failed, in product / lottery details you will see "Refund" link which enables you to refund all tickets to participants if your lottery rules require that.

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

Shortcodes

Here is a list of all available plugin shortcodes. Some shortcodes accept optional orderby and order attributes.

  • show lottery winners - [lotteries_winners], [lotteries_winners per_page="12" order="desc"]
  • show featured lotteries - [featured_lotteries per_page="12" columns="4" orderby="date" order="desc"]
  • show ending soon lotteries - [ending_soon_lotteries per_page="12" columns="4" order="desc"]
  • show recent lotteries - [recent_lotteries per_page="12" columns="4" orderby="date" order="desc"]
  • show future lotteries - [future_lotteries], [future_lotteries per_page="12" columns="4" orderby="date" order="desc"]
  • show lotteries with specific product ID - [lotteries ids="1,2,3,4,5"]
  • show user's lotteries (active lotteries in which user participates and list of user's won lotteries) - [my_lotteries], [my_lotteries show_buy_it_now="true"]
  • show past / ended lotteries - [finished_lotteries], [finished_lotteries per_page="12" columns="4" order="desc"]

Note:

Please note that there is no paging when you use shortcodes (same as with WooCommerce shortcodes). Per page attribute means how many items will be displayed on that particular page without paging!

FAQ

Here you can find answers to frequently asked questions. Feel free to contact us if you can't find answer to your question.

  1. Can users create their own lotteries? - Basically yes, only users who can add new products can create lotteries. You can use multiple vendor plugin which will allow you to add users who will be able to create products (lotteries). You can use multiple vendor plugin which will allow you to add users who will be able to create lotteries. You can use WooCommerce Product Vendors (there is no frontend submission for lotteries only backend).
  2. Do you use cronjobs? - Yes. Please check installation instructions.
  3. Where can I edit email templates? - Go to WooCommerce > Settings and click on Emails tab.
  4. Does this plugin work with caching plugins? - Yes, W3TC and WP Super Cache work but we advise no caching for logged in users. For example if page cache is enabled widget recently viewed lotteries will not work. Once user is logged in and there is no caching anymore all widgets will work. You can use CDN and browser caching. Our plugin demo website uses WP Super Cache with page caching and browser caching. All of our plugins have same requirements for caching as WooCommerce - check it here https://docs.woocommerce.com/document/configuring-caching-plugins
  5. Can I make theme with WooCommerce Lottery and sell it on ThemeForest? - Sure, just purchase extended licence and you're good to go. Since the current licenses do not deal with re-selling Items, Envato lets authors to decide whether they grant permission for bundling Items or not. We have the following conditions, and you need to follow them:
    • You cannot redistribute the item "as-is", even if you modify it or you make a derivative version for another platform
    • You cannot offer the plugin as a stand-alone item
    • You cannot include the plugin separately from your theme in the download package
    • You cannot provide an Item Purchase Code for your customers - Since Envato doesn't have a "multi-use" or transferable license, your customers are not entitled to receive an Item Purchase Code with your theme and use the plugin separately from your work.
    • Updating the plugin is your own responsibility
    • Since your customers cannot receive updates from us, you need to handle this on your own
    • You need to handle related support requests after your customers or you can instruct them to buy regular licence and ask us for support directly via our CodeCanyon profile (we cannot provide free support for your customers)
  6. I can't do anything because I get "out of stock message"? - Lottery plugin needs inventory / stock to be enabled. If you have problems all issues should be fixed by upgrading to Woocommerce Lottery v1.1.6
  7. How can I update plugin with new version? Is auto updating possible? - We suggest you to install Envato Marketplace (installation instructions can be found on plugin's url) plugin for auto update plugin and themes purchased on Envato. Setup is easy. Manual updating can be done by downloading new version of plugin and overwrite old files with new ones or deleting old plugin and installing new one.

    Note:

    If you have modified plugin files (templates) then you need to be careful when updating so you don't overwrite changes you made and that templates are inside child theme or theme woocommerce/ template folder.

  8. Does Woocommerce Lottery work with WordPress import / export tools? - Yes, you can export and import lotteries with standard WordPress import / export tools that are located in Admin -> Tools menu.
  9. How can I enable user registration on login page? - You need to enable that feature in Woocommerce settings.
  10. I have installed your plugin but images are not aligned, buttons are too small / big, input fields needs to be smaller / bigger, can you help? - In short no.

    It's your duty to modify plugin template to matchyour style and theme. Themes can implement different ways how they customize pages and parts of Woocommerce. We cannot guarantee that our plugin will look same as in our demo for every possible theme out there. Web developing is more than getting a theme and couple plugins, enabling them and deliver web site. Our templates are coded by standards and they adhere to WordPress and WooCommerce template structure. That means that minimal intervention is needed from client side, but sometimes there is no way to avoid template changes. Some themes use similar structure and have minimal interventions in structure and our plugin looks good out of the box and some do not. It's your task as web developer and client who purchased plugin to modify and customize plugin templates to match your own (or client's) needs and styles. This is part of developing a web site. You cannot expect that everything will be perfect for every possible theme and plugin comibation out there or that we will do your job for you as part of support. We support plugin - we do not style and customize client's sites. Thanks for understanding.

    Note:

    Right way to customize plugin's templates is to copy contest of plugin_dir/woocommerce-simple-lotteries/templates/ directory to your_theme/woocommerce/ directory and do modifications there.

    When you ask us for support make sure it's not related to tasks we don't do as part of support:

    - style or customize your theme to do this or that
    - provide support for bugs caused by 3rd party plugins or themes (we can pinpoint that some plugin is problematic)
    - send you CSS or HTML code for modifying html elements

  11. Where can I see winners of the lottery? - Read text and check screenshots in paragraph "Plugin options".
  12. How can I add countdown timer / counter on all pages not only on single product page? - You can use code here http://pastebin.com/v3iMcG1k or:

    add_action( 'woocommerce_after_shop_loop_item_title','wpgenie_show_counter_in_loop',50 );
    
    function wpgenie_show_counter_in_loop(){
    
      global $product;
    
      $time = '';
    
      if(!isset ($product))
        return;
      if('lottery' != $product->product_type)
        return;
    
      $timetext = __('Time left', 'wc_lottery');
    
      if(!$product->is_started()){
        $timetext = __('Starting in', 'wc_lottery');
        $counter_time = $product->get_seconds_to_lottery();
      } else{
        $counter_time = $product->get_seconds_remaining();
      }
    
    $time = '<span class="time-left">'.$timetext.'</span <div class="lottery-time-countdown"
    data-time="'.$counter_time.'" data-lotteryid="'.$product->id.'" data-format="'.get_option(
    'simple_lotterys_countdown_format' ).'"></div>'; if($product-&gt;is_closed()){ $time = '<span
    class="has-finished">'.__('Lottery finished','wc_lottery').'</span>'; } echo $time;
    }
    
  13. How winner(s) is picked? How do you pick winners? - Winner(s) is/are picked randomly once lottery is finished. Plugin uses mt_rand PHP function to randomly pick winners. PHP function mt_rand() which provides solid randomization for this purpose.
  14. Can users buy tickets for lotteries without signup / register first? - No. It is impossible to have users purchase tickets before they're logged in because we can not count consistently their previously purchased tickets only those in cart can be counted.
  15. What are custom meta fields for lottery product type (useful for CSV Product Import)?
    
    _lottery_closed
    _lottery_dates_from
    _lottery_dates_to
    _lottery_multiple_winner_per_user
    _lottery_num_winners
    _lottery_participants_count
    _lottery_price
    _lottery_winners
    _lottery_fail_reason
    _max_tickets
    _max_tickets_per_user
    _min_tickets
    _participant_id
    _lottery_wpml_language
    
  16. 3rd party plugin is causing problems? Its developers tell you that we need to fix our plugin? - Woocommerce extensions should be transparent - meaning one extension should work with another without introduction of special code that makes them compatible. Imagine what would happen and how much time we would need to spend if we would have to add a bit of compatibility code for every Woocommerce extension that's out there - we would end up in huge plugin with tons of problems which would be problem to test and debug. That's why we think every plugin developer should stick to Woocommerce coding standards and APIs (they're there for that reason) and not require 3rd party developers to code something into their extensions / plugins so that it could work with theirs.
  17. How can I translate plugin to my language? Do you have translations? - We only maintain english translation. We do not have resources to quality maintain other translations. Here are steps which can help you to traslate plugin or change some strings yourself:
    • you will use file plugins/woocommerce-lottery/languages/wc_lottery.pot to create your translation
    • you need to download and install Poedit https://poedit.net/download
    • download wc_lottery.pot and open it with Poedit
    • do your translations with Poedit
    • when done save wc_lottery-en_GB.po, saving wc_lottery-en_GB.po will create wc_lottery-en_GB.mo
    • you need to upload both files to /wp-content/languages/plugins/ and not to plugin directory because translations will be lost if you update plugin by deleting old one

    Note:

    In filename wc_lottery-en_GB.po suffix en_GB must match your language settings in WordPress, otherwise language will not be loaded. So for example you can have wc_lottery-en_AU.mo, wc_lottery-af.mo or wc_lottery-en_CA.mo, complete list of available suffixes are here https://make.wordpress.org/polyglots/teams/

  18. I want to remove countdown timer on single lottery page, what should I do? Copy file templates/single-product/participate.php to your_theme/woocommerce/single-product/participate.php and comment out this:
    
    <div class="lottery-time" id="countdown"><?php echo apply_filters('time_text', __( 'Time left:',
    'wc_lottery' ), $product->get_type()); ?> <div class="main-lottery lottery-time-countdown" data-time="<?php echo
    $product->get_seconds_remaining() ?>" data-lotteryid="<?php echo $product->get_id() ?>" data-format="<?php echo
    get_option( 'simple_lottery_countdown_format' ) ?>"></div> </div> 
  19. When client cancelled order stock is not restored? - Yes, that's how plugin works. You can use this plugin for restoring stock for cancelled orders https://wordpress.org/plugins/woocommerce-auto-restore-stock/. Also keep on your mind that for Lottery to work you have to enable stock management in WooCommerce Settings -> Products -> Inventory.
  20. Can I manually add winning numbers? Can I enable users to pick ticket numbers? Can I have question - Yes, you will need Pick ticket numbers addon / extension avaliable (for a fee) - check demo and admin screenshot - please contact us for more details via ticket system or email info@wpgenie.org - features included: ticket pick option, 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
  21. What happens with tickets with wrong answer? - When you manually select winner you can select also winner with wrong answer. When winner is selected automatically then tickets with wrong answers will not be taken into draw process.
  22. List of actions and filters - Here is list of all actions:
    
    wc_lottery_close
    wc_lottery_fail
    wc_lottery_min_fail
    wc_lottery_won
    pre_get_lottery_search_form
    

    Here is list of all filters:
    
    woocommerce__lottery_history_data
    lottery_history_started_text
    woocommerce_lottery_participants
    woocommerce_lottery_winners
    woocomerce_lottery_history
    woocommerce_lottery_participating_message
    get_lottery_search_form
    woocommerce_lottery_bage (typo here is fine)
    
  23. Refund feature does not work? How can I tell if my payment gateway supports refunds? If you got this error: "Payment does not support refund" your gateway just does not implement refund feature. Here is link for more infos about how to check if gateway supports refund feature. Keep on your mind that for issuing refund you need to click on refund button in product details, there are not automatic refunds.
  24. How can I create custom query for lotteries? You can use this code:
    $args = array(
    'post_type'   => 'product',
    'show_past_lotteries' => TRUE,
    'tax_query' => array(array('taxonomy' => 'product_type' , 'field' => 'slug', 'terms' => 'lottery')),
    /* 'meta_query' => array(
    		array(
    			'key' => '',
    			'operator' => 'EXISTS',
    		)
    ),*/
    'lottery_archive' => TRUE
    );     
    
    $the_query  = new WP_Query( $args );
    

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.