Selling multiple tickets in groups of 2.

Home Forums Ticket Products Event Tickets Plus Selling multiple tickets in groups of 2.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1064458
    Emiliano Pasini
    Participant

    Hi, I would like to know if there is a way of applying a rule to all the events/tickets to sell tickets in groups of 2.

    To be more precise, I need to sell in multiples of 2 ( 2, 4 , 6 , 8, 10, etc ). There is a plugin that make the rule for each product but I would like to do the same appliying the same rule to the hole calendar if possible.

    Many thanks,
    Emiliano

    #1064467
    George
    Participant

    Hey Emiliano,

    Thanks for reaching out!

    Just to be clear, do you mean that your goal is literally so that a person can never by just one, three, or five tickets for example? But only tickets in multiples of two?

    If so, this is not possible with the plugins at this time. It would require an extensive bit of custom coding. We unfortunately cannot help with custom coding, but let me know if you can confirm that my above summary of your goals is accurate.

    If so, I will try to tinker around with the code a bit and see if I can recommend a solution or some ideas at least.

    Thank you!
    George

    #1064477
    Emiliano Pasini
    Participant

    Hi George, thanks for your answer. Yes that’s exactly what I’m trying to achieve, it would be much appreciated a solution for this!
    Many thanks,
    Emiliano

    #1065038
    George
    Participant

    Hey Emiliano,

    Thanks for your patience with this while I investigated and wrote some code. It’s actually a rather simple change to make to get the quantity field for tickets to only work in multiples of two–you can simply add code like the following to your theme’s functions.php file:


    add_filter( 'woocommerce_quantity_input_step', 'tribe_woo_make_step_2' );

    function tribe_woo_make_step_2() {
    return 2;
    }

    Now, in some cases users could manually alter the value to be something like 3 or 5 anyways…making it truly impossible to enter a non-multiple of 2 value is a bit tricky, but with even a little bit of JavaScript you can make it very, very hard to submit a purchase with a value of tickets that is not a multiple of 2.

    I unfortunately cannot help implement a better solution than what I have here, but what I have here is another bit of code you can add to your theme’s functions.php file – this extra bit of JavaScript will throw an error if users try to buy 0 tickets, or some a value that is not divisible by 2:


    add_action( 'wp_footer', 'tribe_woo_check_if_quantity_is_multiple_of_2' );

    function tribe_woo_check_if_quantity_is_multiple_of_2() {
    wp_enqueue_script( 'jquery' ); ?>
    <script>
    jQuery(document).ready(function($){
    if ( $( 'td.woocommerce.add-to-cart' ).length ) {
    $( 'td.woocommerce.add-to-cart' ).on( 'click', 'button', function(e) {
    var $table = $( e.delegateTarget ).parents( '.tribe-events-tickets' );
    var qty = $table.find( 'input.input-text.qty.text' ).val();

    if ( ( qty > 1 ) && ( qty % 2 == 0 ) ) {
    // Good to go!
    } else {
    e.preventDefault();
    alert( 'You can only buy tickets in multiples of 2.' );
    }

    });
    }
    });
    </script><?php
    }

    I hope this all helps!

    Cheers,
    George

    #1071505
    Emiliano Pasini
    Participant

    Hi George, this is great, thanks so much for your help!
    Just one more thing if possible, we need to limit the amount of tickets that someone can buy ( 12 tickets max )
    There is a way on the system for choosing the max amount of tickets that the user could buy?

    Thanks!

    #1071506
    Emiliano Pasini
    Participant

    I mean, the maximun tickets that someone could buy on each transaction should be 12.

    #1071782
    George
    Participant

    Hey @emiliano,

    Setting the limit that way is unfortunately not possible without even more code customizations 🙁 Doing that is a bit more complicated than the custom code I was able to write for the other aspect of this, and so unfortunately you would either have to write that custom code yourself or hire a developer to write that code for you.

    I’m sorry about this, @emiliano!

    Please let me know if there’s anything else I can help with.

    Sincerely,
    George

    #1082468
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Selling multiple tickets in groups of 2.’ is closed to new replies.