Conditional logic based on quantity of tickets selected

WordPress Event Management, Calendars & Registration Forums General Question Conditional logic based on quantity of tickets selected

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 6 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29973

    Hi, I have a question related to the Conditional Logic API.

    I added a textarea field using the form customizer, and would like to have it hidden by default, but would only appear (and be required to fill in) when the number of tickets selected is geater than 1.

    I tried to hook into the ‘ticketpicker’ field value for condition, and show the textarea field based on but could not make it work.

    Something like this?


    $textarea = $form->get_element( '8' );

    $conditional_logic = array(
        'action' => 'show',
        'gate'   => 'all',
        'conditions' => array(
                array(
                    'target'   => 'ticketpicker',
                    'value'    => 1,
                    'operator' => 'greaterthan',
                )
        ),
    );
    $textarea->set( 'conditional', $conditional_logic );
    

    Mikko Siikaniemi
    #29990

    Hi Mikko,

    Unfortunately that won’t work with the ticketpicker, since the ‘value’ is not just the total number of tickets. For this, you’re going to need to implement itself. Something like:

    jQuery(document).ready( function($) {
        wp.hooks.addFilter( 'eventorganiser.checkout_cart', function( cart ){
            if(cart.quantity > 1) {
                $('#id_of_textarea').show();
            } else {
                $('#id_of_textarea').hide();
            }
            return cart;
        }, 5 );
    } );
    

    You’ll need to ensure the textarea is not required has otherwise customers who purchase only one ticket will not be able to place the booking.

    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.