Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jcrawford

    (@jcrawford)

    I should note that this works fine if I have a product in my cart already but not if my cart is empty that’s where the redirect loop comes from.

    Thread Starter jcrawford

    (@jcrawford)

    it seems to be dying in the do_action call on line 942 of class-wc-cart.php which is the following call

    do_action( 'woocommerce_add_to_cart', $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data );

    If there are no products in the cart that kills the process for some reason or another with nothing in the error log. However if there is even 1 other product in the cart then this call works just fine. Here is my logging so you can see the before and after data

    No products in the cart
    [Wed Mar 04 23:23:23.601721 2015] [:error] [pid 30183] [client 71.181.125.154:49557] cart_item_key: 2838023a778dfaecdc212708f721b788 product_id: 51 quantity: 1 variation_id: "" variation: [] cart_item_data: [], referer: http://jcrawford.heytix.com/?tribe_events=test-event-3

    Add A DIFFERENT Product to the cart
    [Wed Mar 04 23:23:32.716460 2015] [:error] [pid 30442] [client 71.181.125.154:49556] cart_item_key: d82c8d1619ad8176d665453cfb2e55f0 product_id: 53 quantity: 1 variation_id: "" variation: [] cart_item_data: [], referer: http://jcrawford.heytix.com/?tribe_events=test-event-3

    Add THE SAME product to the cart (the one that killed the process the first time)
    [Wed Mar 04 23:23:42.700092 2015] [:error] [pid 30488] [client 71.181.125.154:49574] cart_item_key: 2838023a778dfaecdc212708f721b788 product_id: 51 quantity: 1 variation_id: "" variation: [] cart_item_data: [], referer: http://jcrawford.heytix.com/?tribe_events=test-event-3

    As you can see the data logged is the same just before that action is called whether there is a product in the cart or not, however it continues to die when there are no items in the cart and that code is triggered.

    mohammad-mursaleen

    (@mohammad-mursaleen)

    You can avoid this sort of error by keeping your “Add to cart” button (or what ever you are using) disabled initially and enable it using jQuery only if some product is added.

    Also I think you can try this as well;

    add this to theme’s functions.php

    add_filter (‘add_to_cart_redirect’, ‘redirect_to_checkout’);
    function redirect_to_checkout() {
    global $woocommerce;
    $checkout_url = $woocommerce->cart->get_checkout_url();
    return $checkout_url;
    }

    Refrence : Stackoverflow

    Hello, you can use an excellent and very useful plugin to do this, the plugin is called “WooCommerce Quick Buy”, it’s free. 🙂

    Link: https://wordpress.org/support/view/plugin-reviews/woocommerce-quick-buy

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add Item to Cart’ is closed to new replies.