woocommerce "add_to_cart_redirect" filter useless with wootickets…

Home Forums Ticket Products Event Tickets Plus woocommerce "add_to_cart_redirect" filter useless with wootickets…

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #51717
    somatic
    Participant

    So I’ve been trying to figure out how to bypass the cart page and go straight from clicking the button to purchase tickets straight to checkout. Normally in woocommerce, this is easily accomplished with this filter:

    add_filter(‘add_to_cart_redirect’, ‘custom_add_to_cart_redirect’);
    function custom_add_to_cart_redirect() {
    return get_permalink(get_option(‘woocommerce_checkout_page_id’));
    }

    This filter gets triggered inside woocommerce-functions.php in the function woocommerce_add_to_cart_action(). However — for some reason, when the product being purchased is a wooticket, despite the fact that we’re taken to the shopping cart page, the very first conditional test in this function fails, and thus the rest of the function never executes and filter I want is never called:
    if ( empty( $_REQUEST[‘add-to-cart’] ) || ! is_numeric( $_REQUEST[‘add-to-cart’] ) )
    return;

    when I examined my request, $_REQUEST looked like this:
    array(3) { [“wootickets_process”]=> string(1) “1” [“product_id”]=> array(1) { [0]=> string(2) “37” } [“quantity_37”]=> string(1) “1” }

    So you guys are somehow adding the ticket to the cart, but completely bypassing all the functionality of woocommerce_add_to_cart_action(). I’m not sure that’s well-advised, as there’s a bunch of product->cart validation that goes on in there, and of course, the desired redirect filter.

    It seems this is happening in wooticket’s process_front_end_tickets_form(), which simply calls the woocommerce class directly with $woocommerce->cart->add_to_cart( $product_id, $quantity );

    So given this implementation, how can I skip the cart page and go directly to checkout? I only have one event – I have no need for the cart page…

    #51764
    Barry
    Member

    Hi Somatic,

    There are a few points you bring up and they are neatly encapsulated by this paragraph:

    So you guys are somehow adding the ticket to the cart, but completely bypassing all the functionality of woocommerce_add_to_cart_action(). I’m not sure that’s well-advised, as there’s a bunch of product->cart validation that goes on in there, and of course, the desired redirect filter.

    No redirect is taking place in this scenario – the WooTicket ticket form simply submits directly to the cart page – so to skip straight to your final question you could change this either by overriding the tickets.php and specifying an action URL of your choosing or else you could set up a filter on woocommerce_get_cart_url (which might even serve to catch not only scenarios like this but redirects to the cart page, too).

    I’m not too concerned about the fact that woocommerce_add_to_cart_action()‘s magic isn’t running as a result of this – a series of checks will anyway take place within the cart object’s check_cart_items() method – but if you can describe a case that is going to be missed we’re definitely open to feedback.

    Does that help/clarify things?

    #52269
    infamia
    Participant

    Hrm
    I think this may be related to my problem. I’m trying to integrate woocommerce-waitlist. I believe this plugin uses woocommerce_after_add_to_cart_button. Since we’re not displaying the actual woocommerce “add to cart” button but instead, as teh OP put it, “bypassing all the functionality of woocommerce_add_to_cart_action()”, this plugin does not work.

    Is there an easy way to use the woocommerce cart functions?

    #52292
    Barry
    Member

    You could override the tickets.php template (see our Themer’s Guide – link over in the Useful Resources widget on the right hand side of the forum – for the lowdown on doing this) and simply add a piece of code like:

    do_action(‘woocommerce_after_add_to_cart_button’)

    Before the form element is closed; would that help here?

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘woocommerce "add_to_cart_redirect" filter useless with wootickets…’ is closed to new replies.