• Resolved stefan0s

    (@stefan0s)


    Hello,

    I would like to ask if there is any documentation about the events triggered when adding to cart.

    When calling ajax “nmgr_add_to_cart”, we have a custom validation action rule and we want to listen to your response and do some other action (display a popup). How can we bind to that event??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author nmerii

    (@nmerii)

    After the add to cart action, this fires:

    $(document.body).trigger('nmgr_add_to_cart_response', response);

    So you can use the nmgr_add_to_cart_response event which is triggered on the document.body.

    Thread Starter stefan0s

    (@stefan0s)

    Thank you nmerii for your response. The event is triggering and works good!

    One last querstion. During “Add to cart” i am using “woocommerce_add_to_cart_validation” filter and on my case i don’t allow wishlist item to be added to cart, so i return wc_add_notice(‘Custom Error.’).

    add_filter( ‘woocommerce_add_to_cart_validation’, function($passed, $product_id, $quantity){
    $custom_logic = true;
    if($custom_logic) {
    wc_add_notice( __(‘Custom Error.’, ‘woo’ ), ‘error’ );
    return false;
    }
    return $passed;
    }, 10, 3 );

    On “nmgr_add_to_cart_response” response object, i don’t see that error message to display it on my custom header info. The response.fragments.notice is undefined.

    Plugin Author nmerii

    (@nmerii)

    I tried your custom validation code and it worked. You can access the notice property from the response object as response.notice.

    The plugin however displays all notices automatically within the div.woocommerce on the page so it should display your custom error notice for you. So you should take this into account if you want to display the error notice by yourself, perhaps in a different way.

    Thread Starter stefan0s

    (@stefan0s)

    Thank you. It works fine!

    • This reply was modified 3 years, 1 month ago by stefan0s.
    • This reply was modified 3 years, 1 month ago by stefan0s.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Events’ is closed to new replies.