Advertisement
wpgenie

Buttons that automatically add 5, 10 or 15 tickets to cart

Sep 23rd, 2020 (edited)
1,660
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. /* Buttons that automatically add 5, 10 or 15 tickets to cart */
  2. /* to use this HTML / PHP code, copy it to your child theme functions.php file */
  3. add_action( 'woocommerce_after_add_to_cart_button', 'additional_simple_add_to_cart', 20 );
  4. function additional_simple_add_to_cart() {
  5.  
  6.     global $product;
  7.  
  8.     if ( wc_lottery_use_answers( $product->get_id() ) ): ?>
  9.  
  10.         <script>
  11.         jQuery(document).ready(function($){
  12.            
  13.             $(document).on('click','.lottery-pn-answers li',function(e){
  14.                 var answer_id = $(this).data('answer-id');
  15.                 var aelement = $('a.single_add_to_cart_button-5');
  16.                 var old_url = aelement.attr("href");
  17.                 var new_url = old_url + "&lottery_answer="+answer_id;
  18.                 aelement.attr("href", new_url);
  19.  
  20.                 var aelement = $('a.single_add_to_cart_button-10');
  21.                 var old_url = aelement.attr("href");
  22.                 var new_url = old_url + "&lottery_answer="+answer_id;
  23.                 aelement.attr("href", new_url);
  24.  
  25.                 var aelement = $('a.single_add_to_cart_button-15');
  26.                 var old_url = aelement.attr("href");
  27.                 var new_url = old_url + "&lottery_answer="+answer_id;
  28.                 aelement.attr("href", new_url);
  29.             });
  30.  
  31.         });
  32.         </script>
  33.         <?php endif; ?>
  34.         <br><br>
  35.         <a rel="no-follow" href="?add-to-cart=<?php echo esc_attr( $product->get_id() ) ?>&amp;quantity=5" class="single_add_to_cart_button-5 button alt">Add 5 Tickets</a>
  36.  
  37.         <a rel="no-follow" href="?add-to-cart=<?php echo esc_attr( $product->get_id() ) ?>&amp;quantity=10" class="single_add_to_cart_button-10 button alt">Add 10 Tickets</a>
  38.  
  39.         <a rel="no-follow" href="?add-to-cart=<?php echo esc_attr( $product->get_id() ) ?>&amp;quantity=15" class="single_add_to_cart_button-15 button alt">Add 15 Tickets</a>
  40. <?php
  41. }
Advertisement
Comments
  • mg33dev
    1 year
    # text 0.14 KB | 0 0
    1. When the product is A-Z Alphabet is there a way to "Select all from J" etc
    2.  
    3. So people can select all of the numbers from that alphabet.
Add Comment
Please, Sign In to add comment
Advertisement